#!/usr/bin/perl # Converts a FASTA alignment of *sequences* to a concise file of the # form alignX;seq name:seq where X is an incremental integer and seq is # a comma seperated list of the sequence use warnings; if ( $ARGV[0] ) { open( IN, "<$ARGV[0]" ) or die($!); } else { *IN = *STDIN; } my ( $seq, @seqs, @title ); while () { if (s/^>//) { if ($seq) { $seq =~ s/\n|\s//g; $seq =~ s/(.)/$1,/g; push @seqs, $seq; $seq = ""; } chomp; push @title, $_; } else { chomp; $seq .= $_; } } $seq =~ s/\n|\s//g; $seq =~ s/(.)/$1,/g; push @seqs, $seq; if ( @title != @seqs ) { die("non matching number of titles and sequences!\n"); } foreach ( 0 .. $#title ) { print "align" . ( $_ + 1 ) . ";$title[$_]:$seqs[$_]\n"; }