andyBio has asked for the wisdom of the Perl Monks concerning the following question:
Hello, wise ones! I am trying to read in a file with content like this:
It is a tab demilimited file. I want to manipulate the file to have it look like this:TATTATGAGAATAGTGTGCATTTT 3 ATAGAGCAAAAGGGCAAATGCTGA 6 TACGAGTAGGATATCGATCTGGTGG 2 ATCCCCGGCATCTCCGCCA 1 TGAGAATAGTGTGCATTT 52 CGCATTACATTTGGAGCC 1 ACTCCAGGCAGCGTAGAGTT 1 ATCAACGTTGCTGCATCGG 1
(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:>dme0_count=3 TATTATGAGAATAGTGTGCATTTT >dme1_count=6 ATAGAGCAAAAGGGCAAATGCTGA >dme2_count=52 TGAGAATAGTGTGCATTT
#!/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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Manipulating tab delimited file
by davido (Cardinal) on Apr 29, 2016 at 02:29 UTC | |
by andyBio (Novice) on Apr 29, 2016 at 04:41 UTC | |
|
Re: Manipulating tab delimited file
by kevbot (Vicar) on Apr 29, 2016 at 02:44 UTC | |
by andyBio (Novice) on Apr 29, 2016 at 04:57 UTC | |
by Laurent_R (Canon) on Apr 29, 2016 at 06:25 UTC | |
by Athanasius (Archbishop) on Apr 30, 2016 at 06:11 UTC | |
by andyBio (Novice) on Apr 29, 2016 at 04:39 UTC |