Changeset 27

Show
Ignore:
Timestamp:
06/10/08 23:46:02 (4 years ago)
Author:
mauro
Message:
 
Location:
biocomp.pscoils/branches/biopython-enabled
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • biocomp.pscoils/branches/biopython-enabled/scripts/pscoils

    r24 r27  
    22import sys 
    33import biocomp.pscoils 
     4from biocomp.pscoils import pred_coil 
     5from biocomp.pscoils.utils import readFasta, printCoil 
    46import getopt 
    57import string 
     8from Bio.SeqRecord import SeqRecord 
    69 
    710def usage(prog): 
     
    3134    for o,a in opts: 
    3235        if o == '-f': 
    33             seqs=biocomp.pscoils.readFasta(a) 
     36            seqs=readFasta(a) 
    3437            modefasta=True 
    3538        elif o == '-p': 
     
    5558        #use both  
    5659        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) 
    5964    elif modefasta: 
    6065        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) 
    6369    elif modeprofile: 
     70        # TODO 
     71        raise("TODO") 
    6472        gg,gcc,prob,hept_seq,score=biocomp.pscoils.pred_coil(prof,profLen,params,biocomp.pscoils.profScore) 
    6573        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  
    3535import math 
    3636import string 
     37 
    3738import Params # this must be in the sys.path. Params contains the COILS paramters 
     39import utils 
     40 
     41from Bio.SeqFeature import FeatureLocation, SeqFeature 
    3842 
    3943# 
     
    6973    return prof,pos 
    7074     
    71 #---------------------------------# 
    72  
    73  
    74 #----------- readFasta files  
    75 def readFasta(fname): 
    76     ''' readFasta(fname) returns a dictionary  
    77     ''' 
    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 file 
    88            if name != '': 
    89                seqs[name]=seq 
    90                seq='' 
    91            name=line[1:].strip() 
    92         else: 
    93            seq+=''.join(line.split()) 
    94     if name != '': 
    95         seqs[name]=seq 
    96     return seqs 
    9775#---------------------------------# 
    9876 
     
    134112 
    135113     
    136 #---------------------------------# 
    137 def pred_coil(seq,seqLen,params,fScore): 
     114def pred_coil(seqr, params, fScore=None): 
    138115    ''' 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) 
    139120    hept_pos=['a','b','c','d','e','f','g'] 
    140121    score=[0.0]*seqLen 
    141     prob=[0.0]*seqLen 
    142     gcc=[0.0]*seqLen 
    143     gg=[0.0]*seqLen 
    144122    hept_seq=['x']*seqLen 
    145123    for i in range(seqLen-params.win+1): 
     
    160138                hept_seq[i+j]=hept_pos[pos] 
    161139    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   
    165149     
    166150#---------------------------------# 
     
    195179    return gg,gcc,prob,hept_seq,score 
    196180   
    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=ccLab 
    210             else: 
    211                clabel=loopLab 
    212             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)) 
    213181             
  • biocomp.pscoils/branches/biopython-enabled/tests/tests_coils.py

    r10 r27  
    33from unittest import TestCase 
    44import StringIO 
    5 import biocomp.pscoils 
     5from biocomp.pscoils import pred_coil 
     6from biocomp.pscoils.utils import readFasta, printCoil 
     7from biocomp.pscoils.Params import Params 
     8from Bio.SeqRecord import SeqRecord 
    69 
    710class test_suite(TestCase): 
     
    1215        win=21 
    1316        modeprofile=False 
    14         seqs=biocomp.pscoils.readFasta("tests/ferritin.fasta") 
     17        seqs=readFasta("tests/ferritin.fasta") 
    1518        modefasta=True 
    1619        labels='F' 
    17         params=biocomp.pscoils.Params.Params(weight,win) 
     20        params=Params(weight,win) 
    1821        output = StringIO.StringIO() 
    1922        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) 
    2226        bench_output = open("tests/ferritin.Coils").read() 
    2327        self.assertEqual(output.getvalue(),bench_output)         
     
    2933        win=21 
    3034        modeprofile=False 
    31         seqs=biocomp.pscoils.readFasta("tests/ceba_bovin.fasta") 
     35        seqs=readFasta("tests/ceba_bovin.fasta") 
    3236        modefasta=True 
    3337        labels='F' 
    34         params=biocomp.pscoils.Params.Params(weight,win) 
     38        params=Params(weight,win) 
    3539        output = StringIO.StringIO() 
    3640        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) 
    3944        bench_output = open("tests/ceba_bovin.Coils").read() 
    4045        self.assertEqual(output.getvalue(),bench_output)