maternal_id => $maternal_id,
paternal_id => $paternal_id,
};
- # do it this way to avoid eating memory
- $samples{$individual_id} = \@snps;
- if (@snps != 2*@map) {
- die "The map file and the number of snps don't appear to match";
+ for my $snp_info (@map) {
+ $samples{$individual_id}{$snp_info->{rsid}} = [shift @snps, shift @snps];
+ }
+ if (@snps) {
+ die "The map file and the number of snps don't appear to match".join(' ',@snps)."were left over";
}
}
}
my %valid_snps;
+@valid_snps{map {s/^rs//; "rs$_";} @{$options{snps}}} = (1) x @{$options{snps}};
-if (defined $options{snps} and @{$options{snps}}) {
- for my $snp_i (0..$#snp_order) {
- for my $valid_snp (@{$options{snps}}) {
- if ($snp_order[$snp_i]{rsid} =~ /(rs)?\Q$valid_snp\E/) {
- $valid_snps{$snp_order[$snp_i]{rsid}} = $snp_i;
- last;
- }
- }
- }
-}
-my @snp_ordering;
+my @snp_ordering = map {$_->{rsid}} @snp_order;
+
if (keys %valid_snps) {
- @snp_ordering = sort {$valid_snps{$a} <=>
- $valid_snps{$b}
- } keys %valid_snps;
-}
-else {
- @snp_ordering = map {$_->{rsid}} @snp_order;
+ @snp_ordering = grep {exists $valid_snps{$_}} @snp_ordering;
}
join("\t",
@{$extra_info{$individual_id}}{qw(family_id individual_id),
qw(paternal_id maternal_id sex phenotype)},
- keys %valid_snps ? @{$samples{$individual_id}}[@valid_snps{@snp_ordering}] : @{$samples{$individual_id}}
+ map {@{$_}} @{$samples{$individual_id}}{@snp_ordering}
)."\n";
}
}