entrada de gato1.txt
##gff-version 2
##source-version geneious 5.6.4
Xm_ABL1 Geneious CDS 1 168 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 169 334 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 335 628 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 629 901 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 902 985 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 986 1165 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 1166 1350 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 1351 1504 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious BLAST Hit 169 334 . + .
Xm_ABL1 Geneious extracted region 1 168 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="351297 -> 351464"
Xm_ABL1 Geneious extracted region 169 334 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="371785 -> 371950"
Xm_ABL1 Geneious extracted region 335 628 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="372554 -> 372847"
Xm_ABL1 Geneious extracted region 629 901 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="374760 -> 375032"
Xm_ABL1 Geneious extracted region 902 985 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="375230 -> 375313"
Xm_ABL1 Geneious extracted region 986 1165 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="375992 -> 376171"
Xm_ABL1 Geneious extracted region 1166 1350 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="376575 -> 376759"
Xm_ABL1 Geneious extracted region 1351 1504 . + . Name=Extracted region from gi|371443098|gb|JH556762.1|;Extracted interval="376914 -> 377067"
Verifique input1.txt, la columna CDS y la región extraída tienen el mismo número de filas. Si son iguales, obtenga los valores de la columna $14 de la región extraída (351297, 351464,371785,371950) y reemplace estos valores en las filas CDS $4 y $5 (por ejemplo, en CDS 1.ª fila 1 con 351297, 168 con 351464, 169 con 371785 , 334 con 371950 y así sucesivamente). Imprima las únicas filas de CDS reemplazadas de la siguiente manera
salida de gato1.txt
##gff-version 2
##source-version geneious 5.6.4
Xm_ABL1 Geneious CDS 351297 351464 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 371785 371950 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 372554 372847 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 374760 375032 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 375230 375313 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 375992 376171 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 376575 376759 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Xm_ABL1 Geneious CDS 376914 377067 . + . Name=Xm_ABL1;created by=User;modified by=User;ID=w0IVHutPuN4H4FVDCg4sFVRaJjQ.1340919460469.4
Tengo otro archivo de entrada, input2.txt
entrada de gato2.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"
Quiero tomar $14 de la última línea (interval="1960862) solo agregar el número (2010140) a la columna de $4 (1043,1132,2063..3633), es decir, (1043+2010140=2011183, 2063+2010140=2012203, ) y a la columna $5 (1132+2010140=2011272,2260+2010140=2012400 ), ignore la última línea.
La salida debería verse así:
salida de gato2.txt
##gff-version 2
##source-version geneious 5.6.3
gi371443188gbJH5566721_extraction_reversed Geneious CDS 2011183 2011272 . + . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed Geneious CDS 2012203 2012400 . + . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed Geneious CDS 2012476 2012733 . + . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
gi371443188gbJH5566721_extraction_reversed Geneious CDS 2013614 2013773 . + . Name=Xm ITGB3;created by=User;modified by=User;ID=Pa0FVoXpt/GgL1I/VO7LY0UlFAc.1341246976743.1
Pero necesito un script en Perl, basado en la entrada del usuario (puede ser input1.txt o input2.txt), verifica las condiciones que dan el resultado1.txt o el resultado2.txt.
Respuesta1
Supuse que las líneas de la región extraída siguen las líneas CDS para cada alineación.
Copie este código en script.pl:
use strict;
use warnings;
my $input = 1;
my @field = ('CDS','extracted region');
my (%data);
my (%counter);
&zero;
while ( <> ) {
## Omit header.
next if $. == 1;
next if $. == 2;
## Remove last '\n'.
chomp;
## Split line in tabs.
my @f = split /\t/;
## Is loop over?
if ( $f[2] =~ /$field[0]/ && $counter{$field[1]} > 1 )
{
&comparing;
&zero;
}
## Count number of $field[0] and $field[1] line
$counter{$f[2]}++;
## Storing data
@{$data{$f[2]}[$counter{$f[2]}]} = @f;
}
&comparing;
sub zero {
$data{$field[0]} = [];
$data{$field[1]} = [];
$counter{$field[0]} = 0;
$counter{$field[1]} = 0;
}
sub comparing {
## Is same line ($field[0] and $field[1])? if ( $input == 1 )
if ( $counter{$field[0]} == $counter{$field[1]} || $input == 2 )
{
&recover;
&stamp;
}
}
sub recover {
my $pos = &input2(0,0) if ( $input == 2 );
for my $i ( 1 .. $#{ $data{$field[0]} } ) {
&input1($i) if ( $input == 1 );
&input2($i,$pos) if ( $input == 2 );
}
}
sub input1 {
#;Extracted interval="376914 -> 377067"
$data{$field[1]}[$_[0]][8] =~ m/;Extracted interval="(\d+) /;
$data{$field[0]}[$_[0]][3] = $1;
$data{$field[1]}[$_[0]][8] =~ m/;Extracted interval="\d+ -> (\d+)"/;
$data{$field[0]}[$_[0]][4] = $1;
}
sub input2 {
if ( $_[0] == 0 )
{
#;Extracted interval="2010140 <- 2024072"
$data{$field[1]}[1][8] =~ m/;Extracted interval="(\d+) /;
$1;
}
else
{
$data{$field[0]}[$_[0]][3] = $_[1] + $data{$field[0]}[$_[0]][3];
$data{$field[0]}[$_[0]][4] = $_[1] + $data{$field[0]}[$_[0]][4];
}
}
sub stamp {
for my $i ( 1 .. $#{ $data{$field[0]} } ) {
for my $j ( 0 .. $#{ $data{$field[0]}[$i] } ) {
print "$data{$field[0]}[$i][$j]\t";
}
print "\n";
}
}
Podrías ejecutar el script perl con input1.txt:
perl script.pl input1.txt > output1.txt
si modifica la línea:
my $input = 1;
con
my $input = 2;
podrías ejecutar el script perl con input2.txt:
perl script.pl input2.txt > output2.txt
El script Perl también podría obtener dos argumentos: archivo de entrada y tipo [12].
EDITAR
Enhttps://stackoverflow.com/questions/1730333/how-do-i-use-getoptions-to-get-the-default-argumentHay algunos métodos para obtener argumentos.
Si modifica la línea:
my $input = 1;
con
my $input = 1;
$input = $ARGV[1] if defined $ARGV[1];
podrías ejecutar el script perl con input1.txt:
perl script.pl input1.txt > output1.txt
o
perl script.pl input1.txt 1 > output1.txt
y podrías ejecutar el script perl con input2.txt:
perl script.pl input2.txt 2 > output2.txt