if you find the line open my $fh, '<', \$small_matrix; strange: yes, you can open strings as files in Perl.use strict; use warnings; my @template = qw( rs12272511 rs7107801 rs11027752 rs12421837 ); my $small_matrix = <<'END'; rs12272511 rs11027752 rs12421837 rs12272511 1.0 .844 .276 rs11027752 .267 1.0 -.980 rs12421837 -.876 .374 1.0 END open my $fh, '<', \$small_matrix; my %ids = map { $_ => 1 } split ' ', <$fh>; my $fmt_id_present = join ' ', map $ids{$_} ? '%s' : '0', @template; my $fmt_id_missing = join ' ', ('0') x @template; $_ = "%s $_\n" for $fmt_id_present, $fmt_id_missing; print "\t@template\n"; for (@template) { if ( $ids{$_} ) { printf $fmt_id_present, split ' ', <$fh>; } else { printf $fmt_id_missing, $_; } }
In reply to Re: combining multiple matrices with placeholders if row and column values in one matrix do not exist in another
by Anonymous Monk
in thread combining multiple matrices with placeholders if row and column values in one matrix do not exist in another
by mulder4786
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |