由于我是生物学家并且是 Perl 新手,我希望得到 Perl 专家的帮助
猫输入.txt
##gff-version 2
##source-version geneious 5.6.3
gi371443188gbJH5566721_extraction_reversed Geneious CDS 1043 1132 . + . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed Geneious CDS 2063 2260 . + . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed Geneious CDS 2336 2593 . + . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed Geneious CDS 3474 3633 . + . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed Geneious extracted region 1 13933 . + . Name=Extracted region from gi|371443188|gb|JH556672.1|;Extracted interval="2010140 <- 2024072"
我的输出.txt
gi371443188gbJH5566721_extraction_reversed CDS 2023029 2022940 . - . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed CDS 2022009 2021812 . - . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed CDS 2021736 2021479 . - . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed CDS 2020598 2020439 . - . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
###
我的预期输出
gi_371443188_gb_JH5566721 gene 2020598 2023029 . - . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.13412469767431
gi_371443188_gb_JH5566721 CDS 2020598 2020439 . - . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi_371443188_gb_JH5566721 CDS 2021736 2021479 . - . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi_371443188_gb_JH5566721 CDS 2022009 2021812 . - . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi_371443188_gb_JH5566721 CDS 2023029 2022940 . - . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
###
我需要 Perl 专家的帮助来重新格式化下面给出的 Perl 代码中的输出。
1.我想在输出中将分数添加到数组[0](即gi371443188gbJH5566721_extraction_reversed为gi_371443188_gb_JH5566721)
2.根据输出的第3列和第4列的值按升序对CDS的行进行排序(参见预期输出)
3.在文件顶部添加新行作为 gi_371443188_gb_JH556672.1 基因,其中包含 CDS 行的最小值和最大值(参见预期输出)
我的 Perl 代码如下。
#usr/bin/perl;
open(FH,"$ARGV[0]");
my %num="";
my %all="";
while(<FH>){
chomp $_;
my @array=split("\t"); #print "$array[2]\n";
if($array[2] eq "extracted region"){
$array[8]=~/.*\w+=\"\d+ <- (\d+)"/gm;
$num{$array[0]}="$1";
}
if($array[2] eq "CDS"){
$all{$array[0]}.="$_\n";
}
}
foreach $i (keys %all){
my @line=split "\n",$all{$i};
for ($j=0;$j<=$#line;$j++){
my @new_line=split "\t",$line[$j];
my $pos1=$num{$i}-$new_line[3];
my $pos2=$num{$i}-$new_line[4]; #print $num{$i}; exit;
$new_line[6] =~ s/\+/-/g;
print "$new_line[0]\t$new_line[2]\t$pos1\t$pos2\t$new_line[5]\t$new_line[6]\t$new_line[7]\t$new_line[8]\n";
}
}
print "###\n";
答案1
这将做到这一点(即,我的输出与你的相匹配),尽管它不是最干净的。
用于添加下划线的正则表达式可能可以组合起来。但对于排序,您需要将所有输出行推送到一个列表,然后对其进行排序(也可以在传入端完成,但您仍然需要首先将所有输出行放在一个位置)。
--- test.pl~ 2012-07-13 12:04:36.000000000 -0700
+++ test.pl 2012-07-13 12:17:58.000000000 -0700
@@ -1,4 +1,4 @@
-#usr/bin/perl
+#!/usr/bin/perl
use strict;
open(FH,"$ARGV[0]");
@@ -18,6 +18,7 @@
}
my $i;
+ my @output;
foreach $i (keys %all){
my @line=split "\n",$all{$i};
@@ -27,8 +28,15 @@
my $pos1=$num{$i}-$new_line[3];
my $pos2=$num{$i}-$new_line[4]; #print $num{$i}; exit;
$new_line[6] =~ s/\+/-/g;
- print "$new_line[0]\t$new_line[2]\t$pos1\t$pos2\t$new_line[5]\t$new_line[6]\t$new_line[7]\t$new_line[8]\n";
+ $new_line[0] =~ s/gi/gi_/;
+ $new_line[0] =~ s/gb/_gb_/;
+ $new_line[0] =~ s/_extraction_reversed//;
+ push @output, "$new_line[0]\t$new_line[2]\t$pos1\t$pos2\t$new_line[5]\t$new_line[6]\t$new_line[7]\t$new_line[8]\n";
}
}
+ @output = sort (@output);
+ foreach my $out (@output) {
+ print $out;
+ }
print "###\n";