1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| my $acc_file = "C:/Dokumente und Einstellungen/outaleb/Desktop/Perl/Peptide.txt";
my $fasta_file_in = "C:/Dokumente und Einstellungen/outaleb/Desktop/Perl/FASTA1.fasta";
my $fasta_file_out = "C:/Dokumente und Einstellungen/outaleb/Desktop/Perl/FASTA3.fasta";
# Use a hash to keep a record of accessions we want to find
my %hash_of_req_acc;
# read all the required accessions from the file into the hash as keys
open (ACC_FILE, $acc_file) or die "Couldn't open file: $!\n";
while (<ACC_FILE>) {
my $line = $_;
chomp $line;
$hash_of_req_acc{$_} = 1;
}
#my $key;
#foreach $key ( keys %hash_of_req_acc){
#print $key." = ".$hash_of_req_acc{$key}."\n" ;
#}
close ACC_FILE;
my $seqio_object_in = Bio::SeqIO->new(
-file => $fasta_file_in,
-format => 'fasta'
);
my $seqio_object_out = Bio::SeqIO->new(
-file => $fasta_file_out,
-format => 'fasta'
);
# loop through all the sequences in the fasta file
while (my $seq_object = $seqio_object_in->next_seq) {
# get the sequence accession for easy matching
my $seq_acc = $seq_object->accession_number;
# write the sequence object to the output fasta file if we have a
#matching accession
$seqio_object_out->write_seq($seq_object) if exists
$hash_of_req_acc{$seq_acc};
} |