allpy
changeset 433:6d9b3c679930
Added util realign_block (almost exact copy of flush_left)
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Tue, 15 Feb 2011 20:29:48 +0300 |
parents | 43bca78ece0c |
children | 7d73604c8df6 |
files | utils/realign_block.py |
diffstat | 1 files changed, 49 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/utils/realign_block.py Tue Feb 15 20:29:48 2011 +0300 1.3 @@ -0,0 +1,49 @@ 1.4 +#!/usr/bin/python 1.5 +"""Realign given part of alignment. 1.6 + 1.7 +All position indexes are counting from 1. 1.8 +""" 1.9 +import optparse 1.10 +import sys 1.11 +import os 1.12 +from allpy import protein 1.13 +from allpy.processors import Muscle 1.14 + 1.15 +def main(): 1.16 + alignment = protein.Alignment().append_file(open(options.in_file)) 1.17 + if not options.begin: 1.18 + options.begin = 1 1.19 + if not options.end: 1.20 + options.end = len(alignment.columns) 1.21 + columns = alignment.columns[options.begin-1:options.end] 1.22 + block = protein.Block.from_alignment(alignment, columns=columns) 1.23 + block.process(Muscle) 1.24 + alignment.to_file(open(options.out_file, "w")) 1.25 + if options.msf: 1.26 + os.system("seqret " + options.out_file + " msf::" + options.out_file.split(".")[0] + ".msf") 1.27 + os.system("rm " + options.out_file) 1.28 + 1.29 +if __name__ == "__main__": 1.30 + usage = "Usage: %s [options]\n\n%s" % (sys.argv[0], __doc__.strip()) 1.31 + parser = optparse.OptionParser(usage=usage) 1.32 + parser.add_option("-i", "--in-file", 1.33 + help="Input alignment file (in FASTA format)") 1.34 + parser.add_option("-o", "--out-file", 1.35 + help="Output file") 1.36 + parser.add_option("-b", "--begin", type=int, 1.37 + help="Position in alignment to start from") 1.38 + parser.add_option("-e", "--end", type=int, 1.39 + help="Position in alignment to end with") 1.40 + parser.add_option("-m", "--msf", action='store_true', 1.41 + help="Output in MSF format (FASTA by default)") 1.42 + 1.43 + options, args = parser.parse_args() 1.44 + 1.45 + if args: 1.46 + parser.error("We take no positional arguments.") 1.47 + if not options.in_file or not options.out_file: 1.48 + parser.error("Both -i and -o parameters must be given.") 1.49 + 1.50 + main() 1.51 + 1.52 +# vim: set et ts=4 sts=4 sw=4: