我正在尝试将一个列表(screens.txt )中第1列的每个元素与另一个列表( new_list.txt )中第1列的任何元素进行比较,如果匹配,则打印列表的整行(screens.txt)一个单独的文本文件(matched.txt)。我设法选择了正确的列,但我得到的输出是列表中的行(new_list.txt)而不是列表(screens.txt),并且只找到一个命中,所以看起来循环也有问题.
new_list.txt格式 => first_column->double_tab->the_rest
我是 perl 编程的新手。任何帮助将不胜感激!
这是我到目前为止所做的:
#!usr/bin/perl
use warnings;
$list = "new_list.txt";
$screens = "screens.txt";
$result = "matched.txt";
open (FA, "<$list") or die "Can't read source file $list: $!\n";
open (RES, ">$result") or die "Can't write on file $result: $!\n";
$n = 0;
$column = 10;
while ($line = <FA>) {
@description = split (' ', $line);
@ID = split ('\\t', $description[0]);
#print just first column from the list
# print "$ID[0]\n";
}
close (FA);
open (FA, "$screens") or die "Can't read source file $screens: $!\n";
while ($file = <FA>) {
@table = split (' ', $file);
@accession_no = split ('\ ', $table[0]);
# print the first column from the list
# print "$accession_no[0]\n";
}
open (FA, "<$list") or die "Can't read source file $list: $!\n";
while ($line = <FA>) {
print "$line\n";
@description = split (' ', $line);
@ID = split ('\\t', $description[0]);
if ($accession_no eq $ID[0]) {
$n = $n+1;
for ($i = 0; $i < $column; $i++) {
print RES "$file";
}
print "\n";
}
}
close (FA);
close (RES);
print "Hits found: $n\n";
这是 next_list.txt 的示例:Q9UKA8 RCAN3_HUMAN 0
Q9UKA8-2 RCAN3_HUMAN 0
Q9UKA8-3 RCAN3_HUMAN 0
Q9UKA8-4 RCAN3_HUMAN 0
Q9UKA8-5 RCAN3_HUMAN 0
Q9GZP0 PDGFD_HUMAN 0
这是screens.txt的输入文件:
Q9GZP0 GDLDLASEST 支架连接因子 B2 (SAF-B2) SAFB2
Q9UKA8-5 QKAFNSSSFN Ran GTPase 激活蛋白 1 (RanGAP1) RANGAP1
我有兴趣检查Q9GZP0和Q9UKA8-5(第一列)
来自screens.txt是在new_list.txt的第一列,如果他们
然后从screen.txt打印整行/行。
先感谢您!