I have a tab-delimited text file like this (GOTERMS):
And another like this (SNPS):
I need to combine them so that each 'multiple' entry of one of the files is duplicated and populated with its data in the other, so that I get:
It was suggested I store the rows of the first file in a hash indexed by the row's id:
But I am not getting the GO column onwards in the final file, just duplicated lines of SNPS file - can anyone suggest where I'm going wrong with this script or suggest another solution?
Code:
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
Code:
contig11 3 N contig11 1 Y contig22 1 Y contig22 2 N
Code:
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
Code:
#!/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;
Comment