Perl 检查一个散列的键是否与另一个散列的值相同?
我试图查看哈希%pc中的值在哈希%fasta中的键中,然后打印%fasta的键和值(如果是) 到目前为止,我已经有了剧本:Perl 检查一个散列的键是否与另一个散列的值相同?,perl,hash,Perl,Hash,我试图查看哈希%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 "Cou
#!/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;
}
#/usr/bin/perl
使用警告;
严格使用;
使用Bio::SearchIO;
使用Bio::SeqIO;
我的%pc;
我的%fasta;
#获取核心蛋白质簇的列表
my$file1=$ARGV[0];
打开(INPUT1,$file1)或死亡“无法打开$file1\n”;
while(我的$line1=){
chomp$line1;
my@spl=split(/\ \124;/,$line1);
my$id=$spl[0];
my$gene=$spl[1];
$pc{$id}=$gene;
}
my@files=glob(“*_PC.fa”);
foreach my$fil(@files){
我的$seqio=Bio::seqio->new(-format=>'fasta',-file=>$fil);
my$file=$fil;
$file=~/^(+)\u PC.fa/;
我的$outfile=$1。“\u core.fa”;
打开(OUTFILE,“>”,$OUTFILE)或死“无法打开$OUTFILE\n”;
while(my$seqobj=$seqio->next_seq){
my$seqid=$seqobj->display_id;
my$nuc=$seqobj->seq();
$fasta{$seqid}=$nuc;
foreach my$密钥(密钥%fasta){
my@spl2=split(/\\124;/,$key);
my$fasta_gene=$spl2[1];
if($fasta_基因eq(键%fasta)){
打印输出文件“>$key\n$fasta{$key}\n”;
}
}
}
关闭输出口;
}
提前谢谢
%fasta
如果%pc
中的所有值都作为键存在于%fasta
中,则会打印%fasta
my $some_values_missing = grep { ! exists $fasta{$_} } values %pc;
unless ($some_values_missing) {
print "key:$_; value:$fasta{$_}\n" for keys %fasta;
}