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.
In reply to Re: combining multiple matrices with placeholders if row and column values in one matrix do not exist in another
by BrowserUk
in thread combining multiple matrices with placeholders if row and column values in one matrix do not exist in another
by mulder4786
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |