# -*- coding: utf-8 -*- # :noTabs=true: import sys, os, os.path, commands import json args = json.load( file('.arguments.py') ) essential = [] # list of essential files for this jobs, rest of files will be deleted in ~30 days after the job finish. def execute(message, commandline, return_=False): print message print commandline (res, output) = commands.getstatusoutput(commandline) print output if res: print "\nEncounter error while executing: ", commandline if return_: return True else: sys.exit(1) return False def exit_with_job_failure(failure_message): output = dict(status='fail', failure_message=failure_message) json.dump(output, file('output.json', 'w') ) sys.exit(0) """ # now lets find all CDR_* regions! light_chain = file('input/light_chain.fasta').read() l1 = file('output/query.l1').read().split('\n')[1] l2 = file('output/query.l2').read().split('\n')[1] l3 = file('output/query.l3').read().split('\n')[1] FR_L1, CDR_L1, _ = light_chain.partition(l1) FR_L2, CDR_L2, _ = _.partition(l2) FR_L3, CDR_L3, FR_L4 = _.partition(l3) light_chain_annotated = [('FR_L1',FR_L1), ('CDR_L1', CDR_L1), ('FR_L2', FR_L2), ('CDR_L2', CDR_L2), ('FR_L3', FR_L3), ('CDR_L3',CDR_L3), ('FR_L4', FR_L4)] heavy_chain = file('input/heavy_chain.fasta').read() h1 = file('output/query.h1').read().split('\n')[1] h2 = file('output/query.h2').read().split('\n')[1] h3 = file('output/query.h3').read().split('\n')[1] FR_H1, CDR_H1, _ = heavy_chain.partition(h1) FR_H2, CDR_H2, _ = _.partition(h2) FR_H3, CDR_H3, FR_H4 = _.partition(h3) heavy_chain_annotated = [('FR_H1',FR_H1), ('CDR_H1', CDR_H1), ('FR_H2', FR_H2), ('CDR_H2', CDR_H2), ('FR_H3', FR_H3), ('CDR_H3',CDR_H3), ('FR_H4', FR_H4)] def read_align_file(fname): ''' read .align file and produce tuple (CDR_code, [keys] [list_of_top_values]) with top ~20 structures plus one that in the right side of query.matches and all keys as a zero row ''' lines = file(fname).read().split('\n') file_cdr_key = lines[2].split('.')[-1] for l in file('output/query.matches'): if file_cdr_key == l.split()[0]: matched_pdb = l.split()[-3] [3:7] alignment_keys = ['No.', 'PDB', 'Identity', 'Alignment length', 'Mismatches', 'Gap openings', 'Q start', 'Q end', 'S start', 'S end', 'E value', 'Bit score'] res = [alignment_keys] for l in lines[4:14]: if l: d = l.split() d[1] = d[1] [3:7] if d[1] == matched_pdb: res.insert(1, d) else: res.append(d) d[0] = res.index(d) ''' d = dict( zip(alignment_keys, l.split())[1:] ) d[ alignment_keys[1] ] = d[ alignment_keys[1] ] [3:7] if d[ alignment_keys[1] ] == matched_pdb: res.insert(0, d) else: res.append(d) d['No.'] = res.index(d) + 1 ''' return (file_cdr_key.upper(), res) alignment = dict( map(lambda f: read_align_file('output/query_%s.align' % f), ['l1', 'l2', 'l3', 'h1', 'h2', 'h3', 'lfr', 'hfr', 'lightheavy', ] ) ) """ # extract score info if any... score_table = [] score_table_keys = [] best_decoys = [] score_file = 'score.sf' if os.path.isfile('output/results.json'): status = 0 else: status = 'fail' output = dict(json.load( file('output/results.json') ), status=status, #light_chain_annotated=light_chain_annotated, heavy_chain_annotated=heavy_chain_annotated, #alignment=alignment, #score_table=score_table, score_table_keys=score_table_keys, best_decoys=best_decoys, cluster_centers=cluster_centers, essential=essential) json.dump(output, file('output.json', 'w') )