Dear All,
i am a perl beginner. Recently i wrote a script to extract multiple sequences from a fasta file. The following is an example.
FASTA FILE:
>gene1
cgcggccccccccccccccccccc
>gene2
ggggggggggggggggggcgcgcg
>gene3
tagctacgatagcgtcagatgcaacg
>gene4
attttttttttttttttttttttttttttaaaaaaa
LIST FILE:
>gene4
>gene3
MY SCRIPT:
#!/usr/bin/perl
use strict;
use warnings;
open SEQ, "seq.txt";
my @seq=<SEQ>;
open LIST, "list.txt";
my @list=<LIST>;
my $i=0;
while ($i<$#seq){
my $j=0;
while ($j<$#list){
if ($seq[$i] eq $list[$j]){
print "$seq[$i]\t$seq[$i+1]";
}
$j++;
}
$i +=2;
}
close SEQ;
close LIST;
THE OUTPUT RESULT:
>gene4
attttttttttttttttttttttttttttaaaaaaa
Could anyone help to correct my script or make suggestions? Thank you very much for your help!!
i am a perl beginner. Recently i wrote a script to extract multiple sequences from a fasta file. The following is an example.
FASTA FILE:
>gene1
cgcggccccccccccccccccccc
>gene2
ggggggggggggggggggcgcgcg
>gene3
tagctacgatagcgtcagatgcaacg
>gene4
attttttttttttttttttttttttttttaaaaaaa
LIST FILE:
>gene4
>gene3
MY SCRIPT:
#!/usr/bin/perl
use strict;
use warnings;
open SEQ, "seq.txt";
my @seq=<SEQ>;
open LIST, "list.txt";
my @list=<LIST>;
my $i=0;
while ($i<$#seq){
my $j=0;
while ($j<$#list){
if ($seq[$i] eq $list[$j]){
print "$seq[$i]\t$seq[$i+1]";
}
$j++;
}
$i +=2;
}
close SEQ;
close LIST;
THE OUTPUT RESULT:
>gene4
attttttttttttttttttttttttttttaaaaaaa
Could anyone help to correct my script or make suggestions? Thank you very much for your help!!
Comment