Well, let me just rewrite your program a bit ... but be cautious, this is untested code so I couldn't check your regexes, ... (and I probably introduced some small bugs of my own :)
#! /usr/local/bin/perl -w use strict; my $filename = 'strept_blastx.output'; my ($start_annotation, $end_annotation, $alignments) = parse_blast ($f +ilename); print $start_annotation; print map "$_\nxxxxxxxxx\n$alignments->{$_}\nxxxxxxxxxx\n", keys %$ali +gnments; print $end_annotation; sub parse_blast { my ($filename) = @_; my $blast_output_file; my ($start_anno, $alignment_sec, $end_anno); open( my $data_file, '<', $filename ) or die "Couldn't open file $fi +lename: $!"; $blast_output_file = do {local $/; <$data_file> }; close $data_file; ($start_anno, $alignment_sec, $end_anno) = ($blast_output_file =~/(.*^ALIGNMENTS\n)(.*)(^ Database:.*)/ms); my $align_hashref = parse_blast_alignment($alignment_sec); return ($start_anno, $end_anno, $align_hashref); } sub parse_blast_alignment { my ($alignment_section) = @_; my $alignment_hashref; while ($alignment_section =~ /^>.*\n(^(?!>).*\n)+/gm) { my $value = $&; my ($key) = (split(/\|/, $value)) [1]; $alignment_hashref->{$key} = $value; } return $alignment_hashref; }

So, this should run and then you can tell us if you still have some problems with your regexes and the actual extraction. Some more explanations for us non-biologists about the format would then be helpful as well.

-- Hofmator


In reply to Re: parsing BLAST output by Hofmator
in thread 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.