CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [MB123] Script Advice: Is it doing what I think it is?: Edit Log



Chris Charley
User

Dec 1, 2012, 9:03 AM


Views: 2501
Re: [MB123] Script Advice: Is it doing what I think it is?

You might try this code to get the count. This tests $line for a match for each item in __DATA__ and gets the count.


Code
 #!/usr/bin/perl  
use strict;
use warnings;
use 5.014;

my %cod;
$cod{1} = "Int";
$cod{2} = "non";
$cod{3} = "syn";
$cod{4} = "stop";

$SIG{'__WARN__'} = sub{die $_[0]};
my $file = "Type 9.txt";
open IN, "<", $file or die "could not open $file $! \n";
open OUT, ">", "output.txt" or die "could not open output.txt $! \n";
print OUT "Coordinate No of Strains AA Change\n";
chomp(my @data = <DATA>);
my ($SNP, $count, $change);
while(<IN>){
if (m/^FT\s+SNP\s+(\d+)/) {
$SNP = $1;
}
elsif (m/^FT\s+\/note="(.*)"/) {
my $line = $1;
$count = 0;

for my $data (@data) {
$count += () = $line =~ /$data/g;
}
$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";
}
}

__DATA__
4386_7#8_
4350_7#6_
4414_1#6_
6133_2#2_
4465_5#1_
4465_5#6_
6236_1#3_
4330_8#8_
4386_6#1_
4414_5#9_
4340_5#10_
4340_6#11_
4386_6#8_



(This post was edited by Chris Charley on Dec 2, 2012, 8:41 AM)


Edit Log:
Post edited by Chris Charley (User) on Dec 1, 2012, 9:13 AM
Post edited by Chris Charley (User) on Dec 1, 2012, 3:49 PM
Post edited by Chris Charley (User) on Dec 2, 2012, 8:41 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives