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: Intermediate:
MAKE A BLAST PARSER TO PRINT ONLY E-VALUE & SCORE FROM A BLAST_OUTPUT.TXT FILE IN A NEW STATS.TXT THROUGHT SIMPLE PERL!

 



stelbac
Novice

Jan 10, 2012, 9:00 AM

Post #1 of 2 (875 views)
MAKE A BLAST PARSER TO PRINT ONLY E-VALUE & SCORE FROM A BLAST_OUTPUT.TXT FILE IN A NEW STATS.TXT THROUGHT SIMPLE PERL! Can't Post

MY WORK TILL NOW IS THE FOLLOWING:
PLEASE HELP ME I AM A STUDENT OF BIOLOGY IN GREECE NOT EXPERT IN PERL...
*ESPECIALLY I WANT SOMEONE TO TELL ME HOW TO PRINT MY RESULTS IN A STATS.TXT FILE AND NOT IN COMMAND PROMPT..

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

open(INFILE, "blast_output.txt")
my($subject_ident, $comment_line, $subject_length);
my %hits;
while (<INFILE>)
{
if (/^>/)
$subject_length = 0;
$comment_line = $_;
while (1) {
my $next_line = <INFILE>;
if ($next_line =~ /Length = (\d+)/ ) {
$subject_length = $1;
last;
}
else { # continuation of comment line
chomp $next_line;
$next_line =~ s/^\s+/ /; # remove leading
$next_line =~ s/\s+$/ /; # and trailing multiple spaces
$comment_line .= $next_line;
}
}
$comment_line =~ />(\S+)\s/;
$subject_ident = $1;
$hits{$subject_ident}{subject_length} = $subject_length;
$hits{$subject_ident}{comment_line} = $comment_line;
}
}
my ($Score,$Expect)
while (<INFILE>)
{
if (/Score=/){
my $score_line =$_;
$score_line =~ /Score.*Expect = ([-.e\d]+)/;
$e_value = $1;
}
}
my ($Query_start, $Query_end, $subjct_start, $subjct_end);
while (<INFILE>) {
if ($subjct_ident && exists $hits{$subject_ident}{hit_data} && (/^>/ || /Score =/ || /^Lambda/ ) ) {
push @{ $hits{$subject_ident}[-1] }, $Query_start, $Query_end, $subjct_start, $subjct_end;
last if (/^Lambda/);
$Query_start = $Query_end = $subjct_start = $subjct_end = 0;
}
}
for each my $subject_ident (sort keys %hits) {
print "$subject_ident:\n";
print " $hits{$subject_ident}{comment_line}\n";
print " Length = $hits{$subject_ident}{subject_length}\n";

foreach my $hit ( @{$hits{$subject_ident}{hit_data}} ) {
print "@$hit\n";
}
print "\n";
}



THANK YOUUU!


saurabhsharma
Novice

Jan 12, 2012, 3:05 AM

Post #2 of 2 (733 views)
Re: [stelbac] MAKE A BLAST PARSER TO PRINT ONLY E-VALUE & SCORE FROM A BLAST_OUTPUT.TXT FILE IN A NEW STATS.TXT THROUGHT SIMPLE PERL! [In reply to] Can't Post

Hi stelbac,

I haven't gone through your code but if you want to redirect your standard output to a file (stats.txt in your case) , you can try using :

1. run your perl file and redirect the output to a file as

as perl "your script name" > stats.txt

2. you can open a file in you script named (stats.txt) in write mode and write to it using print

as open LOGFILE,">", "/path where you want to store your file/stats.txt" || die "cannot create log file--->>>>> \n";

print LOGFILE "$subject_iden:\n";

print LOGFILE "$hits{$subject_ident}{comment_libe}\n";

And at the last line of you script close the file as close(LOGFILE);

3. Use IO::Handle module

Just add these three lines after "use warnings;" in you file

use IO::Handle;
open OUTPUT, '>', "stats.txt" or die $!;
STDOUT->fdopen( \*OUTPUT, 'w' ) or die $!;


I personally like the third method Wink

If there is some issue with your code send me the blast_output.txt

Cheers,

Saurabh Smile

 
 


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

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