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

# HG changeset patch
# User boris (netbook)
# Date 1298287822 -10800
# Node ID 126f99bf234d834ca545107811ab5308a22eb4f9
# Parent 84730a6e4a153462ad6048cc6cd583ddc30492b7
geometrical_core refactoring

* move parameter validators to argparse_validators
* move export to spt to spt.py module

diff -r 84730a6e4a15 -r 126f99bf234d geometrical_core/argparse_validators.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/geometrical_core/argparse_validators.py Mon Feb 21 14:30:22 2011 +0300
@@ -0,0 +1,63 @@
+
+import argparse
+
+def f_nng(string):
+ """ Validates nonnegative (>=0) float """
+ try:
+ value = float(string)
+ except:
+ msg = "%r is wrong float" % string
+ raise argparse.ArgumentTypeError(msg)
+ if value < 0:
+ msg = "%r is negative" % string
+ raise argparse.ArgumentTypeError(msg)
+ return value
+
+def part(string):
+ """ Validates 0.0 <= float <= 1.0 """
+ try:
+ value = float(string)
+ except:
+ msg = "%r is wrong float" % string
+ raise argparse.ArgumentTypeError(msg)
+ if not (0.0 <= value <= 1.0):
+ msg = "%r is not float, representing part, ie in [0, 1]" % string
+ raise argparse.ArgumentTypeError(msg)
+ return value
+
+def timeout(string):
+ """ Validates int >= -1 """
+ try:
+ value = int(string)
+ except:
+ msg = "%r is wrong integer" % string
+ raise argparse.ArgumentTypeError(msg)
+ if value < -1:
+ msg = "integer %r is less than -1" % string
+ raise argparse.ArgumentTypeError(msg)
+ return value
+
+def pos(string):
+ """ Validates positive integer """
+ try:
+ value = int(string)
+ except:
+ msg = "%r is wrong integer" % string
+ raise argparse.ArgumentTypeError(msg)
+ if value < 1:
+ msg = "%r is not positive integer" % string
+ raise argparse.ArgumentTypeError(msg)
+ return value
+
+def i_nng(string):
+ """ Validates int >= 0 """
+ try:
+ value = int(string)
+ except:
+ msg = "%r is wrong integer" % string
+ raise argparse.ArgumentTypeError(msg)
+ if value < 0:
+ msg = "integer %r is less than 0" % string
+ raise argparse.ArgumentTypeError(msg)
+ return value
+
diff -r 84730a6e4a15 -r 126f99bf234d geometrical_core/geometrical-core
--- a/geometrical_core/geometrical-core Mon Feb 21 00:02:27 2011 +0300
+++ b/geometrical_core/geometrical-core Mon Feb 21 14:30:22 2011 +0300
@@ -6,108 +6,54 @@

import argparse
import os
-from tempfile import NamedTemporaryFile

from allpy import config
from protein_pdb import Alignment, Block, Monomer, Sequence
from allpy import markup
from allpy import fileio
+from spt import gcs_to_spt
+from argparse_validators import f_nng, part, timeout, pos, i_nng

r = argparse.FileType('r')
w = argparse.FileType('w')
c = config

-def f_nng(string):
- """ Validates nonnegative (>=0) float """
- try:
- value = float(string)
- except:
- msg = "%r is wrong float" % string
- raise argparse.ArgumentTypeError(msg)
- if value < 0:
- msg = "%r is negative" % string
- raise argparse.ArgumentTypeError(msg)
- return value
-
-def part(string):
- """ Validates 0.0 <= float <= 1.0 """
- try:
- value = float(string)
- except:
- msg = "%r is wrong float" % string
- raise argparse.ArgumentTypeError(msg)
- if not (0.0 <= value <= 1.0):
- msg = "%r is not float, representing part, ie in [0, 1]" % string
- raise argparse.ArgumentTypeError(msg)
- return value
-
-def timeout(string):
- """ Validates int >= -1 """
- try:
- value = int(string)
- except:
- msg = "%r is wrong integer" % string
- raise argparse.ArgumentTypeError(msg)
- if value < -1:
- msg = "integer %r is less than -1" % string
- raise argparse.ArgumentTypeError(msg)
- return value
-
-def pos(string):
- """ Validates positive integer """
- try:
- value = int(string)
- except:
- msg = "%r is wrong integer" % string
- raise argparse.ArgumentTypeError(msg)
- if value < 1:
- msg = "%r is not positive integer" % string
- raise argparse.ArgumentTypeError(msg)
- return value
-
-def i_nng(string):
- """ Validates int >= 0 """
- try:
- value = int(string)
- except:
- msg = "%r is wrong integer" % string
- raise argparse.ArgumentTypeError(msg)
- if value < 0:
- msg = "integer %r is less than 0" % string
- raise argparse.ArgumentTypeError(msg)
- return value
-
p = argparse.ArgumentParser(
description='Geometrical Core building tool.',
epilog='''1) Distance spreading [angstrom]
2) -1 timeout means running Bron-Kerbosh algorithm without timeout
3) Alternative core new aa part: read documentation for more information
-4) Superposition core identifier: main core is 0, first alternative is 1 etc. ''',
+4) Superposition core: main core is 0, first alternative is 1 etc. ''',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
-#~ argument_default=argparse.SUPPRESS,
)

p.add_argument('-v','--version',action='version',version='%(prog)s 2.0')
-p.add_argument('-i',help='Input alignment file',metavar='FILE',type=r,required=True)
-p.add_argument('-c',help='PDB names conformity file',metavar='FILE',type=r)
+p.add_argument('-i',help='Input alignment file',
+ metavar='FILE',type=r,required=True)
+p.add_argument('-c',help='PDB names conformity file',
+ metavar='FILE',type=r)
p.add_argument('-l',help='Output list file',metavar='FILE',type=w)
p.add_argument('-f',help='Output fasta file',metavar='FILE',type=w)
p.add_argument('-g',help='Output msf file',metavar='FILE',type=w)
p.add_argument('-p',help='Output pdb file',metavar='FILE',type=w)
p.add_argument('-s',help='Output spt file',metavar='FILE',type=w)
-p.add_argument('-d',help='Distance spreading',metavar='float',type=f_nng,default=c.delta)
-p.add_argument('-m',help='Min core size',metavar='int',type=pos,default=c.minsize)
-p.add_argument('-t',help='Bron-Kerbosh algorithm timeout',metavar='int',type=timeout,default=c.timeout)
-p.add_argument('-n',help='Alternative core new aa part',metavar='float',type=part,default=c.ac_new_atoms)
-p.add_argument('-a',help='Cores count',metavar='int',type=i_nng,default=c.ac_count)
-p.add_argument('-x',help='Superposition core identifier',metavar='int',type=i_nng,default=0)
+p.add_argument('-d',help='Distance spreading',
+ metavar='float',type=f_nng,default=c.delta)
+p.add_argument('-m',help='Min core size',
+ metavar='int',type=pos,default=c.minsize)
+p.add_argument('-t',help='Bron-Kerbosh algorithm timeout',
+ metavar='int',type=timeout,default=c.timeout)
+p.add_argument('-n',help='Alternative core new aa part',
+ metavar='float',type=part,default=c.ac_new_atoms)
+p.add_argument('-a',help='Cores count',
+ metavar='int',type=i_nng,default=c.ac_count)
+p.add_argument('-x',help='Superposition core identifier',
+ metavar='int',type=i_nng,default=0)

-tmp_file = None
-
-#try:
args = p.parse_args()

-if not args.l and not args.f and not args.g and not args.p and not args.s:
+if not args.l and not args.f and not args.g\
+ and not args.p and not args.s:
print 'Error: no output file provided'
exit()
if not (args.p and args.s) and not (not args.p and not args.s):
@@ -176,51 +122,5 @@
pdb_map = block.save_pdb(args.p)

if args.s:
- s = args.s # spt
- temp_i = 0
- for sequence in alignment.sequences:
- chain, model = pdb_map[sequence]
- s.write("define p_%(name)s *:%(chain)s/%(model)d\n" %\
- {'name':sequence.name, 'chain':chain, 'model':model})
- cores = []
- for j, gc in enumerate(GCs):
- j = j or ''
- core_parts = []
- for sequence in alignment.sequences:
- core_parts.append("core%(j)s_%(name)s"%\
- {'name': sequence.name, 'j': j})
- gc_n = []
- for column in gc:
- monomer = column[sequence]
- residue = monomer.pdb_residue
- hetero_flag, n, insertion = residue.id
- gc_n.append(n)
- gc_n.sort()
- batches = []
- while gc_n:
- batch = '(%s)' % (','.join(str(i) for i in gc_n[:50]))
- batches.append(batch)
- gc_n = gc_n[50:]
- if len(batches) == 1:
- s.write(
- "define core%(j)s_%(name)s %(batch)s and p_%(name)s\n"%\
- {'name': sequence.name, 'batch': batch, 'j': j})
- else:
- temps = []
- for batch in batches:
- s.write(
- "define temp_%(i)d %(batch)s and p_%(name)s\n" %\
- {'name': sequence.name, 'batch': batch, 'i': i})
- temps.append("temp_%(i)d" % {'i': i})
- temps_str = '(%s)' % (','.join(temps))
- s.write(
- "define core%(j)s_%(name)s %(temps_str)s\n" % {'j':j,
- 'name': sequence.name, 'temps_str': temps_str})
- s.write("define core%(j)s %(core_parts)s\n" % {'j':j,
- 'core_parts': ','.join(core_parts)})
- cores.append("core%(j)s" % {'j': j})
- s.write("define cores %(cores)s\n" % {'cores': ','.join(cores)})
+ gcs_to_spt(args.s, GCs, alignment, pdb_map)

-if tmp_file:
- os.unlink(tmp_file.name)
-
diff -r 84730a6e4a15 -r 126f99bf234d geometrical_core/spt.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/geometrical_core/spt.py Mon Feb 21 14:30:22 2011 +0300
@@ -0,0 +1,55 @@
+
+def gcs_to_spt(spt, GCs, alignment, pdb_map):
+ """ Save information about geometrical cores to spt
+
+ * spt - file object for write
+ * GCs - list of geomentrical cores.
+ Geometrical core is a collection of Column's
+ * alignment
+ * pdb_map - {sequence: (chain, model)}
+ char chain
+ int model
+ """
+ temp_i = 0
+ for sequence in alignment.sequences:
+ chain, model = pdb_map[sequence]
+ spt.write("define p_%(name)s *:%(chain)s/%(model)d\n" %\
+ {'name':sequence.name, 'chain':chain, 'model':model})
+ cores = []
+ for j, gc in enumerate(GCs):
+ j = j or ''
+ core_parts = []
+ for sequence in alignment.sequences:
+ core_parts.append("core%(j)s_%(name)s"%\
+ {'name': sequence.name, 'j': j})
+ gc_n = []
+ for column in gc:
+ monomer = column[sequence]
+ residue = monomer.pdb_residue
+ hetero_flag, n, insertion = residue.id
+ gc_n.append(n)
+ gc_n.sort()
+ batches = []
+ while gc_n:
+ batch = '(%s)'%(','.join(str(i) for i in gc_n[:50]))
+ batches.append(batch)
+ gc_n = gc_n[50:]
+ if len(batches) == 1:
+ spt.write(
+ "define core%(j)s_%(name)s %(batch)s and p_%(name)s\n"%\
+ {'name': sequence.name, 'batch': batch, 'j': j})
+ else:
+ temps = []
+ for batch in batches:
+ spt.write(
+ "define temp_%(i)d %(batch)s and p_%(name)s\n"\
+ %{'name': sequence.name, 'batch': batch, 'i': i})
+ temps.append("temp_%(i)d" % {'i': i})
+ temps_str = '(%s)' % (','.join(temps))
+ spt.write(
+ "define core%(j)s_%(name)s %(temps_str)s\n" % {'j':j,
+ 'name': sequence.name, 'temps_str': temps_str})
+ spt.write("define core%(j)s %(core_parts)s\n" % {'j':j,
+ 'core_parts': ','.join(core_parts)})
+ cores.append("core%(j)s" % {'j': j})
+ spt.write("define cores %(cores)s\n" % {'cores': ','.join(cores)})