Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Parsing problem

by kcott (Abbot)
on Nov 08, 2012 at 00:40 UTC ( #1002780=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Parsing problem
in thread Parsing problem

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


Comment on Re^3: Parsing problem
Download Code
Re^4: Parsing problem
by MB123 (Initiate) on Nov 08, 2012 at 10:48 UTC

    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 http://www.perl.org/, the Perl Home Pa +ge.

      -- Ken

        I suspect I am missing a lot of fundamental knowledge! Here is my output -
        This is perl 5, version 16, subversion 1 (v5.16.1) built for MSWin32-x +64-multi-thread Copyright 1987-2012, 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 kit. 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 http://www.perl.org/, the Per +l Home Page.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1002780]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2014-09-18 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls