As I am biologist and new to perl, I would like to get help of perl expert
cat input.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"
My output.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
###
My expected ouput
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
###
I would like help of perl expert in reformating my output in perl code given below.
1.I would like add under score to array[0] in output (i.e gi371443188gbJH5566721_extraction_reversed as gi_371443188_gb_JH5566721)
2.sort rows of CDS in ascending order based on values of column3 & 4 of the output (see expected output)
3.Add new row at the top of file as gi_371443188_gb_JH556672.1 gene with minimum & maximum value of CDS rows (see expected output)
My Perl code is given below.
#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";
perl
code withinput.txt
and getoutput.txt
? Would you like to get the second output instead? Yourperl
code doesn't compile in my test, so I couldn't try that at least.use strict
and run it likeperl script.pl input.txt
assumingscript.pl
has the code of your question, and the output was only###
. What is your whole code and how do you run it to get theoutput.txt
of your question?