【发布时间】:2013-02-24 02:32:26
【问题描述】:
我有一个巨大的制表符分隔文件,如下所示:
contig04733 contig00012 77
contig00546 contig01344 12
contig08943 contig00001 14
contig00765 contig03125 88
等
我有一个单独的制表符分隔文件,其中只有这些重叠群对的一个子集,如下所示:
contig04733 contig00012
contig08943 contig00001
等
我想将第一个文件中与第二个文件中列出的行相对应的行提取到一个新文件中。在这个特定的数据集中,我认为在两个文件中每对的哪一种方式应该是相同的。但也想知道如果说:
file1 contig08943 contig00001 14
但在file2中它的
contig00001 contig08943
我仍然想要这种组合,是否也可以为此编写脚本?
我的代码如下。
use strict;
use warnings;
#open the contig pairs list
open (PAIRS, "$ARGV[0]") or die "Error opening the input file with contig pairs";
#hash to store contig IDs - I think?!
my $pairs;
#read through the pairs list and read into memory?
while(<PAIRS>){
chomp $_; #get rid of ending whitepace
$pairs->{$_} = 1;
}
close(PAIRS);
#open data file
open(DATA, "$ARGV[1]") or die "Error opening the sequence pairs file\n";
while(<DATA>){
chomp $_;
my ($contigs, $identity) = split("\t", $_);
if (defined $pairs->{$contigs}) {
print STDOUT "$_\n";
}
}
close(DATA);
【问题讨论】:
-
另外,如果可能的话,我想转换第一个文件中的第 3 列 - 将数字除以 100,然后对其求平方根。例如。本例中新文件的第一行是 contig04733 contig00012 0.877
-
向我们展示您的代码。你试过什么?
-
@GregBacon - 试试这个:使用严格;使用警告; #open contig pair list open (PAIRS, "$ARGV[0]") or die "Error opening the input file with contig pairs"; #hash 来存储 contig ID - 我想?!我的 $pairs; #读取对列表并读入内存?而(
){ chomp $_; #摆脱结束的空白 $pairs->{$_} = 1; } 关闭(对); #open data file open(DATA, "$ARGV[1]") or die "Error opening the sequence pairs file\n";而(){ chomp $_;我的 ($contigs, $identity) = split("\t", $_); if (defined $pairs->{$contigs}) { print STDOUT "$_\n"; } } 关闭(数据); -
@GregBacon 但这需要我删除前两列之间的间隙/制表符,然后再次将它们分开我想....对不起,我对 perl 完全陌生,所以只是试图将网络上的示例拼接在一起!
标签: perl unix text-processing csv