给定一组基因和现有的一对基因,我想生成尚未存在的新基因对。
基因文件具有以下格式:
123
134
23455
3242
3423
...
...
基因对文件具有以下格式:
12,345
134,23455
23455,343
3242,464452
3423,7655
...
...
但是我仍然在 known_interactions 和 new_pairs 之间得到了一些共同的元素。我不确定错误在哪里。
对于参数,
perl generate_random_pairs.pl entrez_genes_file known_interactions_file 250000
我得到了一个共同的元素 15880。数字 250000 是告诉我希望程序生成多少个随机对。
#! usr/bin/perl
use strict;
use warnings;
if (@ARGV != 3) {
die "Usage: generate_random_pairs.pl <entrez_genes> <known_interactions> <number_of_interactions>\n";
}
my ($e_file, $k_file, $interactions) = @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>; s/\s+\z// for @e_file;
my @k_file = <IN2>; s/\s+\z// for @k_file;
my (%known_interactions);
my %entrez_genes;
$entrez_genes{$_}++ foreach @e_file;
foreach my $line (@k_file) {
my @array = split (/,/, $line);
$known_interactions{$array[0]} = $array[1];
}
my $count = 0;
foreach my $key1 (keys %entrez_genes) {
foreach my $key2 (keys %entrez_genes) {
if ($key1 != $key2) {
if (exists $known_interactions{$key1} && ($known_interactions{$key1} == $key2)) {next;}
if (exists $known_interactions{$key2} && ($known_interactions{$key2} == $key1)) {next;}
if ($key1 < $key2) { print "$key1,$key2\n"; $count++; }
else { print "$key2,$key1\n"; $count++; }
}
if ($count == $interactions) {
die "$count\n";
}
}
}