#!/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.
|