allpy
changeset 435:e19b527196c7
Added mass_realign_blocks util to apply muscle to multiple blocks in multiple files
author | Daniil Alexeyevsky <dendik@kodomo.fbb.msu.ru> |
---|---|
date | Tue, 15 Feb 2011 21:03:19 +0300 |
parents | 7d73604c8df6 |
children | fedcd441e2fc |
files | utils/mass_realign_blocks.py |
diffstat | 1 files changed, 48 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/utils/mass_realign_blocks.py Tue Feb 15 21:03:19 2011 +0300 1.3 @@ -0,0 +1,48 @@ 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 read_task(file): 1.16 + task = {} 1.17 + for line in file: 1.18 + line = line.rstrip("\n\r") 1.19 + filename, begin, end = line.split("\t") 1.20 + task[filename] = task.get(filename, []) 1.21 + task[filename].append((begin, end)) 1.22 + return task 1.23 + 1.24 +def main(): 1.25 + taks = read_task(open(options.task_file)) 1.26 + for filename in task: 1.27 + with open(filename) as in_file: 1.28 + alignment = protein.Alignment().append_file(in_file) 1.29 + columns = [] 1.30 + for begin, end in task[filename]: 1.31 + columns += alignment.columns[begin-1:end] 1.32 + block = protein.Block.from_alignment(alignment, columns=columns) 1.33 + block.process(Muscle) 1.34 + with open(filename, "w") as out_file: 1.35 + alignment.to_file(out_file) 1.36 + 1.37 +if __name__ == "__main__": 1.38 + usage = "Usage: %s [options]\n\n%s" % (sys.argv[0], __doc__.strip()) 1.39 + parser = optparse.OptionParser(usage=usage) 1.40 + parser.add_option("-t", "--task-file", 1.41 + help="Task description file. Each line has filename, start position, end position, separated with tabs.") 1.42 + options, args = parser.parse_args() 1.43 + 1.44 + if args: 1.45 + parser.error("We take no positional arguments.") 1.46 + if not options.task_file: 1.47 + parser.error("-t option is mandatory; see -h for help") 1.48 + 1.49 + main() 1.50 + 1.51 +# vim: set et ts=4 sts=4 sw=4: