Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/cd43d59c0dba
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:26:36 2012
Кодировка:

# HG changeset patch
# User Andrei
# Date 1294860428 -10800
# Node ID cd43d59c0dbaaa7d959b7422cc672183bea6dd54
# Parent 679494ad2f4e30c5a735f7f93c4822ba5ff8f6c8
flush_left renamed to flush_left_vblock. flush_left_vblocks created for multiple blocks flush left

diff -r 679494ad2f4e -r cd43d59c0dba utils/flush_left_vblock.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/utils/flush_left_vblock.py Wed Jan 12 22:27:08 2011 +0300
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+"""Flush all monomers in given range to the left, all gaps to the right.
+
+All position indexes are counting from 1.
+"""
+import optparse
+import sys
+import os
+from allpy import protein
+
+def main():
+ alignment = protein.Alignment.from_fasta(open(options.in_file))
+ if not options.begin:
+ options.begin = 1
+ if not options.end:
+ options.end = len(alignment.columns)
+ columns = alignment.columns[options.begin-1:options.end]
+ block = protein.Block.from_alignment(alignment, columns=columns)
+ block.flush_left()
+ alignment.to_fasta(open(options.out_file, "w"))
+ if options.msf:
+ os.system("seqret " + options.out_file + " msf::" + options.out_file.split(".")[0] + ".msf")
+ os.system("rm " + options.out_file)
+
+if __name__ == "__main__":
+ usage = "Usage: %s [options]\n\n%s" % (sys.argv[0], __doc__.strip())
+ parser = optparse.OptionParser(usage=usage)
+ parser.add_option("-i", "--in-file",
+ help="Input alignment file (in FASTA format)")
+ parser.add_option("-o", "--out-file",
+ help="Output file")
+ parser.add_option("-b", "--begin", type=int,
+ help="Position in alignment to start from")
+ parser.add_option("-e", "--end", type=int,
+ help="Position in alignment to end with")
+ parser.add_option("-m", "--msf", action='store_true',
+ help="Output in MSF format (FASTA by default)")
+
+ options, args = parser.parse_args()
+
+ if args:
+ parser.error("We take no positional arguments.")
+ if not options.in_file or not options.out_file:
+ parser.error("Both -i and -o parameters must be given.")
+
+ main()
+
+# vim: set et ts=4 sts=4 sw=4:
diff -r 679494ad2f4e -r cd43d59c0dba utils/flush_left_vblocks.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/utils/flush_left_vblocks.py Wed Jan 12 22:27:08 2011 +0300
@@ -0,0 +1,71 @@
+#!/usr/bin/python
+"""Flush all monomers in given ranges to the left, all gaps to the right.
+
+All position indexes are counting from 1.
+
+File with ranges format is as follows
+#from to
+10 15
+107 121
+etc
+
+Lines with "#" in 1st position are skipped
+
+"""
+import optparse
+import sys
+import os
+from allpy import protein
+
+def main(ranges):
+ alignment = protein.Alignment.from_fasta(open(options.in_file))
+ for begin, end in ranges:
+ columns = alignment.columns[begin-1:end]
+ block = protein.Block.from_alignment(alignment, columns=columns)
+ block.flush_left()
+
+ alignment.to_fasta(open(options.out_file, "w"))
+ if options.msf:
+ os.system("seqret " + options.out_file + " msf::" + options.out_file.split(".")[0] + ".msf")
+ os.system("rm " + options.out_file)
+
+def ranges():
+ ranges = []
+ for line_no, line in enumerate(open(options.ranges), 1):
+ if line.strip() == "":
+ continue
+ if line[0] == "#":
+ continue
+ try:
+ begin, end = line.strip().split()
+ begin = int(begin)
+ end = int(end)
+ except Exception:
+ print "Warning: wrong format in line %s, ignoring" % line_no
+ continue
+ ranges.append( (begin, end) )
+ return ranges
+
+
+if __name__ == "__main__":
+ usage = "Usage: %s [options]\n\n%s" % (sys.argv[0], __doc__.strip())
+ parser = optparse.OptionParser(usage=usage)
+ parser.add_option("-i", "--in-file",
+ help="Input alignment file (in FASTA format)")
+ parser.add_option("-o", "--out-file",
+ help="Output file")
+ parser.add_option("-r", "--ranges",
+ help="Input file with ranges")
+ parser.add_option("-m", "--msf", action='store_true',
+ help="Output in MSF format (FASTA by default)")
+
+ options, args = parser.parse_args()
+
+ if args:
+ parser.error("We take no positional arguments.")
+ if not options.in_file or not options.out_file:
+ parser.error("Both -i and -o parameters must be given.")
+
+ main(ranges())
+
+# vim: set et ts=4 sts=4 sw=4: