Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^2: Parsing problem

by MB123 (Initiate)
on Nov 07, 2012 at 23:49 UTC ( #1002775=note: print w/replies, xml ) Need Help??

in reply to Re: Parsing problem
in thread Parsing problem

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.

Replies are listed 'Best First'.
Re^3: Parsing problem
by kcott (Chancellor) on Nov 08, 2012 at 00:40 UTC

    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 = ""; 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!

        I now have some inkling of what the problem might be. I suspect you're missing some very fundamental knowledge. Don't panic about this: none of us was born with this information and you just haven't learned it yet. I can probably take you through this step-by-step but first I'll need some information. Please type

        perl -v

        at your command prompt and then post the full output (within <code>...</code> tags). Here's an example from my system (my command prompt is "$ " - you don't type this):

        $ perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for darwin-th +read-multi-2level Copyright 1987-2011, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at, the Perl Home Pa +ge.

        -- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002775]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2018-05-25 02:03 GMT
Find Nodes?
    Voting Booth?