#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |