Guest User

Untitled

a guest
Oct 20th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. # fasta_flattener.pl
  3. # Mike Covington
  4. # created: 2012-06-14
  5. #
  6. # Description: flatten a FASTA file by removing white space
  7. #
  8. use strict;
  9. use warnings;
  10. use Bio::SeqIO;
  11. use v5.10; #or later... or change 'say' to 'print' X_x
  12.  
  13. my $fasta_in = "input.fa";
  14. open my $fasta_out, ">", "output.fa";
  15.  
  16. my $seqio_in = Bio::SeqIO->new(
  17. -file => $fasta_in,
  18. -format => 'Fasta',
  19. );
  20.  
  21. my ( $seq_obj, %seq_hash );
  22.  
  23. while ( my $seq_obj = $seqio_in->next_seq() ) {
  24. my $seq_id = $seq_obj->display_id(); #this is the sequence ID
  25. my $seq = $seq_obj->seq(); #this is the actual sequence
  26. $seq_hash{$seq_id} = $seq; #and hashed!
  27.  
  28. #to print them to your screen in a "consolidated" FASTA format:
  29. say ">$seq_id";
  30. say $seq_hash{$seq_id};
  31.  
  32. #to save to a file in a "consolidated" FASTA format:
  33. say $fasta_out ">$seq_id";
  34. say $fasta_out $seq_hash{$seq_id};
  35. }
  36. exit;
Add Comment
Please, Sign In to add comment