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:
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, 8:53 AM

Post #1 of 2 (543 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!


wickedxter
User

Jan 10, 2012, 6:56 PM

Post #2 of 2 (535 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

open the file to write to

Code
#>> is append mode 
open OUTFILE, '>>', '/dir/to/output_file.txt';
open(INFILE, "blast_output.txt") ;


and change the print(s) that print to the STDIN(command prompt) to


Code
 print OUTFILE "";


 
 


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

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