http://www.perlmonks.org?node_id=1002766


in reply to Parsing problem

G'day MB123,

Welcome to the monastery.

I am unable to reproduce the stated problem. Furthermore, after removing the debug print statements (e.g. say qq(DEBUG: Line = "$line");), the output I get is:

Coordinate No of Strains AA Change 703 1 AA Ala->Thr 937 1 AA Val->Leu 1804 3 AA Ser->Thr

This appears to be exactly what you were hoping for!

Please check that the code and data you've posted is the same as that which generates the warnings you described.

-- Ken

Replies are listed 'Best First'.
Re^2: Parsing problem
by MB123 (Initiate) on Nov 07, 2012 at 23:49 UTC
    Hi Ken,

    Thank you for your reply. I have just double checked the whole file and the sample I put up, with and without the debug statements and I am still getting the same result. My output file just prints the coordinates and leaves the 'number of strains' and 'AA Change' columns blank.

      Here's exactly what I used to test your code and data:

      #!/usr/bin/env perl use strict; use warnings; use feature qw(say); #my $file = "BSAC.pl"; my %cod = ( 1 => "red", 2 => "non", 3 => "green" ); #open my $in, "<", "$file"; #open my $out, ">", "output.txt"; say "Coordinate No of Strains AA Change"; my $SNP; my $count; my $change; while ( my $line = <DATA> ) { chomp $line; #say qq(DEBUG: Line = "$line"); if ( $line =~ /^FT\s+SNP\s+(\d+)/ ){ $SNP = $1; #say qq(\$SNP = $1;); } elsif ( $line =~ /^FT\s+\/note="(.*)"/) { my $note = $1; #say qq(my \$note = $1); $count = ($note =~ tr/=/=/); $note =~ /\((AA \w+->\w+)\)\s*$/; $change = $1 || ""; } elsif ( $line =~ /^FT\s+\/colour=(\d+)/ ) { #say qq(Code = $1); if ( $cod{$1} eq "non" ) { printf "%-12.12s %-15.15s %s\n", $SNP, $count, $change; } } } __DATA__ ID SNP FT SNP 433 FT /note="refAllele: T SNPstrains: 7083_1#5=C 7414_8#8=C 7480_8#4 +9=C " FT /colour=1 FT SNP 442 FT /note="refAllele: T SNPstrains: 7065_8#2=C 7065_8#94=C 7083_1# +2=C 7083_1#3=C 7083_1#41=C 7083_1#42=C 7083_1#43=C " FT /colour=1 FT SNP 460 FT /note="refAllele: T SNPstrains: 7564_8#14=C " FT /colour=1 FT SNP 703 FT /note="refAllele: G SNPstrains: 7521_5#39=A (non-synonymous) ( +AA Ala->Thr) " FT /colour=2 FT SNP 937 FT /note="refAllele: G SNPstrains: 7414_8#30=T (non-synonymous) ( +AA Val->Leu) " FT /colour=2 FT SNP 1269 FT /note="refAllele: G SNPstrains: 7480_7#22=A (synonymous) 7480_ +7#62=A (synonymous) " FT /colour=3 FT SNP 1804 FT /note="refAllele: T SNPstrains: 7414_7#66=A (non-synonymous) ( +AA Ser->Thr) 7414_8#44=A (non-synonymous) (AA Ser->Thr) 7521_6#54=A ( +non-synonymous) (AA Ser->Thr) " FT /colour=2

      Try running this. Assuming it works, try changing the data to something you know will generate the warnings - keeping the data to an absolute minimum.

      If you are also unable to reproduce the warnings, then the problem may lie in your input file. There might be embedded characters that aren't showing up when the text is copied and pasted. Anyway, I'm jumping the gun a bit here - see how you go with above code first.

      -- Ken

        Using your exact code and the data posted here, I get "Coordinates No of Strains AA Change" printed in my command line, and no output file created.

        I don't understand how I am getting different results!