我有这样我怎样才能隔离数据块从一个文件
a score=-120.0
s Chicken.chr22 947 4 + 4081097 tgag
s Turkey.chrZ 31560312 4 - 81011772 ttct
s Mallard.apl2 2559751 4 - 153042893 TTCG
a score=61344.0
s Chicken.chr22 951 15 + 4081097 c------tgggtgaagcactg
s Turkey.chrZ 31560316 15 - 81011772 t------tgggtaaggaactg
s Mallard.apl2 2559755 15 - 153042893 T------TGGGTTAGAAACTG
s Rock_pigeon.scaffold637 370291 15 + 418352 G------AGGGTCAGTTTCTG
s Common_cuckoo.scaffold569 739303 15 + 1009149 C------TGGGTTGAAAACTG
s Anna_s_hummingbird.scaffold44 3039342 15 - 10500161 C------TGGGTTAAACACTG
s Hoatzin.scaffold186 66281 15 + 155126 C------TGGATAAAGAACTG
s Emperor_penguin.Scaffold155 7152296 15 - 9595628 C------TGGGTAAAAAATTG
s Adelie_penguin.scaffold207 570235 15 - 3061884 C------TGGGTCAAAAACTG
s Crested_ibis.scaffold108 24271571 15 - 27015053 C------TGAGTAAAAACCTG
s Little_egret.scaffold238 365328 14 + 1015180 -------TGGGTTAAAAACTG
s Peregrine_falcon.scaffold41_1 3239034 14 - 3351735 -------TGGGTTAAAAGCTG
s Budgerigar.megascaffold18 4987476 14 + 17573940 -------TGGATAAAGAACTG
s Golden_collared_manakin.scaffold312 1652783 16 + 1993610 A-----CAGGGTTAGGAACTG
s Downy_woodpecker.scaffold1064 9341 21 - 117330 AGTGAGGTGGATTGTGAACTG
每个数据块具有与a
开始,并且其他行开始s
第一线中的文件。之后,一个空白行分隔块。
不幸的是每个块包含不同数量的s
线。
我想要收集将具有第一行(从a
开始)和s
行的数目等于我将作为参数传递的数字的块(在具有相同格式的不同文件中) 。
我写了下面的脚本,但它不工作。有人可以帮助我吗?
#!/usr/bin/perl
use strict;
#use warnings;
use POSIX;
my $maf = $ARGV[0];
my $species = $ARGV[1];
#It filters the maf file. takes the blocks with all the species
open my $maf_file, $maf or die "Could not open $maf: $!";
my $count = 0;
my @array;
while (my $mline = <$maf_file>) {
next if /^\s*#/; #to avoid some lines with comments
if ($mline =~ /^a/) {
push(@array, $mline);
}
if ($mline =~ /^s/) {
until ($mline != ~/\s/) {
push(@array, $mline);
$count += 1;
}
foreach (@array) {
if ($count == $species) {
print "$_\n";
}
}
undef(@array);
}
这是圣诞大餐的选择? :) – simbabque
你是什么意思的“它不工作”?是否有错误讯息?它是否做任何事情?你在谈论另一个文件...这个文件看起来和你给的样本一样吗? – simbabque
此外,检查出https://metacpan.org/pod/Bio::AlignIO::maf。它可能是你正在寻找的东西。 – simbabque