in reply to Converting fasta (with multiple sequences) into tabular using perl
This appears to do what you require:
#!/usr/bin/perl # fasta_to_tbl.pl use strict; use warnings; die "Please specify suitable file\n" if @ARGV != 1; my ( $fasta ) = @ARGV; my $outfile = "$fasta.tbl"; open my $in, '<', $fasta or die "error reading $fasta. $!"; open my $out, '>', $outfile or die "error creating $outfile. $!"; while ( <$in> ) { if ( /^>/ ) { # Identifier! # "\t" TAB character for "tabular format" s/[:\s|,;].*/\t/s; print $out $_; next; } s/\s//g; if ( !/\w/ || eof $in ) { # empty line or end of file print $out "$_\n\n"; } else { # Data print $out $_; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Converting fasta (with multiple sequences) into tabular using perl
by rarenas (Acolyte) on Dec 14, 2017 at 10:45 UTC |