I have a large text files in the format shown below –
ID SNP
FT SNP 433
FT /note="refAllele: T SNPstrains: 7083_1#5=C 7414_8#8=C 7480_8#49=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
This is the code I used –
$file="input file";
open IN, "$file";
open OUT, ">output file";
print OUT "Coordinate No of Strains AA Change\n";
while(<IN>){
if(m/^FT\s+SNP\s+(\d+)/){
$SNP=$1;
}elsif(m/^FT\s+\/note="(.*)"/){
$line=$1;
$count = ($line =~ tr/=/=/);
$line =~ m/\((AA \w+->\w+)\)\s*$/;
$change = $1 || "";
}elsif(m/^FT\s+\/colour=(\d+)/){
print OUT "$SNP $count $change\n" if $cod{$1} eq "non";
}
}
The aim is to have an output file that is like the one below (for the above part of text file)
Coordinates No of Strains AA Change
703 1 AA Ala->Thr
937 1 AA Val->Leu
1804 3 AA Ser->Thr
However, when I apply the code to the text file I receive an error: Use of uninitialised values ($count or $change) in concatenation (.) or string at line 23. The line in question is
print OUT "$SNP $count $change\n" if $cod{$1} eq "non";
The error refers to lines that contain
FT /colour=2
i.e., lines that show a non-synonymous mutation, such as line 13 in the sample text.
Please be advised that I am a novice in programming and a large part of this code was not written by me. Any help would be appreciated!
Many thanks in advance.
I rewrote your program using more modern coding standards:
use strict;anduse warnings;I found some minor glitches, but it didn’t take me long to fix the issues. Here’s your code:
And here’s the output:
Is this what you’re looking for?