我有10個文件夾,並在每個文件夾中,我有兩個文件(CSV,逗號delimeted)在以下格式。解析CSV文件和匹配
文件1:
Ensembl Gene ID,Ensembl Transcript ID,Exon Chr Start (bp),Exon Chr End (bp),Exon Rank in Transcript, Transcript count,Gene End (bp) ,Gene Start (bp),Strand
ENSG00000271782,ENST00000607815,50902700,50902978,1,1,50902978,50902700,-1
ENSG00000232753,ENST00000424955,103817769,103817825,1,1,103828355,103817769,1
ENSG00000232753,ENST00000424955,103827995,103828355,2,1,103828355,103817769,1
ENSG00000225767,ENST00000424664,50927141 50927168,1,1,50936822,50927141,1
文件2:
number,Start pos,End Pos
1,41035,41048
3,36738,36751
3,38169,38182
3,40264,40277
我試圖匹配第二文件firstfile
- 在第二個文件的colum1數量是關鍵在第一個文件中記錄編號。
- 從第一個文件
在需要時輸出提取最後3個colums:
1,ENSG00000271782,41035,41048,50902978,50902700,-1
3,ENSG00000225767,36738,36751,50936822,50927141,1
3,ENSG00000225767,38169,38182,50936822,50927141,1
3,ENSG00000225767,40264,40277,50936822,50927141,1
我已經開始從第二使用TexT::CSV
讀書,但需要幫助。
use strict;
use warnings;
use lib 'C:/Perl/lib';
use Text::CSV;
my $file1 = "infile1";
open my $fh, "<", $file1 or die "$file1: $!";
my $file2 = "infile2"
open my $fh2, "<", $file2 or die "$file2: $!";
my $csv = Text::CSV->new ({
binary => 1,
auto_diag => 1,
});
while (my $row = $csv->getline ($fh2)) {
print "@$row\n"; # I am stuck in extraction ? do I need to put another while loop for fh1
}
close $fh1;
close $fh2;
第一個文件中沒有「關鍵記錄號」。沒有這樣的列,並且該ID上沒有'3'。 – TLP
我的意思是關鍵記錄號是數字表示第一個文件的Ensembl Gene ID列中的記錄號。 1 ENSG00000271782 – user61398
'3'仍然不是'ENSG00000225767'。這些文件之間沒有關係。 – TLP