JPRED-2 Initial commit of software for the Jpred website (some files excluded due...
[jpred.git] / websoft / bin / fasta2concise
1 #!/usr/bin/perl
2
3 # Converts a FASTA alignment of *sequences* to a concise file of the
4 # form alignX;seq name:seq where X is an incremental integer and seq is
5 # a comma seperated list of the sequence
6
7 use warnings;
8
9 if ( $ARGV[0] ) { open( IN, "<$ARGV[0]" ) or die($!); }
10 else            { *IN = *STDIN; }
11
12 my ( $seq, @seqs, @title );
13 while (<IN>) {
14   if (s/^>//) {
15     if ($seq) {
16       $seq =~ s/\n|\s//g;
17       $seq =~ s/(.)/$1,/g;
18       push @seqs, $seq;
19       $seq = "";
20     }
21     chomp;
22     push @title, $_;
23   } else {
24     chomp;
25     $seq .= $_;
26   }
27 }
28 $seq =~ s/\n|\s//g;
29 $seq =~ s/(.)/$1,/g;
30 push @seqs, $seq;
31
32 if ( @title != @seqs ) { die("non matching number of titles and sequences!\n"); }
33
34 foreach ( 0 .. $#title ) {
35   print "align" . ( $_ + 1 ) . ";$title[$_]:$seqs[$_]\n";
36 }