in reply to combining multiple matrices with placeholders if row and column values in one matrix do not exist in another

This should get you started:

#! perl -slw use strict; use Inline::Files; use Data::Dump qw[ pp ]; my @templateIds = split ' ', <TEMPLATE>; my %template = map{ my( $id, @vals )= split(); $id => \@vals } <TEMPLA +TE>; #pp \%template; my @missingIds = split ' ', <MISSING>; my %missing = map{ my( $id, @vals )= split(); $id => \@vals } <MISSING +>; #pp \%missing; for my $i ( 0 .. $#templateIds ) { if( $templateIds[ $i ] ne $missingIds[ $i ] ) { splice @missingIds, $i, 0, $templateIds[ $i ]; for my $k ( keys %missing ) { splice @{ $missing{ $k } }, $i, 0, 0; } $missing{ $templateIds[ $i ] } = [ (0) x @{ $template{ $templa +teIds[ $i ] } } ]; } } print "\t", join ' ', @missingIds; print join ' ', $_, @{ $missing{ $_ } } for @missingIds; __TEMPLATE__ rs12272511 rs7107801 rs11027752 rs12421837 rs12272511 1.0 -0.023 -0.511 -0.046 rs7107801 -0.023 1.0 0.040 0.233 rs11027752 0.494 0.514 1.0 0.501 rs12421837 -0.039 -0.040 0.021 1.0 __MISSING__ rs12272511 rs11027752 rs12421837 rs12272511 1.0 .844 .276 rs11027752 .267 1.0 -.980 rs12421837 -.876 .374 1.0

Output:

C:\test>1152731 rs12272511 rs7107801 rs11027752 rs12421837 rs12272511 1.0 0 .844 .276 rs7107801 0 0 0 0 rs11027752 .267 0 1.0 -.980 rs12421837 -.876 0 .374 1.0

Note:I've used Inline::Files to produce a self-contained example; you'd need to open the real files and operate on them for your real work.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.
  • Comment on Re: combining multiple matrices with placeholders if row and column values in one matrix do not exist in another
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: combining multiple matrices with placeholders if row and column values in one matrix do not exist in another
by mulder4786 (Novice) on Jan 14, 2016 at 14:47 UTC
    This works well, thank you!