Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/rev/211330654df7
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 00:45:01 2012
Кодировка:
allpy: 211330654df7

allpy

changeset 596:211330654df7

pair_cores: multiprocessing, no forking
author boris (kodomo) <bnagaev@gmail.com>
date Sat, 02 Apr 2011 17:04:11 +0400
parents 688348824267
children 9ee27791d3e6
files pair_cores/pair_cores.py pair_cores/pair_cores_all.py
diffstat 2 files changed, 89 insertions(+), 37 deletions(-) [+]
line diff
     1.1 --- a/pair_cores/pair_cores.py	Fri Apr 01 17:14:26 2011 +0400
     1.2 +++ b/pair_cores/pair_cores.py	Sat Apr 02 17:04:11 2011 +0400
     1.3 @@ -33,53 +33,61 @@
     1.4              if m not in monomers_with_structure:
     1.5                  assert not hasattr(column.pop(s), 'ca_xyz')
     1.6  
     1.7 -r = argparse.FileType('r')
     1.8 -w = argparse.FileType('w')
     1.9 +def run(args):
    1.10  
    1.11 -p = argparse.ArgumentParser(
    1.12 -description='PairCores',
    1.13 -formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    1.14 -)
    1.15 +    try:
    1.16 +        alignment = Alignment().append_file(args.i)
    1.17 +    except:
    1.18 +        raise Exception()
    1.19  
    1.20 -p.add_argument('-v','--version',action='version',version='%(prog)s 2.0')
    1.21 -p.add_argument('-i',help='Input alignment file',metavar='FILE',type=r,required=True)
    1.22 -p.add_argument('-d',help='Distance spreading',metavar='float',type=float,default=2.0)
    1.23 -p.add_argument('-o',help='Output alignment file',metavar='FILE',type=w, required=True)
    1.24 -p.add_argument('-b',help='Output pair_cores file',metavar='FILE',type=w, required=True)
    1.25 -p.add_argument('-H',help='Output HTML file',metavar='FILE',type=w)
    1.26 +    unique_sequences = list(set([s.name for s in alignment.sequences]))
    1.27 +    if len(unique_sequences) < len(alignment.sequences):
    1.28 +        alignment.sequences = unique_sequences
    1.29  
    1.30 -args = p.parse_args()
    1.31 +    bad_sequences = set()
    1.32 +    for sequence in copy(alignment.sequences):
    1.33 +        try:
    1.34 +            sequence.auto_pdb(xyz_only=True)
    1.35 +        except:
    1.36 +            bad_sequences.add(sequence)
    1.37 +    if bad_sequences:
    1.38 +        alignment.sequences = list(set(alignment.sequences)-bad_sequences)
    1.39  
    1.40 -try:
    1.41 -    alignment = Alignment().append_file(args.i)
    1.42 -except:
    1.43 -    raise Exception()
    1.44 +    if len(alignment.sequences) < 2:
    1.45 +        raise Exception()
    1.46  
    1.47 -unique_sequences = list(set([s.name for s in alignment.sequences]))
    1.48 -if len(unique_sequences) < len(alignment.sequences):
    1.49 -    alignment.sequences = unique_sequences
    1.50 +    block = Block.from_alignment(alignment)
    1.51  
    1.52 -bad_sequences = set()
    1.53 -for sequence in copy(alignment.sequences):
    1.54 -    try:
    1.55 -        sequence.auto_pdb(xyz_only=True)
    1.56 -    except:
    1.57 -        bad_sequences.add(sequence)
    1.58 -if bad_sequences:
    1.59 -    alignment.sequences = list(set(alignment.sequences)-bad_sequences)
    1.60 +    remove_monomers_without_structure(block)
    1.61  
    1.62 -if len(alignment.sequences) < 2:
    1.63 -    raise Exception()
    1.64 +    block.to_file(args.o)
    1.65  
    1.66 -block = Block.from_alignment(alignment)
    1.67 +    blocks = block.pair_core_parts(max_delta=args.d, timeout=0)
    1.68 +    block.blocks_to_file(args.b, blocks)
    1.69  
    1.70 -remove_monomers_without_structure(block)
    1.71 +    if args.H:
    1.72 +        block.blocks_to_html(args.H, blocks, open(html_template).read())
    1.73  
    1.74 -block.to_file(args.o)
    1.75 +class A(object):
    1.76 +    pass
    1.77  
    1.78 -blocks = block.pair_core_parts(max_delta=args.d, timeout=0)
    1.79 -block.blocks_to_file(args.b, blocks)
    1.80 +if __name__ == '__main__':
    1.81  
    1.82 -if args.H:
    1.83 -    block.blocks_to_html(args.H, blocks, open(html_template).read())
    1.84 +    r = argparse.FileType('r')
    1.85 +    w = argparse.FileType('w')
    1.86  
    1.87 +    p = argparse.ArgumentParser(
    1.88 +    description='PairCores',
    1.89 +    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    1.90 +    )
    1.91 +
    1.92 +    p.add_argument('-v','--version',action='version',version='%(prog)s 2.0')
    1.93 +    p.add_argument('-i',help='Input alignment file',metavar='FILE',type=r,required=True)
    1.94 +    p.add_argument('-d',help='Distance spreading',metavar='float',type=float,default=2.0)
    1.95 +    p.add_argument('-o',help='Output alignment file',metavar='FILE',type=w, required=True)
    1.96 +    p.add_argument('-b',help='Output pair_cores file',metavar='FILE',type=w, required=True)
    1.97 +    p.add_argument('-H',help='Output HTML file',metavar='FILE',type=w)
    1.98 +
    1.99 +    args = p.parse_args()
   1.100 +    run(args)
   1.101 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/pair_cores/pair_cores_all.py	Sat Apr 02 17:04:11 2011 +0400
     2.3 @@ -0,0 +1,44 @@
     2.4 +
     2.5 +import sys
     2.6 +import os
     2.7 +from multiprocessing import Pool
     2.8 +from copy import copy
     2.9 +
    2.10 +from pair_cores import run, A
    2.11 +
    2.12 +d_in = sys.argv[1]
    2.13 +d_out = sys.argv[2]
    2.14 +name = sys.argv[3]
    2.15 +cpu_count = int(sys.argv[4])
    2.16 +
    2.17 +def run2(args):
    2.18 +    print args.i
    2.19 +    args.i = open(args.i)
    2.20 +    args.o = open(args.o, 'w')
    2.21 +    args.H = open(args.H, 'w')
    2.22 +    args.b = open(args.b, 'w')
    2.23 +    try:
    2.24 +        run(args)
    2.25 +    except:
    2.26 +        pass
    2.27 +
    2.28 +def tasks():
    2.29 +    for file in os.listdir(d_in):
    2.30 +        args = A()
    2.31 +        args.i = os.path.join(d_in, file)
    2.32 +        Dir = os.path.join(d_out, file)
    2.33 +        if not os.path.exists(Dir):
    2.34 +            os.mkdir(Dir)
    2.35 +        args.o = os.path.join(Dir, 'structure_only.fasta')
    2.36 +        for d in [2.0,2.5]:
    2.37 +            args.d = d
    2.38 +            args.H = os.path.join(Dir, '%s-%.1f.html'%(name,d))
    2.39 +            blocks_filename = os.path.join(Dir, '%s-%.1f.blocks'%(name,d))
    2.40 +            args.b = blocks_filename
    2.41 +            if not os.path.exists(blocks_filename) or os.path.getsize(blocks_filename) < 10:
    2.42 +                yield copy(args)
    2.43 +
    2.44 +pool = Pool(processes=cpu_count)
    2.45 +pool.map(run2, tasks())
    2.46 +
    2.47 +