0

次のようなタブ区切りのテキスト ファイルがあります。

contig11 GO:100 other columns of data
contig11 GO:289 other columns of data
contig11 GO:113 other columns of data
contig22 GO:388 other columns of data
contig22 GO:101 other columns of data

そして、このような別のもの:

contig11 3 N
contig11 1 Y
contig22 1 Y
contig22 2 N

ファイルの1つの「複数」の各エントリが複製され、そのデータが他のファイルに入力されるように、それらを組み合わせる必要があります。

contig11 3 N GO:100 other columns of data
contig11 3 N GO:289 other columns of data
contig11 3 N GO:113 other columns of data
contig11 1 Y GO:100 other columns of data
contig11 1 Y GO:289 other columns of data
contig11 1 Y GO:113 other columns of data
contig22 1 Y GO:388 other columns of data
contig22 1 Y GO:101 other columns of data
contig22 2 N GO:388 other columns of data
contig22 2 N GO:101 other columns of data

私はスクリプトの経験がほとんどありませんが、たとえば「contig11」がハッシュ/キーを使用してファイルの1つで1回だけ発生する場合にこれを行いました。しかし、私はこれを行うために頭を動かすことさえできません! この問題に取り組む方法について、いくつかの助けやヒントを本当に感謝しています.

編集だから私はこれで池上の提案(答えを見てください)を試しました:しかし、これはGO:100列以降を除いて必要な出力を生成しました($rest in script???) - 私が間違っていることは何ですか?

#!/usr/bin/env/perl

use warnings;

open (GOTERMS, "$ARGV[0]") or die "Error opening the input file with GO terms";
open (SNPS, "$ARGV[1]") or die "Error opening the input file with SNPs";

my %goterm;

while (<GOTERMS>)
{
    my($id, $rest) = /^(\S++)(,*)/s;
    push @{$goterm{$id}}, $rest;
}

while (my $row2 = <SNPS>)
{
    chomp($row2);
    my ($id) = $row2 =~ /^(\S+)/;
    for my $rest (@{ $goterm{$id} })
    {
        print("$row2$rest\n");
    }
}

close GOTERMS;
close SNPS;
4

2 に答える 2