Perl-get 입력, 조건 확인

Perl-get 입력, 조건 확인

고양이 input1.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"

input1.txt를 확인하세요. CDS 열과 추출된 영역의 행 수가 동일합니다. 동일한 경우 추출된 영역 $14 열(351297, 351464,371785,371950)에서 값을 가져오고 CDS 행 $4 &$5에서 이 값을 바꿉니다(예: CDS 첫 번째 행 1에서 351297로, 168에서 351464, 169에서 371785로) , 334, 371950 등). 다음과 같이 교체된 CDS 행만 인쇄합니다.

고양이 출력1.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

또 다른 입력 파일인 input2.txt가 있습니다.

고양이 input2.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"

마지막 줄(간격="1960862)의 $14를 취하고 싶습니다. 숫자(2010140)만 $4 열(1043,1132,2063..3633)에 추가합니다. 즉, (1043+2010140=2011183, , 2063+2010140=2012203, ) 및 $5 열(1132+2010140=2011272,2260+2010140=2012400)에서는 마지막 줄을 무시합니다.

출력은 다음과 같아야 합니다.

고양이 출력2.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

하지만 하나의 Perl 스크립트가 필요합니다. 사용자 입력(input1.txt 또는 input2.txt일 수 있음)을 기반으로 조건이 output1.txt 또는 output2.txt를 제공하는지 확인합니다.

답변1

추출된 영역 선은 각 정렬에 대해 CDS 선을 따른다고 가정했습니다.

이 코드를 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";
    }
}

input1.txt를 사용하여 Perl 스크립트를 실행할 수 있습니다.

perl script.pl input1.txt > output1.txt

줄을 수정하는 경우:

my $input = 1;

~와 함께

my $input = 2;

input2.txt를 사용하여 Perl 스크립트를 실행할 수 있습니다.

perl script.pl input2.txt > output2.txt

Perl 스크립트는 입력 파일과 유형[12]이라는 두 가지 인수를 얻을 수도 있습니다.

편집하다

~ 안에https://stackoverflow.com/questions/1730333/how-do-i-use-getoptions-to-get-the-default-argument인수를 얻으려는 몇 가지 방법이 있습니다.

라인을 수정하는 경우:

my $input = 1;

~와 함께

my $input = 1;
$input = $ARGV[1] if defined $ARGV[1];

input1.txt를 사용하여 Perl 스크립트를 실행할 수 있습니다.

perl script.pl input1.txt > output1.txt

또는

perl script.pl input1.txt 1 > output1.txt

input2.txt를 사용하여 Perl 스크립트를 실행할 수 있습니다.

perl script.pl input2.txt 2 > output2.txt

관련 정보