allpy
changeset 909:30225705261a
add script pair_cores/against-database.py
Input:
* directory of .markup files
Output:
* scores file
author | Boris Nagaev <bnagaev@gmail.com> |
---|---|
date | Wed, 26 Oct 2011 22:44:07 +0300 |
parents | efed40e84d1a |
children | 7b070e8ff18c |
files | pair_cores/against-database.py |
diffstat | 1 files changed, 85 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/pair_cores/against-database.py Wed Oct 26 22:44:07 2011 +0300 1.3 @@ -0,0 +1,85 @@ 1.4 +#!/usr/bin/python 1.5 + 1.6 +import os 1.7 +import glob 1.8 +import warnings 1.9 +import argparse 1.10 +import multiprocessing as mp 1.11 + 1.12 +from pair_cores_all import homology_from_markup_all 1.13 +score_all = __import__('score-all').score_all 1.14 +from allpy.homology import MonomerHomology as MH 1.15 +from allpy.util import Binder 1.16 +from allpy.structure import CachedDownloadPdb 1.17 + 1.18 +def makedirs(d): 1.19 + try: 1.20 + os.makedirs(d) 1.21 + except: 1.22 + pass 1.23 + 1.24 +def case_homology(file_in, file_out, case): 1.25 + MH.case_homology(file_in, file_out, case, 'markup') 1.26 + 1.27 +def against_database(markups_dir, mask, output_dir, scores, delta, cache, 1.28 + jobs, pair_cores, case, no_case, suffix): 1.29 + makedirs(output_dir) 1.30 + makedirs(os.path.join(output_dir, pair_cores)) 1.31 + makedirs(os.path.join(output_dir, case)) 1.32 + makedirs(os.path.join(output_dir, no_case)) 1.33 + case_tasks = [] 1.34 + for f in glob.glob(os.path.join(markups_dir, mask)): 1.35 + f = os.path.basename(f) 1.36 + case_tasks.append(Binder(case_homology, 1.37 + os.path.join(markups_dir, f), 1.38 + os.path.join(output_dir, case, f+suffix), True)) 1.39 + case_tasks.append(Binder(case_homology, 1.40 + os.path.join(markups_dir, f), 1.41 + os.path.join(output_dir, no_case, f+suffix), False)) 1.42 + jobs = jobs or mp.cpu_count() 1.43 + mp.Pool(processes=jobs).map(apply, case_tasks) 1.44 + 1.45 + homology_from_markup_all(input_dir=markups_dir, 1.46 + output_dir=os.path.join(output_dir, pair_cores), max_delta=delta, 1.47 + markups_list=mask, suffix=suffix, 1.48 + pdb_getter=CachedDownloadPdb(cache_dir=cache), cpu_count=jobs) 1.49 + 1.50 + score_all(output_dir, pair_cores, case, no_case, mask+suffix, scores) 1.51 + 1.52 +def main(): 1.53 + p = argparse.ArgumentParser(description='PairCores. ScoreAll', 1.54 + formatter_class=argparse.ArgumentDefaultsHelpFormatter) 1.55 + p.add_argument('-i', '--markups-dir', required=True, 1.56 + help='Directory with input markups') 1.57 + p.add_argument('-o', '--output-dir', required=True, 1.58 + help='Output directory') 1.59 + p.add_argument('-s', '--scores', type=argparse.FileType('w'), required=True, 1.60 + help='Output file with scores (final result)') 1.61 + p.add_argument('-m', '--mask', default='*.markup', 1.62 + help='Mask for input markup files in markups directory') 1.63 + p.add_argument('-d', '--delta', type=float, default=2.0, 1.64 + help='Distance spreading', ) 1.65 + p.add_argument('-c', '--cache', default='pdb_cache', 1.66 + help='Pdb cache directory') 1.67 + p.add_argument('-j', '--jobs', type=int, default=0, 1.68 + help='Number of workers (0 means number of CPUs)') 1.69 + p.add_argument('--pair-cores', default='pair-cores', 1.70 + help='Pair-cores results subdirectory') 1.71 + p.add_argument('--case', default='case', 1.72 + help='Homology from alignment (taking into account letter case)') 1.73 + p.add_argument('--no-case', default='no-case', 1.74 + help='Homology from alignment (ignoring letter case)') 1.75 + p.add_argument('--suffix', default=".xls", 1.76 + help='Suffix added to names of homology files') 1.77 + a = p.parse_args() 1.78 + against_database(markups_dir=a.markups_dir, mask=a.mask, 1.79 + output_dir=a.output_dir, scores=a.scores, delta=a.delta, cache=a.cache, 1.80 + jobs=a.jobs, pair_cores=a.pair_cores, case=a.case, no_case=a.no_case, 1.81 + suffix=a.suffix) 1.82 + 1.83 +if __name__ == '__main__': 1.84 + try: 1.85 + main() 1.86 + except Exception, e: 1.87 + warnings.warn(str(e), stacklevel=2) 1.88 +