#!/usr/local/bin/perl #title "Compare hash with arrays and print" use strict; use warnings; use Bio::SeqIO; my %hash = ( aw1=>10, qs2=>20, dd3=>30, de4=>10, hg5=>30, dfd6=>20, gf4=>20, hgh5=>30, hgy3=>10, ); my $file = "Sample.fa"; my $file10 = "10.fa"; my $file20 = "20.fa"; my $file30 = "30.fa"; my $seq = Bio::SeqIO->new(-file => "<$file", -format=>'fasta'); # input object #output objects my $seqOut10 = Bio::SeqIO->new(-file => ">$file10", -format=>'fasta'); my $seqOut20 = Bio::SeqIO->new(-file => ">$file20", -format=>'fasta'); my $seqOut30 = Bio::SeqIO->new(-file => ">$file30", -format=>'fasta'); while(my $seqIn = $seq->next_seq()){ for my $key (keys %hash){ if($seqIn->id eq $key && $hash{$key}==10){ $seqOut10->write_seq($seqIn); }elsif($seqIn->id eq $key && $hash{$key} == 20){ $seqOut20->write_seq($seqIn); }elsif($seqIn->id eq $key && $hash{$key} == 30){ $seqOut30->write_seq($seqIn); } } } ####