2016-12-05 1 views
-1

私は、サブルーチンを起動することによって、2つのスクリプトを1つのスクリプトに結合しようとしています。問題は、私が1つの下付き文字から別の下付き文字に自分の入力を向けるのに問題があることです。複数のスクリプトでこれを行う必要があります。これらは、それらのリスト全体の最初の2つのスクリプトです。サブルーチンperlを使用してスクリプトを1つのスクリプトに結合する

コード1で生成されたデータは、コード2に送信する必要があります。コード2では、生成されたファイルと元のファイルを比較する追加のステップがあります。

Code 1: 
subst_head_1($infile); 


sub subst_head_1 
{ 
    ##this code helps organise the file in a way that it makes it more convenient for the file to be pushed into a hash for later analysis 

    ##opening file 
    my $i = $_[0]; 

    open(IN, "<$i") || die "\n Error: Cannot open the infile: $infile\n"; 
    # open(OUT, ">op.fa"); 

    ##giving all the headers in the original file line numbers 
    my $lineno = 1; 

    while(<IN>) 
    { 
    chomp; 
    if ($_ =~ />/) 
    { 

     $_ = $lineno++,"\t", $_ ,"\n"; 

     subst_head_2($_); 

    } 
    } 

} 
    ##file organised in the following format; eg., "2>CBB_deg7180000000601_1100_2101_3" 

sub subst_head_2 
{ 

    ##opening files with header information(result of head-subs-1) and the original sequence(submitted query file) file for further info 
    my $i = $_[0]; 
    #print $i; 
    my $i_1 = $_[1]; 


    ##pushing file(headerinfo.txt) with the header information into a hash 
    open(IN, "<$i"); 
    my @file = <IN>; 

    my $file2 = join('', @file); 

    my %hash = split(/[\t\n]/, $file2); 

    ##opening the original file with the sequence information into an array 
    open(IN1, "<$i_1"); 
    my @fila = <IN1>; 


    ##foreach of the sequnces in the sequence file 
    foreach my $fila(@fila) 
    { 

    ##Substituting any "*" in the file, if any, especially at the end of some of sequnces which were present in the file 

    $fila =~ s/\*//g; 

    ##regex for matching with the header information in the file with all the query information 

    if($fila =~ /^\>(\S+).*/) 
    { 

     ##putting info(eg., CBB_deg7180000000601_1100_2101_3) into a variable $user 

     my $user = $1; 

     foreach my $has(sort keys %hash) 
     { 

     ##regex for the values in the key-value relationship in the headerinfo file 
     if($hash{$has} =~ /^\>(\S+).*/) 
     { 

      ##putting info(eg., CBB_deg7180000000601_1100_2101_3) into a variable $user1 
      my $user1 = $1; 

      ##is the info the same?; if it is, then substitute it in the original with key from headerinfo.txt 

      if($user eq $user1) 
      { 

      ##substitute header in the original file with the unique number; 

      $fila =~ s/^\>(\S+).*\n/>$has\n/; 

      } 
     } 
     } 
    } 
    } 

    print @fila; 
} 
+0

グローバル変数はどうですか?または、あるサブの結果を別のサブに渡すか? – Robert

+0

こんにちは、それは問題です。私はどのように1つのサブから別の結果を渡すかを理解することができません。 –

+0

'' 'subst_head_2(subst_head_1(file))' 'の行に沿って何か試してみましたか?' ' – tomc

答えて

0

私の答えは、あなたのコードに見られる最も直面する問題を説明します。代わりに、あなたのプログラムを変更する前に、あなたはおそらくこれを持っていた

$_ = $lineno++,"\t", $_ ,"\n"; 

このラインの

print $lineno++,"\t", $_ ,"\n"; 

あなたがしたすべては$_にこのすべてを置くために割り当てにそれを変更しました。しかし、変数はスカラーです。つまり、それは単一の値です。それはリストを取ることができません。あなたの割り当ては=の右側にある最初のものを$_に入れます。これは($var++がインクリメントしますが、古い値を返します)の$lineno++の結果です。残りはすべて破棄されます。

今すぐあなたの電話subst_head_2($_)には回線番号しかありません。しかし、サブルーチンでは2つの引数が必要です。 (変数の恐ろしい名前です)あなたがファイルを開くには、ファイル名として使用することはできませんので、undefある

my $i = $_[0]; 
my $i_1 = $_[1]; 

秒1、$i_1

あなたの説明には多くの情報が欠けていますので、実際に何をする必要があるかはわかりません。サンプルの入力データと出力データを提供し、コードで何をしたいか考えてください。

関連する問題