- Timestamp:
- 06/10/08 23:46:02 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
biocomp.pscoils/branches/biopython-enabled/src/biocomp/pscoils/__init__.py
r6 r27 35 35 import math 36 36 import string 37 37 38 import Params # this must be in the sys.path. Params contains the COILS paramters 39 import utils 40 41 from Bio.SeqFeature import FeatureLocation, SeqFeature 38 42 39 43 # … … 69 73 return prof,pos 70 74 71 #---------------------------------#72 73 74 #----------- readFasta files75 def readFasta(fname):76 ''' readFasta(fname) returns a dictionary77 '''78 try:79 lines=open(fname,'r').readlines()80 except:81 sys.stderr.write('cannot open file '+fname+'\n')82 sys.exit()83 seqs={}84 name=''85 seq=''86 for line in lines:87 if line[0]=='>': # assuming fasta file88 if name != '':89 seqs[name]=seq90 seq=''91 name=line[1:].strip()92 else:93 seq+=''.join(line.split())94 if name != '':95 seqs[name]=seq96 return seqs97 75 #---------------------------------# 98 76 … … 134 112 135 113 136 #---------------------------------# 137 def pred_coil(seq,seqLen,params,fScore): 114 def pred_coil(seqr, params, fScore=None): 138 115 ''' pred_coil(seq,seqLen,params,fScore) returns the coiled coil prediction of sequence seq''' 116 if fScore == None: 117 fScore = seqScore 118 seq = seqr.seq 119 seqLen = len(seqr.seq) 139 120 hept_pos=['a','b','c','d','e','f','g'] 140 121 score=[0.0]*seqLen 141 prob=[0.0]*seqLen142 gcc=[0.0]*seqLen143 gg=[0.0]*seqLen144 122 hept_seq=['x']*seqLen 145 123 for i in range(seqLen-params.win+1): … … 160 138 hept_seq[i+j]=hept_pos[pos] 161 139 for i in range(seqLen): 162 gg[i],gcc[i],prob[i]= coilProb(score[i],params) 163 return gg,gcc,prob,hept_seq,score 164 140 gg, gcc, prob = coilProb(score[i],params) 141 seqf = SeqFeature(location=FeatureLocation(i,i), type="pscoils") 142 seqf.qualifiers = {'gg':gg, 143 'gcc': gcc, 144 'prob': prob, 145 'score': score[i], 146 'hept_seq': hept_seq[i]} 147 seqr.features.append(seqf) 148 return seqr 165 149 166 150 #---------------------------------# … … 195 179 return gg,gcc,prob,hept_seq,score 196 180 197 def printCoil(seq,seqLen,hept_seq,score,P,Gcc,Gg,labels='T',io=sys.stdout):198 ''' '''199 ccLab="C"200 loopLab="L"201 if labels !='T' :202 for i in range(seqLen):203 #print "%4d %c %c %7.3f %7.3f (%7.3f %7.3f)" % (i+1,seq[i],hept_seq[i],score[i],P[i],Gcc[i],Gg[i])204 io.write("%4d %c %c %7.3f %7.3f %7.3f %7.3f\n" % (i+1,seq[i],hept_seq[i],score[i],P[i],Gcc[i],Gg[i]))205 else:206 io.write(" Pos A Hep Score Prob Gcc Gg Pred (Loop=L Coiledcoil=C)\n")207 for i in range(seqLen):208 if P[i] > 0.5:209 clabel=ccLab210 else:211 clabel=loopLab212 io.write("%4d %c %c %7.3f %7.3f %7.3f %7.3f %s\n" % (i+1,seq[i],hept_seq[i],score[i],P[i],Gcc[i],Gg[i],clabel))213 181
