解析具有多个列的文本文件

时间:2013-07-03 02:32:41

标签: perl bioinformatics

我试图提取以下文件中的11列中的每一列:

http://bioinfo.mc.vanderbilt.edu/TSGene/Human_716_TSGs.txt

...成为初级大学生物信息学项目的标量列表。我的努力,请参见下文,有效但不完美,因为列之间的空白量不同(请参阅文件顶部以获取详细信息)。

use strict;
use warnings;

open FH, '<', 'tsg.txt' or die $!;
my $data = do {local $/; <FH>};
close FH or die $!;

my($id, $sym, $alias, $xref, $chromo, $band, $name, $gene_t, $desc, $nuc_seq,
   $pro_seq) = $data =~ /(\S+)\s+
                         (\S+)\s+
                         (\S+)\s+
                         (\S+)\s+
                         (\S+)\s+
                         (\S+)\s+

                         (\S+)\s+
                         /xms;

print "GeneID: $id", "\n";
print "Gene_symbol: $sym", "\n";
print "Alias: $alias", "\n";
print "XRef: $xref", "\n";
print "Chromosome: $chromo", "\n";
print "Cytoband: $band", "\n";

print "Full_name: $name", "\n";
#print "Gene_type: $gene_t", "\n";
#print "Description: $desc", "\n";
#print "Nucleotide_sequence: $nuc_seq", "\n";
#print "Protein_sequence: $pro_seq", "\n";

感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

此文件看起来与tab分开,您应该能够使用split上的\t将每一行存储到数组中:

my @columns = split( "\t", $data );

然后您可以通过编入索引来访问您的列:

my $id = $columns[0];