Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- # fasta_flattener.pl
- # Mike Covington
- # created: 2012-06-14
- #
- # Description: flatten a FASTA file by removing white space
- #
- 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 sequence
- $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;
Add Comment
Please, Sign In to add comment