I think the safer approach to accomplishing this is to use something like this:
#!/usr/bin/env perl use strict; use warnings; use Bio::SeqIO; use v5.10; #or later... or change 'say' to 'print' X_x my $fasta_in = "input.fa"; open my $fasta_out, ">", "output.fa"; my $seqio_in = Bio::SeqIO->new( -file => $fasta_in, -format => 'Fasta', ); my ( $seq_obj, %seq_hash ); while ( my $seq_obj = $seqio_in->next_seq() ) { my $seq_id = $seq_obj->display_id(); #this is the sequence ID my $seq = $seq_obj->seq(); #this is the actual sequen +ce $seq_hash{$seq_id} = $seq; #and hashed! #to print them to your screen in a "consolidated" FASTA format: say ">$seq_id"; say $seq_hash{$seq_id}; #to save to a file in a "consolidated" FASTA format: say $fasta_out ">$seq_id"; say $fasta_out $seq_hash{$seq_id}; } exit;

You can trim some of the stuff inside the while loop depending on what you actually want to do. For example, if you don't need to use the hash later, there is no point making it, etc.

I've tested this and it works. A sample input and corresponding output can be found here: https://gist.github.com/2928252.


In reply to Re: concatenating multiple lines without using . operator by frozenwithjoy
in thread concatenating multiple lines without using . operator by anonym

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.