Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:26:37+00:00 2026-06-13T23:26:37+00:00

I have a large text files in the format shown below – ID SNP

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:26:38+00:00Added an answer on June 13, 2026 at 11:26 pm

    I rewrote your program using more modern coding standards:

    • I used use strict; and use warnings;
    • I used spaces to help clarify the code
    • I used more modern syntax for things like your loops and if/elsif statements

    I found some minor glitches, but it didn’t take me long to fix the issues. Here’s your code:

    use strict;
    use warnings;
    use feature qw(say);
    
    my $file = "input.txt";
    my %cod = ( 1 => "red", 2 => "non", 3 => "green" );
    open my $in, "<", "$file";
    open my $out, ">", "output.txt";
    say $out "Coordinate   No of Strains   AA Change";
    
    my $SNP;
    my $count;
    my $change;
    while ( my $line = <$in> ) {
        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 $out "%-12.12s %-15.15s %s\n",  $SNP, $count, $change;
            }
        }
    }
    

    And here’s the output:

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

    Is this what you’re looking for?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very large text files that has the format below: items=item1|item2|item3|item4&ids=18|117|34|315&locations=5|26|9|12#Characteristic_1#Describe Characteristic_1#http://example.com items=item1|item2|item3|item4&ids=18|117|34|315&locations=5|26|9|12#Characteristic_2#Describe
I have a large text file in the format of. english word: spanish equivalent
I have several large text files (30m+ lines, >1GB) which are being processed in
i have large numbers of text files and i am in problem that i
I have two large (~100 GB) text files that must be iterated through simultaneously.
I do have to deal with very large plain text files (over 10 gigabytes,
I have two large identical-sized files. One is ASCII plain text, and the other
I have a maven project that converts text files of a specific format to
I have a large text file I need to sort in Java. The format
I have to process text files 10-20GB in size of the format: field1 field2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.