我正在尝试从包含字符串的文件中提取子字符串。该文件是这样的:
>scaffold30 24194
CTTAGCAGCAGCAGCAGCAGTGACTGAAGGAACTGAGAAAAAGAGCGAGCTGAAAGGAAGCATAGCCATTTGGGAGTGCCAGAGAGTTGGGAGG GAGGGAGGGCAGAGATGGAAGAAGAAAGGCAGAAATACAGGGAGATTGAGGATCACCAGGGAG.........
.................
为了提取子字符串,我使用了一个包含子字符串开始和结束坐标的文件。我写的脚本是:
open my $coords_info, $coords_file or die "Could not open $coords_file: $!";
open my $chr_info, $chrom or die "Could not open $chrom: $!";
my $count = 0;
while(my $sline = <$chr_info>) {
if ($sline!~ m/^>/) {
chomp $sline;
print $sline;
foreach(my $cline = <$coords_info>) {
my@data = split('\t', $cline);
my $start = $data[0];
my $end = $data[1];
my $offset = $end - $start;
$count++;
my $sub = substr($sline, $start+1, $offset);
print ">conserved $count\n";
print $sub;
}
}
}
我的问题是我想将文件的所有字符串加载到 sline 变量中(而不是在每次迭代中逐行加载,然后使用 foreach 来提取子字符串。我知道这听起来是一个微不足道的问题,但可以你帮帮我好吗??谢谢...