Package Bio :: Package Blast :: Module Record
[hide private]
[frames] | no frames]

Source Code for Module Bio.Blast.Record

  1  # Copyright 1999-2000 by Jeffrey Chang.  All rights reserved. 
  2  # This code is part of the Biopython distribution and governed by its 
  3  # license.  Please see the LICENSE file that should have been included 
  4  # as part of this package. 
  5   
  6  """Record classes to hold BLAST output. 
  7   
  8  Classes: 
  9  Blast              Holds all the information from a blast search. 
 10  PSIBlast           Holds all the information from a psi-blast search. 
 11   
 12  Header             Holds information from the header. 
 13  Description        Holds information about one hit description. 
 14  Alignment          Holds information about one alignment hit. 
 15  HSP                Holds information about one HSP. 
 16  MultipleAlignment  Holds information about a multiple alignment. 
 17  DatabaseReport     Holds information from the database report. 
 18  Parameters         Holds information from the parameters. 
 19   
 20  """ 
 21  # XXX finish printable BLAST output 
 22   
 23  from Bio.Align import Generic 
 24   
25 -class Header(object):
26 """Saves information from a blast header. 27 28 Members: 29 application The name of the BLAST flavor that generated this data. 30 version Version of blast used. 31 date Date this data was generated. 32 reference Reference for blast. 33 34 query Name of query sequence. 35 query_letters Number of letters in the query sequence. (int) 36 37 database Name of the database. 38 database_sequences Number of sequences in the database. (int) 39 database_letters Number of letters in the database. (int) 40 41 """
42 - def __init__(self):
43 self.application = '' 44 self.version = '' 45 self.date = '' 46 self.reference = '' 47 48 self.query = '' 49 self.query_letters = None 50 51 self.database = '' 52 self.database_sequences = None 53 self.database_letters = None
54
55 -class Description(object):
56 """Stores information about one hit in the descriptions section. 57 58 Members: 59 title Title of the hit. 60 score Number of bits. (int) 61 bits Bit score. (float) 62 e E value. (float) 63 num_alignments Number of alignments for the same subject. (int) 64 65 """
66 - def __init__(self):
67 self.title = '' 68 self.score = None 69 self.bits = None 70 self.e = None 71 self.num_alignments = None
72 - def __str__(self):
73 return "%-66s %5s %s" % (self.title, self.score, self.e)
74
75 -class Alignment(object):
76 """Stores information about one hit in the alignments section. 77 78 Members: 79 title Name. 80 hit_id Hit identifier. (str) 81 hit_def Hit definition. (str) 82 length Length. (int) 83 hsps A list of HSP objects. 84 85 """
86 - def __init__(self):
87 self.title = '' 88 self.hit_id = '' 89 self.hit_def = '' 90 self.length = None 91 self.hsps = []
92 - def __str__(self):
93 lines = self.title.split('\n') 94 lines.append("Length = %s\n" % self.length) 95 return '\n '.join(lines)
96
97 -class HSP(object):
98 """Stores information about one hsp in an alignment hit. 99 100 Members: 101 score BLAST score of hit. (float) 102 bits Number of bits for that score. (float) 103 expect Expect value. (float) 104 num_alignments Number of alignments for same subject. (int) 105 identities Number of identities (int) if using the XML parser. 106 Tuple of numer of identities/total aligned (int, int) 107 if using the (obsolete) plain text parser. 108 positives Number of positives (int) if using the XML parser. 109 Tuple of numer of positives/total aligned (int, int) 110 if using the (obsolete) plain text parser. 111 gaps Number of gaps (int) if using the XML parser. 112 Tuple of numer of gaps/total aligned (int, int) if 113 using the (obsolete) plain text parser. 114 align_length Length of the alignment. (int) 115 strand Tuple of (query, target) strand. 116 frame Tuple of 1 or 2 frame shifts, depending on the flavor. 117 118 query The query sequence. 119 query_start The start residue for the query sequence. (1-based) 120 query_end The end residue for the query sequence. (1-based) 121 match The match sequence. 122 sbjct The sbjct sequence. 123 sbjct_start The start residue for the sbjct sequence. (1-based) 124 sbjct_end The end residue for the sbjct sequence. (1-based) 125 126 Not all flavors of BLAST return values for every attribute: 127 score expect identities positives strand frame 128 BLASTP X X X X 129 BLASTN X X X X X 130 BLASTX X X X X X 131 TBLASTN X X X X X 132 TBLASTX X X X X X/X 133 134 Note: for BLASTX, the query sequence is shown as a protein sequence, 135 but the numbering is based on the nucleotides. Thus, the numbering 136 is 3x larger than the number of amino acid residues. A similar effect 137 can be seen for the sbjct sequence in TBLASTN, and for both sequences 138 in TBLASTX. 139 140 Also, for negative frames, the sequence numbering starts from 141 query_start and counts down. 142 143 """
144 - def __init__(self):
145 self.score = None 146 self.bits = None 147 self.expect = None 148 self.num_alignments = None 149 self.identities = (None, None) 150 self.positives = (None, None) 151 self.gaps = (None, None) 152 self.align_length = None 153 self.strand = (None, None) 154 self.frame = () 155 156 self.query = '' 157 self.query_start = None 158 self.query_end = None 159 self.match = '' 160 self.sbjct = '' 161 self.sbjct_start = None 162 self.sbjct_end = None
163
164 - def __str__(self):
165 lines = ["Score %i (%i bits), expectation %0.1e, alignment length %i" \ 166 % (self.score, self.bits, self.expect, self.align_length)] 167 if self.align_length < 50: 168 lines.append("Query:%s %s %s" % (str(self.query_start).rjust(8), 169 str(self.query), 170 str(self.query_end))) 171 lines.append(" %s" \ 172 % (str(self.match))) 173 lines.append("Sbjct:%s %s %s" % (str(self.sbjct_start).rjust(8), 174 str(self.sbjct), 175 str(self.sbjct_end))) 176 else: 177 lines.append("Query:%s %s...%s %s" \ 178 % (str(self.query_start).rjust(8), 179 str(self.query)[:45], 180 str(self.query)[-3:], 181 str(self.query_end))) 182 lines.append(" %s...%s" \ 183 % (str(self.match)[:45], 184 str(self.match)[-3:])) 185 lines.append("Sbjct:%s %s...%s %s" \ 186 % (str(self.sbjct_start).rjust(8), 187 str(self.sbjct)[:45], 188 str(self.sbjct)[-3:], 189 str(self.sbjct_end))) 190 return "\n".join(lines)
191
192 -class MultipleAlignment(object):
193 """Holds information about a multiple alignment. 194 195 Members: 196 alignment A list of tuples (name, start residue, sequence, end residue). 197 198 The start residue is 1-based. It may be blank, if that sequence is 199 not aligned in the multiple alignment. 200 201 """
202 - def __init__(self):
203 self.alignment = []
204
205 - def to_generic(self, alphabet):
206 """Retrieve generic alignment object for the given alignment. 207 208 Instead of the tuples, this returns an Alignment object from 209 Bio.Align.Generic, through which you can manipulate and query 210 the object. 211 212 alphabet is the specified alphabet for the sequences in the code (for 213 example IUPAC.IUPACProtein. 214 215 Thanks to James Casbon for the code. 216 """ 217 #TODO - Switch to new Bio.Align.MultipleSeqAlignment class? 218 seq_parts = [] 219 seq_names = [] 220 parse_number = 0 221 n = 0 222 for name, start, seq, end in self.alignment: 223 if name == 'QUERY': #QUERY is the first in each alignment block 224 parse_number += 1 225 n = 0 226 227 if parse_number == 1: # create on first_parse, append on all others 228 seq_parts.append(seq) 229 seq_names.append(name) 230 else: 231 seq_parts[n] += seq 232 n += 1 233 234 generic = Generic.Alignment(alphabet) 235 for (name,seq) in zip(seq_names,seq_parts): 236 generic.add_sequence(name, seq) 237 238 return generic
239
240 -class Round(object):
241 """Holds information from a PSI-BLAST round. 242 243 Members: 244 number Round number. (int) 245 reused_seqs Sequences in model, found again. List of Description objects. 246 new_seqs Sequences not found, or below threshold. List of Description. 247 alignments A list of Alignment objects. 248 multiple_alignment A MultipleAlignment object. 249 250 """
251 - def __init__(self):
252 self.number = None 253 self.reused_seqs = [] 254 self.new_seqs = [] 255 self.alignments = [] 256 self.multiple_alignment = None
257
258 -class DatabaseReport(object):
259 """Holds information about a database report. 260 261 Members: 262 database_name List of database names. (can have multiple dbs) 263 num_letters_in_database Number of letters in the database. (int) 264 num_sequences_in_database List of number of sequences in the database. 265 posted_date List of the dates the databases were posted. 266 ka_params A tuple of (lambda, k, h) values. (floats) 267 gapped # XXX this isn't set right! 268 ka_params_gap A tuple of (lambda, k, h) values. (floats) 269 270 """
271 - def __init__(self):
272 self.database_name = [] 273 self.posted_date = [] 274 self.num_letters_in_database = [] 275 self.num_sequences_in_database = [] 276 self.ka_params = (None, None, None) 277 self.gapped = 0 278 self.ka_params_gap = (None, None, None)
279
280 -class Parameters(object):
281 """Holds information about the parameters. 282 283 Members: 284 matrix Name of the matrix. 285 gap_penalties Tuple of (open, extend) penalties. (floats) 286 sc_match Match score for nucleotide-nucleotide comparison 287 sc_mismatch Mismatch penalty for nucleotide-nucleotide comparison 288 num_hits Number of hits to the database. (int) 289 num_sequences Number of sequences. (int) 290 num_good_extends Number of extensions. (int) 291 num_seqs_better_e Number of sequences better than e-value. (int) 292 hsps_no_gap Number of HSP's better, without gapping. (int) 293 hsps_prelim_gapped Number of HSP's gapped in prelim test. (int) 294 hsps_prelim_gapped_attemped Number of HSP's attempted in prelim. (int) 295 hsps_gapped Total number of HSP's gapped. (int) 296 query_length Length of the query. (int) 297 query_id Identifier of the query sequence. (str) 298 database_length Number of letters in the database. (int) 299 effective_hsp_length Effective HSP length. (int) 300 effective_query_length Effective length of query. (int) 301 effective_database_length Effective length of database. (int) 302 effective_search_space Effective search space. (int) 303 effective_search_space_used Effective search space used. (int) 304 frameshift Frameshift window. Tuple of (int, float) 305 threshold Threshold. (int) 306 window_size Window size. (int) 307 dropoff_1st_pass Tuple of (score, bits). (int, float) 308 gap_x_dropoff Tuple of (score, bits). (int, float) 309 gap_x_dropoff_final Tuple of (score, bits). (int, float) 310 gap_trigger Tuple of (score, bits). (int, float) 311 blast_cutoff Tuple of (score, bits). (int, float) 312 """
313 - def __init__(self):
314 self.matrix = '' 315 self.gap_penalties = (None, None) 316 self.sc_match = None 317 self.sc_mismatch = None 318 self.num_hits = None 319 self.num_sequences = None 320 self.num_good_extends = None 321 self.num_seqs_better_e = None 322 self.hsps_no_gap = None 323 self.hsps_prelim_gapped = None 324 self.hsps_prelim_gapped_attemped = None 325 self.hsps_gapped = None 326 self.query_id = None 327 self.query_length = None 328 self.database_length = None 329 self.effective_hsp_length = None 330 self.effective_query_length = None 331 self.effective_database_length = None 332 self.effective_search_space = None 333 self.effective_search_space_used = None 334 self.frameshift = (None, None) 335 self.threshold = None 336 self.window_size = None 337 self.dropoff_1st_pass = (None, None) 338 self.gap_x_dropoff = (None, None) 339 self.gap_x_dropoff_final = (None, None) 340 self.gap_trigger = (None, None) 341 self.blast_cutoff = (None, None)
342
343 -class Blast(Header, DatabaseReport, Parameters):
344 """Saves the results from a blast search. 345 346 Members: 347 descriptions A list of Description objects. 348 alignments A list of Alignment objects. 349 multiple_alignment A MultipleAlignment object. 350 + members inherited from base classes 351 352 """
353 - def __init__(self):
354 Header.__init__(self) 355 DatabaseReport.__init__(self) 356 Parameters.__init__(self) 357 self.descriptions = [] 358 self.alignments = [] 359 self.multiple_alignment = None
360
361 -class PSIBlast(Header, DatabaseReport, Parameters):
362 """Saves the results from a blastpgp search. 363 364 Members: 365 rounds A list of Round objects. 366 converged Whether the search converged. 367 + members inherited from base classes 368 369 """
370 - def __init__(self):
371 Header.__init__(self) 372 DatabaseReport.__init__(self) 373 Parameters.__init__(self) 374 self.rounds = [] 375 self.converged = 0
376