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|0|0|1|1|0|0|2|4|2|0|0|0|2|0|0|0|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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

In reply to help with loop by AWallBuilder

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.