Hi. i am trying to write a program that will parse the output of a blastx file so that the output looks likr this;
Gene: blahblah Query: FDVKHGAHJKHBHXYJTJGHCJHZGJHJJFVJKFG
mb, a BLAST output file looks like this;
Query= 8 (545 letters) Database: /ebi/cgg/one/nrdb-filtered/nrdb.filtered 905,591 sequences; 283,075,510 total letters Searching..................................................done Sco +re E Sequences producing significant alignments: (bi +ts) Value /:swiss|P75505|YC71_MYCPN Hypothetical lipoprotein MPN271 precu... 1 +36 2e-31 >/:swiss|P75505|YC71_MYCPN Hypothetical lipoprotein MPN271 precursor (A65_orf251a).//:pironly|S73889|S73889 probable lipoprotein A65_orf251a - Mycoplasma pneumoniae (ATCC 29342) (SGC3)//:gp|AE000055|1674262 conserved hypothetical protein, see: MPN643 [Mycoplasma pneumoniae] Length = 251 Score = 136 bits (340), Expect = 2e-31 Identities = 72/121 (59%), Positives = 88/121 (72%), Gaps = 1/121 (0% +) Frame = -3 Query: 363 KRSFYQELPLLLWFLLLGTVLSACSKVESTKSVHPVKSFKSDLKSLLKETIKQDIDLSK +T 184 K+ F FLL GT+LSAC+ +++ DL++L+KET +DIDLSK Sbjct: 3 KKKFLSRFSFSSLFLLCGTLLSACTGIQA------------DLRNLIKETTGKDIDLSK +A 50
Here is my attempt below which just doesn't run (p.s i realise that this could be easily achieved using bioperl but i dont want to use that). Error messages especially don't like it when i mention $end_annotation and $start_annotation!! thanks.
#! /usr/local/bin/perl -w use strict; my $start_annotation; my $end_annotation; my %alignments = (); my $filename = 'strept_blastx.output'; parse_blast (\$start_annotation, \$end_annotation, \%alignments, $file +name); print $start_annotation; sub get_file_data { my ($filename) = @_; my @filedata = (); unless(open (GET_FILE_DATA, $filename)) { print STDERR "cant open file \"$filename\"\n\n"; exit; } @filedata = <GET_FILE_DATA>; close GET_FILE_DATA; return @filedata; } foreach my $key (keys %alignments) { print "$key\nxxxxxxxxx\n", $alignments{key}, "\nxxxxxxxxxx\n"; } print $end_annotation; exit; sub parse_blast { my ($start_annotation, $end_annotation, $alignments, $filename) = @_; my $blast_output_file = ''; my $alignment_section = ''; $blast_output_file = join('', get_file_data ($filename)); ($$start_annotation, $alignment_section, $$end_annotation) = ($blas +t_output_file =~/(.*^ALIGNMENTS\n)(.*)(^ Database:.*)/ms); %alignments = parse_blast_alignment ($alignment_section); } sub parse_blast_alignment { my($alignment_section) = @_; my (%alignment_hash) =(); while ($alignment_section =~ /^>.*\n(^(?!>).*\n)+/gm) { my ($value) = $&; my ($key) = (split(/\|/, $value)) [1]; $alignment_hash{$key} = $value; } return %alignment_hash; }

In reply to parsing BLAST output by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.