use DBI;
use strict;
use warning;
my $textfile = "fasta.txt";
open (TEXT,"$textfile") or die "Could not open:$!";
my $dbh = DBI->connect("dbi:mysql:database=file",user,password,{RaiseError=>1}) or die "Could not connect $DBI:errstr";
while(<TEXT>){
$first = <TEXT>;
@second = <TEXT>;
$dbh->do("INSERT INTO open values (?,?)", undef, $first,@second);
}
$dbh->disconnect;
close TEXT;
This is My Perl code. It is not insert data in database. I created database and table. database name is file and table name is open, the table contain two column one is header and another one is sequence.
My expectation. I will create database have two column, one column contain the first line of fasta file and second column contain their sequence.
Header Sequence
>sp|P00547|KHSE_ECOLI Homoserine kinase OS=Escherichia coli (strain K12) GN=thrB PE=1 SV=2 MVKVYAPASSANMSVGFDVLGAAVTPVDGALLGDVVTVEAAETFSLNNLGRFADKLPSEP
RENIVYQCWERFCQELGKQIPVAMTLEKNMPIGSGLGSSACSVVAALMAMNEHCGKPLND
Please help me..
@Jean-Karim Heriche, thanking you for your nice answer. But I am not able to getting Header in my output in one column? Only my output is have a sequence, but its to split into three rows. I want to expect in that header column only the first line and that sequence column contain all sequence in fasta file. Please help me.
This is what I meant by parsing your fasta file correctly. I suggest you use BioPerl's Bio::SeqIO for this. However, if you need an alternative, here is a function that does the job:
Use like this: