AWallBuilder has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, I'm relatively new and cannot get this program to run properly, I think there is something wrong with the logic of my looping. Basically I have a list of 3500 gene ids and I want to look through another file which has one row for each gene_SNP pair. For most genes there are many SNPs. I want to pull out the SNP position information for all of the genes in the first list. At the moment my script just writes output (ie. finds a match in the key and geneid) for the first key that it looks at.
use strict; use warnings; my %scGeneids; # gene ids for marker genes my $key; open(INlist,"scCOGwSNPs_geneids.txt"); while(<INlist>){ chomp; $scGeneids{$_}=1; } close(INlist); open(IN,"snps.position.txt") or die "can't open infile"; open(OUT,">markerGen_allSNPPos.txt"); foreach $key (keys %scGeneids){ print "searching for $key \n"; while (<IN>){ chomp; my @columns=split("\t",$_); my $gene_id=$columns[0]; my $SNP_pos=$columns[2]; if ($key eq $gene_id){ print OUT join("\t",$key,$SNP_pos),"\n"; } } } close(IN);
head INlist
213810.locus_tag:RUM_03050 213810.locus_tag:RUM_03410 213810.locus_tag:RUM_03700 213810.locus_tag:RUM_06140 213810.locus_tag:RUM_06600 213810.locus_tag:RUM_07030 213810.locus_tag:RUM_09690 213810.locus_tag:RUM_09700 213810.locus_tag:RUM_09770 213810.locus_tag:RUM_12130
head IN
245014.locus_tag:CK3_01920 245014.FP929062 204248 T 0|0|0| +1|0|0|2|0|6|5|0|0|0|0|0|0|3|1|6|0|0|1|0|0|5|1|0|0|0|4|0|0|4|4|3|2|0|0 +|0|0|3|0|0|0|0|2|0|0|0|0|0|5|2|0|0|0|0|0|0|2|2|0|0|5|0|0|1|0|0|4|0|0| +2|2|1|9|0|2|2|1|5|0|1|5|0|0|0|0|1|0|0|2|0|0|0|2|1|0|1|0|0|2|0|0|0|0|0 +|0|0|0|1|2|0|0|0|0|1|0|0|1|0|0|2|7|1|0|1|1|0|0|5|1|3|0|3|2|0|10|2|1|1 +|9|2|2|0|0|2|2|0|0|0|1|0|1|0|3|0|0|1|1|0|0|0|1|3|0|1|3|2|1|0|0|4|1|1| +0|0|1|1|0|0|2|2|0|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1|1|1|0|0|1|2|0|0|3|2|0|0|1|4|1|1| +0|0|1|0|0|0|3|1|0|0|0|1|1|0|0|3|4|3|0|0|0|3|0|0|0|1|2|0|1|1|1|0|0|0|1 +|0|3|0|1|0|0|0|0|0|2|0|0|0|1|1|0|0|0|0|0|0|3|1|5|0|1|1|0|0|0|0|0|0|4| +0|4|1|0|0|0|0|0 . 9|T|S[AAG-AAA]|0|0|0|0|0|0|0|0|0|0|0|0 +|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|2|0|0|0|0|0|1|0|0|0|0|1| +0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0 +|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0| +0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|2|0|0|0 +|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0| +0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0 +|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help with loop
by Anonymous Monk on Jan 18, 2012 at 11:38 UTC | |
|
Re: help with loop
by Eliya (Vicar) on Jan 18, 2012 at 11:46 UTC | |
by AWallBuilder (Beadle) on Jan 18, 2012 at 12:30 UTC | |
by Anonymous Monk on Jan 18, 2012 at 12:32 UTC | |
by Eliya (Vicar) on Jan 18, 2012 at 13:48 UTC | |
|
Re: help with loop
by RichardK (Parson) on Jan 18, 2012 at 11:39 UTC | |
|
Re: help with loop
by ansh batra (Friar) on Jan 18, 2012 at 10:44 UTC |