Hi, I have a tab-delimited input file that looks like this:
#chr  loc	rs	   observ 129S1 129S4 129X1 A/J
1     3.013441	rs31192577   A/T   T      T     T    =
1     3.036178	rs32166183   A/C   C      C     C    A
1     3.036265	rs30543887   A/G   G      G	A    A
1     3.039187	rs6365082    G/T   =      =     T    T
1     3.051362	rs30717399   A/G   G      G     G    A
1     3.051854	rs32156135   A/G   G      G     G    A
1     3.062749	rs31606309   A/C   A      =     A    C
1     3.063538	rs30884626   C/G   G      G     G    C
1     3.093816	rs31797356   C/T   T      T     T    C
1     3.093903	rs31986282   A/T   T      T     T    A
1     3.095984	rs30462182   A/C   A      A     A    C
1     3.108194	rs32782895   A/G   A      A     A    G
1     3.11911	rs31819935   A/G   G      G     G    A
1     3.119136	rs31147132   C/T   T      T     T    C
I need to count and print out each occurrence of the rs values. Foreach rs value I need to check if an (A|G|C|T|=)
exist in arrays 4 thru 7. If an '=' sign exist, then I need to skip that array and still keep count of the array number.
So, arrays 4-7 would have values eq to 1 thru 4. The output would look like the following:
snp_id    strain_id    rs_value
1             1        rs31192577
.              .           . 
.              .           .
.              .           .
1             4       rs31192577
2             1        rs32166183
.              .           .
.              .           .
.              .           .
2             4       rs32166183

This iteration will continue for every 'rs' value and each of
the arrays 4-7. The actual file has 48 of the arrays
that need to be checked
The is the code that I have written thus far:

#!/usr/bin/perl
 
use strict;
use warnings;

open( my $in, "20264500_snp_48strains_b37.txt");
open( my $out,">SNP_Strain_join.txt");

my $first_line = <$in>;
chomp $first_line;
my $snp_id_count = 0;

#my $num_of_strains = 48;
my $skip_strain = '=';
while(<$in>){
	chomp;
	my $strain_count = 0;
	my @fields = split /\t/;
	my $rs = $fields2;
	$snp_id_count++;
	$strain_count++;
	print $out "$snp_id_count\t$rs\t$strain_count\n";
}
close($in);
close($out);

In reply to Looping issue... by lomSpace

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.