1 from os import popen2
2 from itertools import imap,count
3
4 from obitools.table import iTableIterator,TableRow,Table,SelectionIterator
5 from obitools.utils import ColumnFile
6 from obitools.location import SimpleLocation
7 from obitools.fasta import formatFasta
8 import sys
9
11 '''
12 Run blast
13 '''
14
15 - def __init__(self,mode,db,program='blastall',**options):
20
23
24
27
28
31
33 tmp = """%(program)s \\
34 -p %(mode)s \\
35 -d %(db)s \\
36 -m 8 \\
37 %(options)s \\
38 """
39 options = ' '.join(['-%s %s' % (x[0],str(x[1]))
40 for x in self._options.iteritems()])
41 data = {
42 'program' : self.program,
43 'db' : self.db,
44 'mode' : self.mode,
45 'options' : options
46 }
47
48 return tmp % data
49
66
67 mode = property(getMode, None, None, "Mode's Docstring")
68
69 db = property(getDb, None, None, "Db's Docstring")
70
71 program = property(getProgram, None, None, "Program's Docstring")
72
73
75 '''
76 Run blast on ncbi servers
77 '''
78
86
87
89
90 - def __init__(self,blastoutput,query=None):
91 '''
92
93 @param blastoutput:
94 @type blastoutput:
95 '''
96 self._blast = ColumnFile(blastoutput,
97 strip=True,
98 skip="#",
99 sep="\t",
100 types=self.types
101 )
102 self._query = query
103 self._hindex = dict((k,i) for i,k in imap(None,count(),self._getHeaders()))
104
106 return ('Query id','Subject id',
107 '% identity','alignment length',
108 'mismatches', 'gap openings',
109 'q. start', 'q. end',
110 's. start', 's. end',
111 'e-value', 'bit score')
112
114 return (str,str,
115 float,int,
116 int,int,
117 int,int,
118 int,int,
119 float,float)
120
123
126
129
130
131 headers = property(_getHeaders,None,None)
132 types = property(_getTypes,None,None)
133 rowFactory = property(_getRowFactory,None,None)
134 subrowFactory = property(_getSubrowFactory,None,None)
135 query = property(_getQuery,None,None)
136
143
144
145
147 '''
148 Results of a blast run
149 '''
150
152 '''
153 Blast high scoring pair between two sequences
154 '''
155
159
163
165 return database[self[1]]
166
168 '''
169 Compute coverage of match on query sequence.
170
171 @param query: the query sequence. Default is None.
172 In this case the query sequence associated
173 to this blast result is used.
174 @type query: L{obitools.BioSequence}
175
176 @return: coverage fraction
177 @rtype: float
178 '''
179 if query is None:
180 query = self.table.query
181 assert query is not None
182 return float(self[7]-self[6]+1)/float(len(query))
183
189
191
192 - def __init__(self,blastiterator,covmin,query=None,**conditions):
199
201 return row.queryCov(self._query)>=self._covmin
202
205