X-Git-Url: https://git.donarmstrong.com/?p=bin.git;a=blobdiff_plain;f=genotypeizer;h=06f6dd7921ab58254ee148ad3d7d879c6611f551;hp=a4f2e4193079bb4a3ba40cea31a81c78899523db;hb=1886c7247cb16ed68a78cd5550b152689a465999;hpb=a000c62118b1e7e7f08957eb196651f8e5c08068 diff --git a/genotypeizer b/genotypeizer index a4f2e41..06f6dd7 100755 --- a/genotypeizer +++ b/genotypeizer @@ -174,36 +174,24 @@ while (($map_file,$ped_file) = splice @map_ped,0,2) { 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; } @@ -223,7 +211,7 @@ if ($options{output_format} eq 'pedmap') { 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"; } }