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
In reply to Trouble skipping lines using Perl by LeBran
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |