Changeset 27
- Timestamp:
- 06/10/08 23:46:02 (4 years ago)
- Location:
- biocomp.pscoils/branches/biopython-enabled
- Files:
-
- 1 added
- 3 modified
-
scripts/pscoils (modified) (3 diffs)
-
src/biocomp/pscoils/__init__.py (modified) (5 diffs)
-
src/biocomp/pscoils/utils.py (added)
-
tests/tests_coils.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
biocomp.pscoils/branches/biopython-enabled/scripts/pscoils
r24 r27 2 2 import sys 3 3 import biocomp.pscoils 4 from biocomp.pscoils import pred_coil 5 from biocomp.pscoils.utils import readFasta, printCoil 4 6 import getopt 5 7 import string 8 from Bio.SeqRecord import SeqRecord 6 9 7 10 def usage(prog): … … 31 34 for o,a in opts: 32 35 if o == '-f': 33 seqs= biocomp.pscoils.readFasta(a)36 seqs=readFasta(a) 34 37 modefasta=True 35 38 elif o == '-p': … … 55 58 #use both 56 59 for name in seqs.keys(): # WARNING We assume only one sequence!!! 57 gg,gcc,prob,hept_seq,score=biocomp.pscoils.pred_coil2(seqs[name],prof,params,wlambda) 58 biocomp.pscoils.printCoil(seqs[name],len(seqs[name]),hept_seq,score,prob,gcc,gg,labels) 60 # TODO 61 raise("TODO") 62 gg,gcc,prob,hept_seq,score=biocomp.pscoils.pred_coil2(seqs[name],prof,params,wlambda) 63 printCoil(seqs[name],len(seqs[name]),hept_seq,score,prob,gcc,gg,labels) 59 64 elif modefasta: 60 65 for name in seqs.keys(): 61 gg,gcc,prob,hept_seq,score=biocomp.pscoils.pred_coil(seqs[name],len(seqs[name]),params,biocomp.pscoils.seqScore) 62 biocomp.pscoils.printCoil(seqs[name],len(seqs[name]),hept_seq,score,prob,gcc,gg,labels) 66 seqr = SeqRecord(seqs[name], id=name) 67 seqr = pred_coil(seqr, params) 68 printCoil(seqr,labels) 63 69 elif modeprofile: 70 # TODO 71 raise("TODO") 64 72 gg,gcc,prob,hept_seq,score=biocomp.pscoils.pred_coil(prof,profLen,params,biocomp.pscoils.profScore) 65 73 biocomp.pscoils.printCoil('x'*profLen,profLen,hept_seq,score,prob,gcc,gg,labels) -
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 -
biocomp.pscoils/branches/biopython-enabled/tests/tests_coils.py
r10 r27 3 3 from unittest import TestCase 4 4 import StringIO 5 import biocomp.pscoils 5 from biocomp.pscoils import pred_coil 6 from biocomp.pscoils.utils import readFasta, printCoil 7 from biocomp.pscoils.Params import Params 8 from Bio.SeqRecord import SeqRecord 6 9 7 10 class test_suite(TestCase): … … 12 15 win=21 13 16 modeprofile=False 14 seqs= biocomp.pscoils.readFasta("tests/ferritin.fasta")17 seqs=readFasta("tests/ferritin.fasta") 15 18 modefasta=True 16 19 labels='F' 17 params= biocomp.pscoils.Params.Params(weight,win)20 params=Params(weight,win) 18 21 output = StringIO.StringIO() 19 22 for name in seqs.keys(): 20 gg,gcc,prob,hept_seq,score=biocomp.pscoils.pred_coil(seqs[name],len(seqs[name]),params,biocomp.pscoils.seqScore) 21 biocomp.pscoils.printCoil(seqs[name],len(seqs[name]),hept_seq,score,prob,gcc,gg,labels,io=output) 23 seqr = SeqRecord(seqs[name], id=name) 24 seqr = pred_coil(seqr, params) 25 printCoil(seqr,labels,io=output) 22 26 bench_output = open("tests/ferritin.Coils").read() 23 27 self.assertEqual(output.getvalue(),bench_output) … … 29 33 win=21 30 34 modeprofile=False 31 seqs= biocomp.pscoils.readFasta("tests/ceba_bovin.fasta")35 seqs=readFasta("tests/ceba_bovin.fasta") 32 36 modefasta=True 33 37 labels='F' 34 params= biocomp.pscoils.Params.Params(weight,win)38 params=Params(weight,win) 35 39 output = StringIO.StringIO() 36 40 for name in seqs.keys(): 37 gg,gcc,prob,hept_seq,score=biocomp.pscoils.pred_coil(seqs[name],len(seqs[name]),params,biocomp.pscoils.seqScore) 38 biocomp.pscoils.printCoil(seqs[name],len(seqs[name]),hept_seq,score,prob,gcc,gg,labels,io=output) 41 seqr = SeqRecord(seqs[name], id=name) 42 seqr = pred_coil(seqr, params) 43 printCoil(seqr,labels,io=output) 39 44 bench_output = open("tests/ceba_bovin.Coils").read() 40 45 self.assertEqual(output.getvalue(),bench_output)
