#!/usr/bin/perl my @chpar = ; chomp @chpar; foreach (@chpar) { my ($ch,$par) = split /\,/,$_; $HASH{$ch} = $par; } foreach $key (keys %HASH) { print "$key,$HASH{$key}\n"} # Make the script executable: chmod 755 loadchpar.pl # # Usage: cat infile.csv | ./loadchpar.pl > outfile # # This simple script takes a child/parent text csv file via STDIN and creates # an array, one element for each line. It then loops through the array # splitting the data, by the comma, into separate child/parent fields. The # child becomes the "key" to the hash pair and the parent the value: # # $HASH{key}=value; # $HASH{$ch}=$par; # # The value (parent) is then is accessed by stating the key: # # $HASH{'YP4491'} would access YP5253. # # The last line in this script prints the contents of the entire hash. It # matches the input. The point, of course, is to first transform the output. # # From this file, subclades and trees can be generated. You can work up the # tree, for example, by taking the parent as the child (key) to get *his* # father, etc. # # Michael Cooley # Lead for the Open Y project