Hello, wise ones! I am trying to read in a file with content like this:

TATTATGAGAATAGTGTGCATTTT 3 ATAGAGCAAAAGGGCAAATGCTGA 6 TACGAGTAGGATATCGATCTGGTGG 2 ATCCCCGGCATCTCCGCCA 1 TGAGAATAGTGTGCATTT 52 CGCATTACATTTGGAGCC 1 ACTCCAGGCAGCGTAGAGTT 1 ATCAACGTTGCTGCATCGG 1
It is a tab demilimited file. I want to manipulate the file to have it look like this:
>dme0_count=3 TATTATGAGAATAGTGTGCATTTT >dme1_count=6 ATAGAGCAAAAGGGCAAATGCTGA >dme2_count=52 TGAGAATAGTGTGCATTT
(i). Sequences(column 0) with length less than 15 or greater than 30 are ommitted (ii). Sequences with counts (Column 1) < 2 are ommitted (iii). the print statement takes uses an argument and the count for the header line. Here is my code:

#!/usr/bin/perl -w use strict; use warnings; my $species=$ARGV[0]; my $input=$ARGV[1]; my @fields; my $n = 0; open my $tabdata, '<', "$input" or die ("Can't open $input\n"); while (my $line = <$tabdata>) { foreach my $line ($tabdata){ my @fields = split("\t",$line); if(($fields[1] > 2) && (length($fields[0]) > 14 && length($fields[ +0]) < 31)) {print ">$species" . $n++ . "_count=$fields[1]\n$fields[0]\n"} +; } } close ($tabdata);
Here is the error: a> line 1. Use of uninitialized value $fields[1] in numeric gt (>) at tab.pl line + 19, <$tabdata> line 2. Use of uninitialized value $fields[1] in numeric gt (>) at tab.pl line + 19, <$tabdata> line 3. . . . Use of uninitialized value $fields[1] in numeric gt (>) at tab.pl line + 19, <$tabdata> line 21.

I'd appreciate some assistance on how to get this to work! Thank you.


In reply to Manipulating tab delimited file by andyBio

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.