# Reads in GTR file. # Takes a filehandle opened for reading. Returns two hash references. One contains information specific to # particular dyes: the threshold values and indices (the threshold determine which sites get filtered out) and # the number of character in the filtered and unfiltered ... sub readGTR($) { *GTR_IN = shift; local $/ = getLineEnding *GTR_IN; my (%thresholds, %data, %comments, @labels); local $_; while () { chomp; $comments{$.} = $1, next if /^#(.*)/; next if /^$/; last if /^\%DATA%$/; my $dye = $_; while () { chomp; $comments{$.} = $1, next if /^#(.*)/; last if /^$/; my ($key, $value) = /^\s*(\w.*?):\t(.*)$/ or die "Error reading line $.:\n$_\n"; # Have to append a dummy character to $value to force split() to return trailing empty fields. @{$thresholds{$dye}{$key}} = map {$_ eq 'undef' ? undef : $_} split /\t/, $value.chr(0); substr( ${$thresholds{$dye}{$key}}[-1], -1 ) = ""; # Remove the dummy character. } } while () { chomp; next if /^$/ || /^#/; my $taxon_label = $_; push @labels, $taxon_label; # To record the order of the taxa. while ( =~ /\s*(.*?)\t(.*)$/) { $data{$taxon_label}{$1} = $2; } my $dye; while () { chomp; next if /^#/; last if /^$/; ($dye) = /^\s*Dye\s+(.*)/; while () { chomp; next if /^#/; last if /^$/; my @values = split /\t/; my $key = shift @values; $data{$taxon_label}{'Samples'}{$dye}{$key} = \@values; } } } return \%thresholds, \%data, \%comments, \@labels; }