我试图查看散列 %pc 中的值在散列 %fasta 中的键中,然后打印 %fasta 的键和值(如果是)。
到目前为止,我有脚本:
#!/usr/bin/perl
use warnings;
use strict;
use Bio::SearchIO;
use Bio::SeqIO;
my %pc;
my %fasta;
#get list of core protein clusters
my $file1 = $ARGV[0];
open (INPUT1, $file1) or die "Could not open $file1\n";
while (my $line1 = <INPUT1>) {
chomp $line1;
my @spl = split (/\|/, $line1);
my $id = $spl[0];
my $gene = $spl[1];
$pc{$id}=$gene;
}
my @files = glob("*_PC.fa");
foreach my $fil (@files) {
my $seqio = Bio::SeqIO->new(-format => 'fasta', -file => $fil);
my $file = $fil;
$file =~ /^(.+)_PC.fa/;
my $outfile = $1."_core.fa";
open (OUTFILE,'>', $outfile) or die "Could not open $outfile \n";
while (my $seqobj = $seqio->next_seq) {
my $seqid = $seqobj->display_id;
my $nuc = $seqobj->seq();
$fasta{$seqid}=$nuc;
foreach my $key (keys %fasta) {
my @spl2 = split (/\|/,$key);
my $fasta_gene = $spl2[1];
if ($fasta_gene eq (keys %fasta)) {
print OUTFILE ">$key\n$fasta{$key}\n";
}
}
}
close OUTFILE;
}
提前致谢!