0

2セットのファイルがあります。1つのファイルに遺伝子名のリストが表示されます(1行に1つの遺伝子)。2番目のファイルには、遺伝子ペアのリストがあります(たとえば、=> '1,2'と1つの遺伝子ペアperl行)。遺伝子名は数字です。既知の遺伝子ペアを除いて、考えられるすべての遺伝子の組み合わせをリストしたいと思います。

私の出力は次のようになります。

3,4  
4,5  
6,7  
...  
...  

しかし、私はこのようなものを手に入れます=>

,4  
,5  
,7  

最初の要素はすべて印刷されません。コードの何が問題なのか正確にはわかりません。誰か助けてもらえますか?

私のコード:

#! usr/bin/perl

use strict;
use warnings;

if (@ARGV !=2) {
   die "Usage: generate_random_pairs.pl <entrez_genes> <known_interactions>\n";
}
my ($e_file, $k_file) = @ARGV;

open (IN, $e_file) or die "Error!! Cannot open $e_file\n";
open (IN2, $k_file) or die "Error!! Cannot open $k_file\n";

my @e_file = <IN>; chomp (@e_file);
my @k_file = <IN2>; chomp (@k_file);

my (%known_interactions, %random_interactions);

foreach my $line (@k_file) {
    my @array = split (/,/, $line);
    $known_interactions{$array[0]} = $array[1];
}

for (my $i = 0; $i <= $#e_file; $i++) {
    for (my $j = $i+1 ; $j <= $#e_file; $j++) {
        if ((exists $known_interactions{$e_file[$i]}) && ($known_interactions{$e_file[$i]} == $e_file[$j])) {next;}
        if ((exists $known_interactions{$e_file[$j]}) && ($known_interactions{$e_file[$j]} == $e_file[$i])) {next;}
        print "$e_file[$i],$e_file[$j]\n";
    }
}
4

1 に答える 1

3

ファイルは行末にCRLFを使用していますが、行末にLFを使用するシステムを使用しているため、プログラムは次のように出力します。

"3" <CR> "," "4" <CR> <LF>

ターミナルは次のように表示されます

,4

を使用して行末を修正する

dos2unix inputfile

または変更

chomp(@e_file);
chomp(@k_file);

s/\s+\z// for @e_file;
s/\s+\z// for @k_file;
于 2012-07-31T03:15:56.663 に答える