[英]Parsing a text file with multiple columns
我正在嘗試提取以下文件中的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";
謝謝您的幫助。
該文件看起來像它的tab
分開,您應該能夠使用\\t
上的split
將每一行存儲到一個數組中:
my @columns = split( "\t", $data );
然后,您可以通過建立索引來訪問列:
my $id = $columns[0];
等等
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.