From d5b4cbe96883e41b093080a1d9d1235341cd9df4 Mon Sep 17 00:00:00 2001 From: jprocter Date: Wed, 14 Sep 2011 12:07:28 +0100 Subject: [PATCH] JAL-931 (related) - utility to split an alignment database in stockholm format into individual alignment files --- utils/splitstockholm.pl | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 utils/splitstockholm.pl diff --git a/utils/splitstockholm.pl b/utils/splitstockholm.pl new file mode 100644 index 0000000..5a31679 --- /dev/null +++ b/utils/splitstockholm.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl +# Splits a concatenated set of Stockholm Files into several individual files. + +use strict; +use FileHandle; +my $ac; +my $lns=""; +my $fh; +while (<>) { + if ($_=~m!^//!) { + $fh->print("//\n"); + $fh->close(); + $ac = undef; + $lns = ""; + } else { + if ($_=~/GF\s+AC\s+([0-9.RPF]+)/) { + $ac=$1; + ($fh=new FileHandle)->open(">$ac.stk") or die("Couldn't open file '$ac.stk'"); + $lns=~/^. STOCKHOLM 1.0/ or $fh->print("# STOCKHOLM 1.0\n"); + }; + if (defined($fh)) { + if (defined $lns) { + $fh->print($lns); $lns=undef; } + + $fh->print($_); + } else { + $lns .= $_; + } + } +} -- 1.7.10.2