#!/usr/bin/python # program: build_sheet # takes sheet constraints as inputs (or numbers) # and defines a sheet meeting constraints based # on near-backbone-11 prediction(s). """ Notes: the sheet generated assumes we are alternating directions (i.e. anti-parallel) and that each strand specified by the first two digits in the tuple are in the order as they appear in the sheet. Otherwise things can get screwed up. TODO: handle parallel and mixed sheets. (direction doesn't change between strands...) """ import string import sys eUp = 0 eDown = 1 eNeither = -1 from optparse import OptionParser def die(s,err=1): sys.stderr.write(s+'\n') sys.exit(err) direction = eUp # target = '' def getargs(): global options,target,direction usage = """usage: \%prog [-o] [-d] targetID < sheetValues \tSheet values are lines with either the standard SheetConstraint \tor four numbers separated by spaces that represent the two \tsections to align. The last pair has ascending values for parallel, \tand descending for anti-parallel (as is done in 'SheetContraint').""" p = OptionParser(usage) p.add_option("--orient","-o", help="Direction to orient the buried residues", default="up") p.add_option("--dist", "-d", help="Distribution base for near-backbone-11 predictions", default="t06") (options,args) = p.parse_args() # if len(args)<1: die("missing the target argument") if (options.orient=="up"): direction = eUp elif (options.orient=="down"): direction = eDown elif (options.orient=="neither"): direction = eNeither else: die("orientation must be either 'up','down', or 'neither'") return args # NOTE: add logic to force strand lengths to match (or just lay it out?) def mean(near,index): val = 0 i = 1 for v in near[index-1]: val += i*v i += 1 return val def buried_offset(near,a,b): use0 = 0 use1 = 0 for index in range(a,b+1,2): use0 += mean(near,index) use1 += mean(near,index+1) if use0>use1: return 0 return 1 # build a sheet based on the sequence, the near-backbond # and the list of tuples of numbers... def build_sheet(sequence,near,sheets,direction=0): seq = ' '+sequence for sheet in sheets: # get buried side off1 = int(direction<>buried_offset(near,sheet[0],sheet[1])) # flip the 'direction' between strands # only if we have anti-parallel?? if sheet[3]buried_offset(near,sheet[3],sheet[2])) # print "offs ",off1,off2 a = sheet[0] b = sheet[1] c = sheet[2]+off2 d = sheet[3]+off2 print ("SheetConstraint %c%-3i %c%-3i %c%-3i %c%-3i hbond %c%i 1.0" % \ (seq[a],a,seq[b],b,seq[c],c,seq[d],d,seq[a+off1],a+off1)) return def get_input(): lines = sys.stdin.readlines() sheets = [] for line in lines: # strip numbers fields = string.split(line) if fields[0]=="SheetConstraint": # strip unneeded sheet = [fields[1][7:],fields[2][7:],fields[3][7:],fields[4][7:]] else: sheet = [fields[0],fields[1],fields[2],fields[3]] sheet = tuple(map(int,sheet)) sheets.append(sheet) return sheets target = getargs()[0] prefix = "/projects/compbio/experiments/protein-predict/casp7/"+target+'/'+target # get sequence f = open(prefix+'.a2m') f.readline() sequence = '' for line in f.readline(): sequence += string.strip(line) f.close() # get near f = open(prefix+'.t06.near-backbone-11.rdb') near = [] lines = f.readlines() f.close() for line in lines: if not (line[0]>='0' and line[0]<='9'): continue if line[:3]=='10N': continue near.append(map(float,string.split(line)[2:])) sheets = get_input() build_sheet(sequence,near,sheets,direction)