JPRED-2 Initial commit of software for the Jpred website (some files excluded due...
[jpred.git] / websoft / bin / fasta2concise
diff --git a/websoft/bin/fasta2concise b/websoft/bin/fasta2concise
new file mode 100755 (executable)
index 0000000..282dff6
--- /dev/null
@@ -0,0 +1,36 @@
+#!/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 (<IN>) {
+  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";
+}