[Bio] / FigMetagenomeTools / join2lists.pl Repository:
ViewVC logotype

View of /FigMetagenomeTools/join2lists.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (download) (as text) (annotate)
Sat Aug 29 22:01:51 2009 UTC (10 years, 3 months ago) by redwards
Branch: MAIN
CVS Tags: mgrast_dev_08112011, mgrast_dev_08022011, mgrast_dev_05262011, mgrast_dev_04082011, mgrast_version_3_2, mgrast_dev_12152011, mgrast_dev_06072011, mgrast_dev_10262011, mgrast_dev_02212011, mgrast_release_3_0, mgrast_dev_03252011, mgrast_release_3_0_4, mgrast_release_3_0_2, mgrast_release_3_0_3, mgrast_release_3_0_1, mgrast_dev_03312011, mgrast_release_3_1_2, mgrast_release_3_1_1, mgrast_release_3_1_0, mgrast_dev_04132011, mgrast_dev_04012011, myrast_33, mgrast_dev_04052011, mgrast_dev_02222011, HEAD
Changes since 1.1: +26 -16 lines
an arbitrary number of lists

#!/usr/bin/perl -w

# Join lists from files. Anything with the same keys will be merged. This assumes there are two columns separated by tabs, and the first column is the key and the second the value.

use strict;



unless ($ARGV[0]) {
 print STDERR <<EOF;

$0 <list of files>

Join two lists from two files. Anything with the same keys will be merged. 
This assumes there are two columns separated by tabs, and the first column is the key and 
the second the value.
EOF

die;
}

my $data;
my %keys;
foreach my $file (@ARGV) {
	open(IN, $file) || die "can't open $file";
	while (<IN>) {
		chomp;
		my @a=split /\t/;
		$data->{$file}->{$a[0]}=$a[1];
		$keys{$a[0]}=1;
	}
	close IN;
}


print join("\t", "Key", @ARGV). "\n";
foreach my $k (sort keys %keys) {
	print $k;
	foreach my $f (@ARGV) {
		$data->{$f}->{$k} ? print "\t", $data->{$f}->{$k} : print "\t0";
	}
	print "\n";
}




MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3