#!/usr/bin/env perl use strict; use warnings; use autodie; my $main_df_file = 'pm_11131885_main_df'; my $comp_df_file = 'pm_11131885_comp_df'; my %val_for; { open my $comp_df_fh, '<', $comp_df_file; while (<$comp_df_fh>) { next if $. == 1; chomp; my (undef, $id, undef, $val) = split /\s+/; my $key = (split /\./, $id)[0]; $val_for{$key} = $val unless exists $val_for{$key}; } } { my @out_headers = qw{ID1 ID2 dN dS Omega Value Label_ID1 Label_ID2 Group}; my $out_fmt = "%-8s\t%-8s\t%-6s\t%-6s\t%-6s\t%-7s\t%-13s\t%-13s\t%-5s\n"; my @pre_val_indices = 0 .. 4; my @post_val_indices = 5 .. 7; my $no_match_val = ' -'; my %seen; printf $out_fmt, @out_headers; open my $main_df_fh, '<', $main_df_file; while (<$main_df_fh>) { next if $. == 1; chomp; next unless length; my @elements = split /\s+/; my $key = $elements[0]; next if $seen{$key}++; my $val = exists($val_for{$key}) ? $val_for{$key} : $no_match_val; printf $out_fmt, @elements[@pre_val_indices], $val, @elements[@post_val_indices]; } }