LeBran has asked for the wisdom of the Perl Monks concerning the following question:
Hello all, I'm struggling to get Perl to work in skipping lines containing certain features which means I don't need to use them, basically I'm just unsure of the syntax, though it appears to work in some places and not in others
Looking at this following table;
chrM 2928 A G 17 0 0% A 46 105 69.54% + R Somatic 1 1.23052720566294E-008 17 29 50 55 + 4 13 0 0 chr1 108310 T C 9 0 0% T 3 5 62.5% Y + Somatic 1 0.0090497738 2 1 2 3 7 2 0 + 0 chr1 726958 T A 11 0 0% T 9 4 30.77% + W Somatic 1 0.0672877847 6 3 1 3 5 6 0 + 0 chr1 1412720 C A 33 0 0% C 22 6 21.43% + M Somatic 1 0.0067850063 10 12 3 3 14 1 +9 0 0 chr1 1822396 C G 6 0 0% C 4 4 50% S + Somatic 1 0.0699300699 3 1 2 2 4 2 0 +0 chr1 1822457 C T 10 0 0% C 4 4 50% Y + Somatic 1 0.022875817 3 1 2 2 6 4 0 + 0
I'm trying to skip the lines which are chrM rather than chr1, the following code is what I came up with (I'm also extracting different columns)
while (my $line = <FILE>) { next if ($. == 1); chomp $line; my @sepline = split ("\t", $line); my $chromosome = $sepline[0]; my $chrpos = $sepline[1]; my $nmreads = $sepline[8]; my $mutants = $sepline[9]; my $totalreads = $nmreads + $mutants; next if ($chromosome = /^chrM/); print ("$nmreads $mutants $totalreads\n"); }
So the script works fine if I # out the lower next if function towards the bottom of the script, I've also tried "next if ($chromosome = "chrM");" and "if ($chromosome = "chrM") { next;} but neither will work. Is there something incorrect about my syntax or am I simply going about it completely the wrong way? Appreciate any help, cheers
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble skipping lines using Perl
by haukex (Archbishop) on Nov 21, 2017 at 16:01 UTC | |
by LeBran (Initiate) on Nov 21, 2017 at 16:11 UTC | |
by haukex (Archbishop) on Nov 21, 2017 at 16:19 UTC | |
by LeBran (Initiate) on Nov 21, 2017 at 16:55 UTC | |
by roboticus (Chancellor) on Nov 21, 2017 at 16:30 UTC | |
by LeBran (Initiate) on Nov 21, 2017 at 17:03 UTC | |
by AnomalousMonk (Archbishop) on Nov 21, 2017 at 17:23 UTC | |
by AnomalousMonk (Archbishop) on Nov 21, 2017 at 17:49 UTC | |
by LeBran (Initiate) on Nov 22, 2017 at 11:03 UTC | |
|
Re: Trouble skipping lines using Perl
by Eily (Monsignor) on Nov 21, 2017 at 16:16 UTC | |
by LeBran (Initiate) on Nov 21, 2017 at 17:05 UTC | |
|
Re: Trouble skipping lines using Perl
by Laurent_R (Canon) on Nov 21, 2017 at 20:01 UTC | |
by LeBran (Initiate) on Nov 22, 2017 at 11:06 UTC |