我有一個龐大的製表符分隔的文件是這樣的:從一個單獨的列表的文本文件選擇數據 - Perl或UNIX
contig04733 contig00012 77個
contig00546 contig01344 12個
contig08943 contig00001 14個
contig00765 contig03125 88
等
而且我有一個單獨的製表符分隔的文件,只有這樣,這些重疊羣對集:
contig04733 contig00012
contig08943 contig00001
等
我想提取到一個新的文件中,與在第二列出的對應所述第一文件中的行。在這個特定的數據集中,我認爲兩個文件中的每對應該是相同的。但也想知道,如果你說:
文件1 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);
另外如果可能的話,我想轉換第一個文件中的第三列 - 將數字除以100,然後對其進行平方根。例如。本例中新文件的第一行是contig04733 contig00012 0.877 – 2013-03-08 14:18:50
向我們顯示您的代碼。你有什麼嘗試? – 2013-03-08 14:50:59
@GregBacon - 試試這個: use strict; 使用警告; #打開重疊羣對列表 打開(PAIRS,「$ ARGV [0]」)或死「打開帶重疊羣對的輸入文件時出錯」; #hash存儲重疊羣ID - 我想?! my $ pairs; #閱讀對列表並讀入內存? while(){ \t chomp $ _; \t #get rid riddle whitepace \t $ pairs - > {$ _} = 1; } close(PAIRS); #打開數據文件 打開(DATA,「$ ARGV [1]」)或死「錯誤打開序列對文件\ n」; while(){ \t chomp $ _; \t \t my($ contigs,$ identity)= split(「\ t」,$ _); \t if(defined $ pairs - > {$ contigs}){ \t \t print STDOUT「$ _ \ n」; \t} } close(DATA); –
2013-03-08 15:52:32