0

我试图查看散列 %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;    
}

提前致谢!

4

1 回答 1

1

%fasta%pc如果来自的所有值都作为键存在,则打印%fasta

my $some_values_missing = grep { ! exists $fasta{$_} } values %pc;

unless ($some_values_missing) {
  print "key:$_; value:$fasta{$_}\n" for keys %fasta;
}
于 2013-06-12T07:06:35.967 回答