Package Bio :: Package GenBank :: Module Scanner
[hide private]
[frames] | no frames]

Source Code for Module Bio.GenBank.Scanner

   1  # Copyright 2007-2010 by Peter Cock.  All rights reserved. 
   2  # Revisions copyright 2010 by Uri Laserson.  All rights reserved. 
   3  # This code is part of the Biopython distribution and governed by its 
   4  # license.  Please see the LICENSE file that should have been included 
   5  # as part of this package. 
   6  """Internal code for parsing GenBank and EMBL files (PRIVATE). 
   7   
   8  This code is NOT intended for direct use.  It provides a basic scanner 
   9  (for use with a event consumer such as Bio.GenBank._FeatureConsumer) 
  10  to parse a GenBank or EMBL file (with their shared INSDC feature table). 
  11   
  12  It is used by Bio.GenBank to parse GenBank files 
  13  It is also used by Bio.SeqIO to parse GenBank and EMBL files 
  14   
  15  Feature Table Documentation: 
  16  http://www.insdc.org/files/feature_table.html 
  17  http://www.ncbi.nlm.nih.gov/projects/collab/FT/index.html 
  18  ftp://ftp.ncbi.nih.gov/genbank/docs/ 
  19  """ 
  20  # 17-MAR-2009: added wgs, wgs_scafld for GenBank whole genome shotgun master records. 
  21  # These are GenBank files that summarize the content of a project, and provide lists of 
  22  # scaffold and contig files in the project. These will be in annotations['wgs'] and 
  23  # annotations['wgs_scafld']. These GenBank files do not have sequences. See 
  24  # http://groups.google.com/group/bionet.molbio.genbank/browse_thread/thread/51fb88bf39e7dc36 
  25  # http://is.gd/nNgk 
  26  # for more details of this format, and an example. 
  27  # Added by Ying Huang & Iddo Friedberg 
  28   
  29  from __future__ import print_function 
  30   
  31  import warnings 
  32  import re 
  33  from Bio.Seq import Seq 
  34  from Bio.SeqRecord import SeqRecord 
  35  from Bio.Alphabet import generic_protein 
  36  from Bio import BiopythonParserWarning 
  37   
  38  __docformat__ = "restructuredtext en" 
  39   
  40   
41 -class InsdcScanner(object):
42 """Basic functions for breaking up a GenBank/EMBL file into sub sections. 43 44 The International Nucleotide Sequence Database Collaboration (INSDC) 45 between the DDBJ, EMBL, and GenBank. These organisations all use the 46 same "Feature Table" layout in their plain text flat file formats. 47 48 However, the header and sequence sections of an EMBL file are very 49 different in layout to those produced by GenBank/DDBJ.""" 50 51 # These constants get redefined with sensible values in the sub classes: 52 RECORD_START = "XXX" # "LOCUS " or "ID " 53 HEADER_WIDTH = 3 # 12 or 5 54 FEATURE_START_MARKERS = ["XXX***FEATURES***XXX"] 55 FEATURE_END_MARKERS = ["XXX***END FEATURES***XXX"] 56 FEATURE_QUALIFIER_INDENT = 0 57 FEATURE_QUALIFIER_SPACER = "" 58 SEQUENCE_HEADERS = ["XXX"] # with right hand side spaces removed 59
60 - def __init__(self, debug=0):
61 assert len(self.RECORD_START) == self.HEADER_WIDTH 62 for marker in self.SEQUENCE_HEADERS: 63 assert marker == marker.rstrip() 64 assert len(self.FEATURE_QUALIFIER_SPACER) == self.FEATURE_QUALIFIER_INDENT 65 self.debug = debug 66 self.line = None
67
68 - def set_handle(self, handle):
69 self.handle = handle 70 self.line = ""
71
72 - def find_start(self):
73 """Read in lines until find the ID/LOCUS line, which is returned. 74 75 Any preamble (such as the header used by the NCBI on ``*.seq.gz`` archives) 76 will we ignored.""" 77 while True: 78 if self.line: 79 line = self.line 80 self.line = "" 81 else: 82 line = self.handle.readline() 83 if not line: 84 if self.debug: 85 print("End of file") 86 return None 87 if line[:self.HEADER_WIDTH] == self.RECORD_START: 88 if self.debug > 1: 89 print("Found the start of a record:\n" + line) 90 break 91 line = line.rstrip() 92 if line == "//": 93 if self.debug > 1: 94 print("Skipping // marking end of last record") 95 elif line == "": 96 if self.debug > 1: 97 print("Skipping blank line before record") 98 else: 99 # Ignore any header before the first ID/LOCUS line. 100 if self.debug > 1: 101 print("Skipping header line before record:\n" + line) 102 self.line = line 103 return line
104
105 - def parse_header(self):
106 """Return list of strings making up the header 107 108 New line characters are removed. 109 110 Assumes you have just read in the ID/LOCUS line. 111 """ 112 assert self.line[:self.HEADER_WIDTH] == self.RECORD_START, \ 113 "Not at start of record" 114 115 header_lines = [] 116 while True: 117 line = self.handle.readline() 118 if not line: 119 raise ValueError("Premature end of line during sequence data") 120 line = line.rstrip() 121 if line in self.FEATURE_START_MARKERS: 122 if self.debug: 123 print("Found feature table") 124 break 125 # if line[:self.HEADER_WIDTH]==self.FEATURE_START_MARKER[:self.HEADER_WIDTH]: 126 # if self.debug : print("Found header table (?)") 127 # break 128 if line[:self.HEADER_WIDTH].rstrip() in self.SEQUENCE_HEADERS: 129 if self.debug: 130 print("Found start of sequence") 131 break 132 if line == "//": 133 raise ValueError("Premature end of sequence data marker '//' found") 134 header_lines.append(line) 135 self.line = line 136 return header_lines
137
138 - def parse_features(self, skip=False):
139 """Return list of tuples for the features (if present) 140 141 Each feature is returned as a tuple (key, location, qualifiers) 142 where key and location are strings (e.g. "CDS" and 143 "complement(join(490883..490885,1..879))") while qualifiers 144 is a list of two string tuples (feature qualifier keys and values). 145 146 Assumes you have already read to the start of the features table. 147 """ 148 if self.line.rstrip() not in self.FEATURE_START_MARKERS: 149 if self.debug: 150 print("Didn't find any feature table") 151 return [] 152 153 while self.line.rstrip() in self.FEATURE_START_MARKERS: 154 self.line = self.handle.readline() 155 156 features = [] 157 line = self.line 158 while True: 159 if not line: 160 raise ValueError("Premature end of line during features table") 161 if line[:self.HEADER_WIDTH].rstrip() in self.SEQUENCE_HEADERS: 162 if self.debug: 163 print("Found start of sequence") 164 break 165 line = line.rstrip() 166 if line == "//": 167 raise ValueError("Premature end of features table, marker '//' found") 168 if line in self.FEATURE_END_MARKERS: 169 if self.debug: 170 print("Found end of features") 171 line = self.handle.readline() 172 break 173 if line[2:self.FEATURE_QUALIFIER_INDENT].strip() == "": 174 # This is an empty feature line between qualifiers. Empty 175 # feature lines within qualifiers are handled below (ignored). 176 line = self.handle.readline() 177 continue 178 if len(line) < self.FEATURE_QUALIFIER_INDENT: 179 warnings.warn("line too short to contain a feature: %r" % line, 180 BiopythonParserWarning) 181 line = self.handle.readline() 182 continue 183 184 if skip: 185 line = self.handle.readline() 186 while line[:self.FEATURE_QUALIFIER_INDENT] == self.FEATURE_QUALIFIER_SPACER: 187 line = self.handle.readline() 188 else: 189 # Build up a list of the lines making up this feature: 190 if line[self.FEATURE_QUALIFIER_INDENT] != " " \ 191 and " " in line[self.FEATURE_QUALIFIER_INDENT:]: 192 # The feature table design enforces a length limit on the feature keys. 193 # Some third party files (e.g. IGMT's EMBL like files) solve this by 194 # over indenting the location and qualifiers. 195 feature_key, line = line[2:].strip().split(None, 1) 196 feature_lines = [line] 197 warnings.warn("Overindented %s feature?" % feature_key, 198 BiopythonParserWarning) 199 else: 200 feature_key = line[2:self.FEATURE_QUALIFIER_INDENT].strip() 201 feature_lines = [line[self.FEATURE_QUALIFIER_INDENT:]] 202 line = self.handle.readline() 203 while line[:self.FEATURE_QUALIFIER_INDENT] == self.FEATURE_QUALIFIER_SPACER \ 204 or line.rstrip() == "": # cope with blank lines in the midst of a feature 205 # Use strip to remove any harmless trailing white space AND and leading 206 # white space (e.g. out of spec files with too much indentation) 207 feature_lines.append(line[self.FEATURE_QUALIFIER_INDENT:].strip()) 208 line = self.handle.readline() 209 features.append(self.parse_feature(feature_key, feature_lines)) 210 self.line = line 211 return features
212
213 - def parse_feature(self, feature_key, lines):
214 r"""Expects a feature as a list of strings, returns a tuple (key, location, qualifiers) 215 216 For example given this GenBank feature:: 217 218 CDS complement(join(490883..490885,1..879)) 219 /locus_tag="NEQ001" 220 /note="conserved hypothetical [Methanococcus jannaschii]; 221 COG1583:Uncharacterized ACR; IPR001472:Bipartite nuclear 222 localization signal; IPR002743: Protein of unknown 223 function DUF57" 224 /codon_start=1 225 /transl_table=11 226 /product="hypothetical protein" 227 /protein_id="NP_963295.1" 228 /db_xref="GI:41614797" 229 /db_xref="GeneID:2732620" 230 /translation="MRLLLELKALNSIDKKQLSNYLIQGFIYNILKNTEYSWLHNWKK 231 EKYFNFTLIPKKDIIENKRYYLIISSPDKRFIEVLHNKIKDLDIITIGLAQFQLRKTK 232 KFDPKLRFPWVTITPIVLREGKIVILKGDKYYKVFVKRLEELKKYNLIKKKEPILEEP 233 IEISLNQIKDGWKIIDVKDRYYDFRNKSFSAFSNWLRDLKEQSLRKYNNFCGKNFYFE 234 EAIFEGFTFYKTVSIRIRINRGEAVYIGTLWKELNVYRKLDKEEREFYKFLYDCGLGS 235 LNSMGFGFVNTKKNSAR" 236 237 Then should give input key="CDS" and the rest of the data as a list of strings 238 lines=["complement(join(490883..490885,1..879))", ..., "LNSMGFGFVNTKKNSAR"] 239 where the leading spaces and trailing newlines have been removed. 240 241 Returns tuple containing: (key as string, location string, qualifiers as list) 242 as follows for this example: 243 244 key = "CDS", string 245 location = "complement(join(490883..490885,1..879))", string 246 qualifiers = list of string tuples: 247 248 [('locus_tag', '"NEQ001"'), 249 ('note', '"conserved hypothetical [Methanococcus jannaschii];\nCOG1583:..."'), 250 ('codon_start', '1'), 251 ('transl_table', '11'), 252 ('product', '"hypothetical protein"'), 253 ('protein_id', '"NP_963295.1"'), 254 ('db_xref', '"GI:41614797"'), 255 ('db_xref', '"GeneID:2732620"'), 256 ('translation', '"MRLLLELKALNSIDKKQLSNYLIQGFIYNILKNTEYSWLHNWKK\nEKYFNFT..."')] 257 258 In the above example, the "note" and "translation" were edited for compactness, 259 and they would contain multiple new line characters (displayed above as \n) 260 261 If a qualifier is quoted (in this case, everything except codon_start and 262 transl_table) then the quotes are NOT removed. 263 264 Note that no whitespace is removed. 265 """ 266 # Skip any blank lines 267 iterator = (x for x in lines if x) 268 try: 269 line = next(iterator) 270 271 feature_location = line.strip() 272 while feature_location[-1:] == ",": 273 # Multiline location, still more to come! 274 line = next(iterator) 275 feature_location += line.strip() 276 277 qualifiers = [] 278 279 for line_number, line in enumerate(iterator): 280 # check for extra wrapping of the location closing parentheses 281 if line_number == 0 and line.startswith(")"): 282 feature_location += line.strip() 283 elif line[0] == "/": 284 # New qualifier 285 i = line.find("=") 286 key = line[1:i] # does not work if i==-1 287 value = line[i + 1:] # we ignore 'value' if i==-1 288 if i == -1: 289 # Qualifier with no key, e.g. /pseudo 290 key = line[1:] 291 qualifiers.append((key, None)) 292 elif not value: 293 # ApE can output /note= 294 qualifiers.append((key, "")) 295 elif value == '"': 296 # One single quote 297 if self.debug: 298 print("Single quote %s:%s" % (key, value)) 299 # DO NOT remove the quote... 300 qualifiers.append((key, value)) 301 elif value[0] == '"': 302 # Quoted... 303 value_list = [value] 304 while value_list[-1][-1] != '"': 305 value_list.append(next(iterator)) 306 value = '\n'.join(value_list) 307 # DO NOT remove the quotes... 308 qualifiers.append((key, value)) 309 else: 310 # Unquoted 311 # if debug : print("Unquoted line %s:%s" % (key,value)) 312 qualifiers.append((key, value)) 313 else: 314 # Unquoted continuation 315 assert len(qualifiers) > 0 316 assert key == qualifiers[-1][0] 317 # if debug : print("Unquoted Cont %s:%s" % (key, line)) 318 if qualifiers[-1][1] is None: 319 raise StopIteration 320 qualifiers[-1] = (key, qualifiers[-1][1] + "\n" + line) 321 return (feature_key, feature_location, qualifiers) 322 except StopIteration: 323 # Bummer 324 raise ValueError("Problem with '%s' feature:\n%s" 325 % (feature_key, "\n".join(lines)))
326 349
350 - def _feed_first_line(self, consumer, line):
351 """Handle the LOCUS/ID line, passing data to the comsumer 352 353 This should be implemented by the EMBL / GenBank specific subclass 354 355 Used by the parse_records() and parse() methods. 356 """ 357 pass
358
359 - def _feed_header_lines(self, consumer, lines):
360 """Handle the header lines (list of strings), passing data to the comsumer 361 362 This should be implemented by the EMBL / GenBank specific subclass 363 364 Used by the parse_records() and parse() methods. 365 """ 366 pass
367
368 - def _feed_feature_table(self, consumer, feature_tuples):
369 """Handle the feature table (list of tuples), passing data to the comsumer 370 371 Used by the parse_records() and parse() methods. 372 """ 373 consumer.start_feature_table() 374 for feature_key, location_string, qualifiers in feature_tuples: 375 consumer.feature_key(feature_key) 376 consumer.location(location_string) 377 for q_key, q_value in qualifiers: 378 if q_value is None: 379 consumer.feature_qualifier(q_key, q_value) 380 else: 381 consumer.feature_qualifier(q_key, q_value.replace("\n", " "))
382
383 - def _feed_misc_lines(self, consumer, lines):
384 """Handle any lines between features and sequence (list of strings), passing data to the consumer 385 386 This should be implemented by the EMBL / GenBank specific subclass 387 388 Used by the parse_records() and parse() methods. 389 """ 390 pass
391
392 - def feed(self, handle, consumer, do_features=True):
393 """Feed a set of data into the consumer. 394 395 This method is intended for use with the "old" code in Bio.GenBank 396 397 Arguments: 398 399 - handle - A handle with the information to parse. 400 - consumer - The consumer that should be informed of events. 401 - do_features - Boolean, should the features be parsed? 402 Skipping the features can be much faster. 403 404 Return values: 405 406 - true - Passed a record 407 - false - Did not find a record 408 """ 409 # Should work with both EMBL and GenBank files provided the 410 # equivalent Bio.GenBank._FeatureConsumer methods are called... 411 self.set_handle(handle) 412 if not self.find_start(): 413 # Could not find (another) record 414 consumer.data = None 415 return False 416 417 # We use the above class methods to parse the file into a simplified format. 418 # The first line, header lines and any misc lines after the features will be 419 # dealt with by GenBank / EMBL specific derived classes. 420 421 # First line and header: 422 self._feed_first_line(consumer, self.line) 423 self._feed_header_lines(consumer, self.parse_header()) 424 425 # Features (common to both EMBL and GenBank): 426 if do_features: 427 self._feed_feature_table(consumer, self.parse_features(skip=False)) 428 else: 429 self.parse_features(skip=True) # ignore the data 430 431 # Footer and sequence 432 misc_lines, sequence_string = self.parse_footer() 433 self._feed_misc_lines(consumer, misc_lines) 434 435 consumer.sequence(sequence_string) 436 # Calls to consumer.base_number() do nothing anyway 437 consumer.record_end("//") 438 439 assert self.line == "//" 440 441 # And we are done 442 return True
443
444 - def parse(self, handle, do_features=True):
445 """Returns a SeqRecord (with SeqFeatures if do_features=True) 446 447 See also the method parse_records() for use on multi-record files. 448 """ 449 from Bio.GenBank import _FeatureConsumer 450 from Bio.GenBank.utils import FeatureValueCleaner 451 452 consumer = _FeatureConsumer(use_fuzziness=1, 453 feature_cleaner=FeatureValueCleaner()) 454 455 if self.feed(handle, consumer, do_features): 456 return consumer.data 457 else: 458 return None
459
460 - def parse_records(self, handle, do_features=True):
461 """Returns a SeqRecord object iterator 462 463 Each record (from the ID/LOCUS line to the // line) becomes a SeqRecord 464 465 The SeqRecord objects include SeqFeatures if do_features=True 466 467 This method is intended for use in Bio.SeqIO 468 """ 469 # This is a generator function 470 while True: 471 record = self.parse(handle, do_features) 472 if record is None: 473 break 474 if record.id is None: 475 raise ValueError("Failed to parse the record's ID. Invalid ID line?") 476 if record.name == "<unknown name>": 477 raise ValueError("Failed to parse the record's name. Invalid ID line?") 478 if record.description == "<unknown description>": 479 raise ValueError("Failed to parse the record's description") 480 yield record
481
482 - def parse_cds_features(self, handle, 483 alphabet=generic_protein, 484 tags2id=('protein_id', 'locus_tag', 'product')):
485 """Returns SeqRecord object iterator 486 487 Each CDS feature becomes a SeqRecord. 488 489 - alphabet - Used for any sequence found in a translation field. 490 - tags2id - Tupple of three strings, the feature keys to use 491 for the record id, name and description, 492 493 This method is intended for use in Bio.SeqIO 494 """ 495 self.set_handle(handle) 496 while self.find_start(): 497 # Got an EMBL or GenBank record... 498 self.parse_header() # ignore header lines! 499 feature_tuples = self.parse_features() 500 # self.parse_footer() # ignore footer lines! 501 while True: 502 line = self.handle.readline() 503 if not line: 504 break 505 if line[:2] == "//": 506 break 507 self.line = line.rstrip() 508 509 # Now go though those features... 510 for key, location_string, qualifiers in feature_tuples: 511 if key == "CDS": 512 # Create SeqRecord 513 # ================ 514 # SeqRecord objects cannot be created with annotations, they 515 # must be added afterwards. So create an empty record and 516 # then populate it: 517 record = SeqRecord(seq=None) 518 annotations = record.annotations 519 520 # Should we add a location object to the annotations? 521 # I *think* that only makes sense for SeqFeatures with their 522 # sub features... 523 annotations['raw_location'] = location_string.replace(' ', '') 524 525 for (qualifier_name, qualifier_data) in qualifiers: 526 if qualifier_data is not None \ 527 and qualifier_data[0] == '"' and qualifier_data[-1] == '"': 528 # Remove quotes 529 qualifier_data = qualifier_data[1:-1] 530 # Append the data to the annotation qualifier... 531 if qualifier_name == "translation": 532 assert record.seq is None, "Multiple translations!" 533 record.seq = Seq(qualifier_data.replace("\n", ""), alphabet) 534 elif qualifier_name == "db_xref": 535 # its a list, possibly empty. Its safe to extend 536 record.dbxrefs.append(qualifier_data) 537 else: 538 if qualifier_data is not None: 539 qualifier_data = qualifier_data.replace("\n", " ").replace(" ", " ") 540 try: 541 annotations[qualifier_name] += " " + qualifier_data 542 except KeyError: 543 # Not an addition to existing data, its the first bit 544 annotations[qualifier_name] = qualifier_data 545 546 # Fill in the ID, Name, Description 547 # ================================= 548 try: 549 record.id = annotations[tags2id[0]] 550 except KeyError: 551 pass 552 try: 553 record.name = annotations[tags2id[1]] 554 except KeyError: 555 pass 556 try: 557 record.description = annotations[tags2id[2]] 558 except KeyError: 559 pass 560 561 yield record
562 563
564 -class EmblScanner(InsdcScanner):
565 """For extracting chunks of information in EMBL files""" 566 567 RECORD_START = "ID " 568 HEADER_WIDTH = 5 569 FEATURE_START_MARKERS = ["FH Key Location/Qualifiers", "FH"] 570 FEATURE_END_MARKERS = ["XX"] # XX can also mark the end of many things! 571 FEATURE_QUALIFIER_INDENT = 21 572 FEATURE_QUALIFIER_SPACER = "FT" + " " * (FEATURE_QUALIFIER_INDENT - 2) 573 SEQUENCE_HEADERS = ["SQ", "CO"] # Remove trailing spaces 574 609
610 - def _feed_first_line(self, consumer, line):
611 assert line[:self.HEADER_WIDTH].rstrip() == "ID" 612 if line[self.HEADER_WIDTH:].count(";") == 6: 613 # Looks like the semi colon separated style introduced in 2006 614 self._feed_first_line_new(consumer, line) 615 elif line[self.HEADER_WIDTH:].count(";") == 3: 616 if line.rstrip().endswith(" SQ"): 617 # EMBL-bank patent data 618 self._feed_first_line_patents(consumer, line) 619 else: 620 # Looks like the pre 2006 style 621 self._feed_first_line_old(consumer, line) 622 else: 623 raise ValueError('Did not recognise the ID line layout:\n' + line)
624
625 - def _feed_first_line_patents(self, consumer, line):
626 # Either Non-Redundant Level 1 database records, 627 # ID <accession>; <molecule type>; <non-redundant level 1>; <cluster size L1> 628 # e.g. ID NRP_AX000635; PRT; NR1; 15 SQ 629 # 630 # Or, Non-Redundant Level 2 database records: 631 # ID <L2-accession>; <molecule type>; <non-redundant level 2>; <cluster size L2> 632 # e.g. ID NRP0000016E; PRT; NR2; 5 SQ 633 fields = line[self.HEADER_WIDTH:].rstrip()[:-3].split(";") 634 assert len(fields) == 4 635 consumer.locus(fields[0]) 636 consumer.residue_type(fields[1]) 637 consumer.data_file_division(fields[2])
638 # TODO - Record cluster size? 639
640 - def _feed_first_line_old(self, consumer, line):
641 # Expects an ID line in the style before 2006, e.g. 642 # ID SC10H5 standard; DNA; PRO; 4870 BP. 643 # ID BSUB9999 standard; circular DNA; PRO; 4214630 BP. 644 assert line[:self.HEADER_WIDTH].rstrip() == "ID" 645 fields = [line[self.HEADER_WIDTH:].split(None, 1)[0]] 646 fields.extend(line[self.HEADER_WIDTH:].split(None, 1)[1].split(";")) 647 fields = [entry.strip() for entry in fields] 648 """ 649 The tokens represent: 650 651 0. Primary accession number 652 (space sep) 653 1. ??? (e.g. standard) 654 (semi-colon) 655 2. Topology and/or Molecule type (e.g. 'circular DNA' or 'DNA') 656 3. Taxonomic division (e.g. 'PRO') 657 4. Sequence length (e.g. '4639675 BP.') 658 """ 659 consumer.locus(fields[0]) # Should we also call the accession consumer? 660 consumer.residue_type(fields[2]) 661 consumer.data_file_division(fields[3]) 662 self._feed_seq_length(consumer, fields[4])
663
664 - def _feed_first_line_new(self, consumer, line):
665 # Expects an ID line in the style introduced in 2006, e.g. 666 # ID X56734; SV 1; linear; mRNA; STD; PLN; 1859 BP. 667 # ID CD789012; SV 4; linear; genomic DNA; HTG; MAM; 500 BP. 668 assert line[:self.HEADER_WIDTH].rstrip() == "ID" 669 fields = [data.strip() for data in line[self.HEADER_WIDTH:].strip().split(";")] 670 assert len(fields) == 7 671 """ 672 The tokens represent: 673 674 0. Primary accession number 675 1. Sequence version number 676 2. Topology: 'circular' or 'linear' 677 3. Molecule type (e.g. 'genomic DNA') 678 4. Data class (e.g. 'STD') 679 5. Taxonomic division (e.g. 'PRO') 680 6. Sequence length (e.g. '4639675 BP.') 681 """ 682 683 consumer.locus(fields[0]) 684 685 # Call the accession consumer now, to make sure we record 686 # something as the record.id, in case there is no AC line 687 consumer.accession(fields[0]) 688 689 # TODO - How to deal with the version field? At the moment the consumer 690 # will try and use this for the ID which isn't ideal for EMBL files. 691 version_parts = fields[1].split() 692 if len(version_parts) == 2 \ 693 and version_parts[0] == "SV" \ 694 and version_parts[1].isdigit(): 695 consumer.version_suffix(version_parts[1]) 696 697 # Based on how the old GenBank parser worked, merge these two: 698 consumer.residue_type(" ".join(fields[2:4])) # TODO - Store as two fields? 699 700 # consumer.xxx(fields[4]) # TODO - What should we do with the data class? 701 702 consumer.data_file_division(fields[5]) 703 704 self._feed_seq_length(consumer, fields[6])
705
706 - def _feed_seq_length(self, consumer, text):
707 length_parts = text.split() 708 assert len(length_parts) == 2, "Invalid sequence length string %r" % text 709 assert length_parts[1].upper() in ["BP", "BP.", "AA", "AA."] 710 consumer.size(length_parts[0])
711
712 - def _feed_header_lines(self, consumer, lines):
713 EMBL_INDENT = self.HEADER_WIDTH 714 EMBL_SPACER = " " * EMBL_INDENT 715 consumer_dict = { 716 'AC': 'accession', 717 'SV': 'version', # SV line removed in June 2006, now part of ID line 718 'DE': 'definition', 719 # 'RN' : 'reference_num', 720 # 'RC' : reference comment... TODO 721 # 'RP' : 'reference_bases', 722 # 'RX' : reference cross reference... DOI or Pubmed 723 'RG': 'consrtm', # optional consortium 724 # 'RA' : 'authors', 725 # 'RT' : 'title', 726 'RL': 'journal', 727 'OS': 'organism', 728 'OC': 'taxonomy', 729 # 'DR' : data reference 730 'CC': 'comment', 731 # 'XX' : splitter 732 } 733 # We have to handle the following specially: 734 # RX (depending on reference type...) 735 for line in lines: 736 line_type = line[:EMBL_INDENT].strip() 737 data = line[EMBL_INDENT:].strip() 738 if line_type == 'XX': 739 pass 740 elif line_type == 'RN': 741 # Reformat reference numbers for the GenBank based consumer 742 # e.g. '[1]' becomes '1' 743 if data[0] == "[" and data[-1] == "]": 744 data = data[1:-1] 745 consumer.reference_num(data) 746 elif line_type == 'RP': 747 # Reformat reference numbers for the GenBank based consumer 748 # e.g. '1-4639675' becomes '(bases 1 to 4639675)' 749 # and '160-550, 904-1055' becomes '(bases 160 to 550; 904 to 1055)' 750 # Note could be multi-line, and end with a comma 751 parts = [bases.replace("-", " to ").strip() for bases in data.split(",") if bases.strip()] 752 consumer.reference_bases("(bases %s)" % "; ".join(parts)) 753 elif line_type == 'RT': 754 # Remove the enclosing quotes and trailing semi colon. 755 # Note the title can be split over multiple lines. 756 if data.startswith('"'): 757 data = data[1:] 758 if data.endswith('";'): 759 data = data[:-2] 760 consumer.title(data) 761 elif line_type == 'RX': 762 # EMBL support three reference types at the moment: 763 # - PUBMED PUBMED bibliographic database (NLM) 764 # - DOI Digital Object Identifier (International DOI Foundation) 765 # - AGRICOLA US National Agriculture Library (NAL) of the US Department 766 # of Agriculture (USDA) 767 # 768 # Format: 769 # RX resource_identifier; identifier. 770 # 771 # e.g. 772 # RX DOI; 10.1016/0024-3205(83)90010-3. 773 # RX PUBMED; 264242. 774 # 775 # Currently our reference object only supports PUBMED and MEDLINE 776 # (as these were in GenBank files?). 777 key, value = data.split(";", 1) 778 if value.endswith("."): 779 value = value[:-1] 780 value = value.strip() 781 if key == "PUBMED": 782 consumer.pubmed_id(value) 783 # TODO - Handle other reference types (here and in BioSQL bindings) 784 elif line_type == 'CC': 785 # Have to pass a list of strings for this one (not just a string) 786 consumer.comment([data]) 787 elif line_type == 'DR': 788 # Database Cross-reference, format: 789 # DR database_identifier; primary_identifier; secondary_identifier. 790 # 791 # e.g. 792 # DR MGI; 98599; Tcrb-V4. 793 # 794 # TODO - How should we store any secondary identifier? 795 parts = data.rstrip(".").split(";") 796 # Turn it into "database_identifier:primary_identifier" to 797 # mimic the GenBank parser. e.g. "MGI:98599" 798 consumer.dblink("%s:%s" % (parts[0].strip(), 799 parts[1].strip())) 800 elif line_type == 'RA': 801 # Remove trailing ; at end of authors list 802 consumer.authors(data.rstrip(";")) 803 elif line_type == 'PR': 804 # Remove trailing ; at end of the project reference 805 # In GenBank files this corresponds to the old PROJECT 806 # line which is being replaced with the DBLINK line. 807 consumer.project(data.rstrip(";")) 808 elif line_type == 'KW': 809 consumer.keywords(data.rstrip(";")) 810 elif line_type in consumer_dict: 811 # Its a semi-automatic entry! 812 getattr(consumer, consumer_dict[line_type])(data) 813 else: 814 if self.debug: 815 print("Ignoring EMBL header line:\n%s" % line)
816
817 - def _feed_misc_lines(self, consumer, lines):
818 # TODO - Should we do something with the information on the SQ line(s)? 819 lines.append("") 820 line_iter = iter(lines) 821 try: 822 for line in line_iter: 823 if line.startswith("CO "): 824 line = line[5:].strip() 825 contig_location = line 826 while True: 827 line = next(line_iter) 828 if not line: 829 break 830 elif line.startswith("CO "): 831 # Don't need to preseve the whitespace here. 832 contig_location += line[5:].strip() 833 else: 834 raise ValueError('Expected CO (contig) continuation line, got:\n' + line) 835 consumer.contig_location(contig_location) 836 if line.startswith("SQ Sequence "): 837 # e.g. 838 # SQ Sequence 219 BP; 82 A; 48 C; 33 G; 45 T; 11 other; 839 # 840 # Or, EMBL-bank patent, e.g. 841 # SQ Sequence 465 AA; 3963407aa91d3a0d622fec679a4524e0; MD5; 842 self._feed_seq_length(consumer, line[14:].rstrip().rstrip(";").split(";", 1)[0]) 843 # TODO - Record the checksum etc? 844 return 845 except StopIteration: 846 raise ValueError("Problem in misc lines before sequence")
847 848
849 -class _ImgtScanner(EmblScanner):
850 """For extracting chunks of information in IMGT (EMBL like) files (PRIVATE). 851 852 IMGT files are like EMBL files but in order to allow longer feature types 853 the features should be indented by 25 characters not 21 characters. In 854 practice the IMGT flat files tend to use either 21 or 25 characters, so we 855 must cope with both. 856 857 This is private to encourage use of Bio.SeqIO rather than Bio.GenBank. 858 """ 859 860 FEATURE_START_MARKERS = ["FH Key Location/Qualifiers", 861 "FH Key Location/Qualifiers (from EMBL)", 862 "FH Key Location/Qualifiers", 863 "FH"] 864
865 - def parse_features(self, skip=False):
866 """Return list of tuples for the features (if present) 867 868 Each feature is returned as a tuple (key, location, qualifiers) 869 where key and location are strings (e.g. "CDS" and 870 "complement(join(490883..490885,1..879))") while qualifiers 871 is a list of two string tuples (feature qualifier keys and values). 872 873 Assumes you have already read to the start of the features table. 874 """ 875 if self.line.rstrip() not in self.FEATURE_START_MARKERS: 876 if self.debug: 877 print("Didn't find any feature table") 878 return [] 879 880 while self.line.rstrip() in self.FEATURE_START_MARKERS: 881 self.line = self.handle.readline() 882 883 bad_position_re = re.compile(r'([0-9]+)>{1}') 884 885 features = [] 886 line = self.line 887 while True: 888 if not line: 889 raise ValueError("Premature end of line during features table") 890 if line[:self.HEADER_WIDTH].rstrip() in self.SEQUENCE_HEADERS: 891 if self.debug: 892 print("Found start of sequence") 893 break 894 line = line.rstrip() 895 if line == "//": 896 raise ValueError("Premature end of features table, marker '//' found") 897 if line in self.FEATURE_END_MARKERS: 898 if self.debug: 899 print("Found end of features") 900 line = self.handle.readline() 901 break 902 if line[2:self.FEATURE_QUALIFIER_INDENT].strip() == "": 903 # This is an empty feature line between qualifiers. Empty 904 # feature lines within qualifiers are handled below (ignored). 905 line = self.handle.readline() 906 continue 907 908 if skip: 909 line = self.handle.readline() 910 while line[:self.FEATURE_QUALIFIER_INDENT] == self.FEATURE_QUALIFIER_SPACER: 911 line = self.handle.readline() 912 else: 913 assert line[:2] == "FT" 914 try: 915 feature_key, location_start = line[2:].strip().split() 916 except ValueError: 917 # e.g. "FT TRANSMEMBRANE-REGION2163..2240\n" 918 # Assume indent of 25 as per IMGT spec, with the location 919 # start in column 26 (one-based). 920 feature_key = line[2:25].strip() 921 location_start = line[25:].strip() 922 feature_lines = [location_start] 923 line = self.handle.readline() 924 while line[:self.FEATURE_QUALIFIER_INDENT] == self.FEATURE_QUALIFIER_SPACER \ 925 or line.rstrip() == "": # cope with blank lines in the midst of a feature 926 # Use strip to remove any harmless trailing white space AND and leading 927 # white space (copes with 21 or 26 indents and orther variants) 928 assert line[:2] == "FT" 929 feature_lines.append(line[self.FEATURE_QUALIFIER_INDENT:].strip()) 930 line = self.handle.readline() 931 feature_key, location, qualifiers = \ 932 self.parse_feature(feature_key, feature_lines) 933 # Try to handle known problems with IMGT locations here: 934 if ">" in location: 935 # Nasty hack for common IMGT bug, should be >123 not 123> 936 # in a location string. At least here the meaning is clear, 937 # and since it is so common I don't want to issue a warning 938 # warnings.warn("Feature location %s is invalid, " 939 # "moving greater than sign before position" 940 # % location, BiopythonParserWarning) 941 location = bad_position_re.sub(r'>\1', location) 942 features.append((feature_key, location, qualifiers)) 943 self.line = line 944 return features
945 946
947 -class GenBankScanner(InsdcScanner):
948 """For extracting chunks of information in GenBank files""" 949 950 RECORD_START = "LOCUS " 951 HEADER_WIDTH = 12 952 FEATURE_START_MARKERS = ["FEATURES Location/Qualifiers", "FEATURES"] 953 FEATURE_END_MARKERS = [] 954 FEATURE_QUALIFIER_INDENT = 21 955 FEATURE_QUALIFIER_SPACER = " " * FEATURE_QUALIFIER_INDENT 956 SEQUENCE_HEADERS = ["CONTIG", "ORIGIN", "BASE COUNT", "WGS"] # trailing spaces removed 957 1010
1011 - def _feed_first_line(self, consumer, line):
1012 """Scan over and parse GenBank LOCUS line (PRIVATE). 1013 1014 This must cope with several variants, primarily the old and new column 1015 based standards from GenBank. Additionally EnsEMBL produces GenBank 1016 files where the LOCUS line is space separated rather that following 1017 the column based layout. 1018 1019 We also try to cope with GenBank like files with partial LOCUS lines. 1020 """ 1021 ##################################### 1022 # LOCUS line # 1023 ##################################### 1024 GENBANK_INDENT = self.HEADER_WIDTH 1025 GENBANK_SPACER = " " * GENBANK_INDENT 1026 assert line[0:GENBANK_INDENT] == 'LOCUS ', \ 1027 'LOCUS line does not start correctly:\n' + line 1028 1029 # Have to break up the locus line, and handle the different bits of it. 1030 # There are at least two different versions of the locus line... 1031 if line[29:33] in [' bp ', ' aa ', ' rc '] and line[55:62] == ' ': 1032 # Old... note we insist on the 55:62 being empty to avoid trying 1033 # to parse space separated LOCUS lines from Ensembl etc, see below. 1034 # 1035 # Positions Contents 1036 # --------- -------- 1037 # 00:06 LOCUS 1038 # 06:12 spaces 1039 # 12:?? Locus name 1040 # ??:?? space 1041 # ??:29 Length of sequence, right-justified 1042 # 29:33 space, bp, space 1043 # 33:41 strand type 1044 # 41:42 space 1045 # 42:51 Blank (implies linear), linear or circular 1046 # 51:52 space 1047 # 52:55 The division code (e.g. BCT, VRL, INV) 1048 # 55:62 space 1049 # 62:73 Date, in the form dd-MMM-yyyy (e.g., 15-MAR-1991) 1050 # 1051 # assert line[29:33] in [' bp ', ' aa ',' rc '] , \ 1052 # 'LOCUS line does not contain size units at expected position:\n' + line 1053 assert line[41:42] == ' ', \ 1054 'LOCUS line does not contain space at position 42:\n' + line 1055 assert line[42:51].strip() in ['', 'linear', 'circular'], \ 1056 'LOCUS line does not contain valid entry (linear, circular, ...):\n' + line 1057 assert line[51:52] == ' ', \ 1058 'LOCUS line does not contain space at position 52:\n' + line 1059 # assert line[55:62] == ' ', \ 1060 # 'LOCUS line does not contain spaces from position 56 to 62:\n' + line 1061 if line[62:73].strip(): 1062 assert line[64:65] == '-', \ 1063 'LOCUS line does not contain - at position 65 in date:\n' + line 1064 assert line[68:69] == '-', \ 1065 'LOCUS line does not contain - at position 69 in date:\n' + line 1066 1067 name_and_length_str = line[GENBANK_INDENT:29] 1068 while ' ' in name_and_length_str: 1069 name_and_length_str = name_and_length_str.replace(' ', ' ') 1070 name_and_length = name_and_length_str.split(' ') 1071 assert len(name_and_length) <= 2, \ 1072 'Cannot parse the name and length in the LOCUS line:\n' + line 1073 assert len(name_and_length) != 1, \ 1074 'Name and length collide in the LOCUS line:\n' + line 1075 # Should be possible to split them based on position, if 1076 # a clear definition of the standard exists THAT AGREES with 1077 # existing files. 1078 consumer.locus(name_and_length[0]) 1079 consumer.size(name_and_length[1]) 1080 # consumer.residue_type(line[33:41].strip()) 1081 1082 if line[33:51].strip() == "" and line[29:33] == ' aa ': 1083 # Amino acids -> protein (even if there is no residue type given) 1084 # We want to use a protein alphabet in this case, rather than a 1085 # generic one. Not sure if this is the best way to achieve this, 1086 # but it works because the scanner checks for this: 1087 consumer.residue_type("PROTEIN") 1088 else: 1089 consumer.residue_type(line[33:51].strip()) 1090 1091 consumer.data_file_division(line[52:55]) 1092 if line[62:73].strip(): 1093 consumer.date(line[62:73]) 1094 elif line[40:44] in [' bp ', ' aa ', ' rc '] \ 1095 and line[54:64].strip() in ['', 'linear', 'circular']: 1096 # New... linear/circular/big blank test should avoid EnsEMBL style 1097 # LOCUS line being treated like a proper column based LOCUS line. 1098 # 1099 # Positions Contents 1100 # --------- -------- 1101 # 00:06 LOCUS 1102 # 06:12 spaces 1103 # 12:?? Locus name 1104 # ??:?? space 1105 # ??:40 Length of sequence, right-justified 1106 # 40:44 space, bp, space 1107 # 44:47 Blank, ss-, ds-, ms- 1108 # 47:54 Blank, DNA, RNA, tRNA, mRNA, uRNA, snRNA, cDNA 1109 # 54:55 space 1110 # 55:63 Blank (implies linear), linear or circular 1111 # 63:64 space 1112 # 64:67 The division code (e.g. BCT, VRL, INV) 1113 # 67:68 space 1114 # 68:79 Date, in the form dd-MMM-yyyy (e.g., 15-MAR-1991) 1115 # 1116 assert line[40:44] in [' bp ', ' aa ', ' rc '], \ 1117 'LOCUS line does not contain size units at expected position:\n' + line 1118 assert line[44:47] in [' ', 'ss-', 'ds-', 'ms-'], \ 1119 'LOCUS line does not have valid strand type (Single stranded, ...):\n' + line 1120 assert line[47:54].strip() == "" \ 1121 or 'DNA' in line[47:54].strip().upper() \ 1122 or 'RNA' in line[47:54].strip().upper(), \ 1123 'LOCUS line does not contain valid sequence type (DNA, RNA, ...):\n' + line 1124 assert line[54:55] == ' ', \ 1125 'LOCUS line does not contain space at position 55:\n' + line 1126 assert line[55:63].strip() in ['', 'linear', 'circular'], \ 1127 'LOCUS line does not contain valid entry (linear, circular, ...):\n' + line 1128 assert line[63:64] == ' ', \ 1129 'LOCUS line does not contain space at position 64:\n' + line 1130 assert line[67:68] == ' ', \ 1131 'LOCUS line does not contain space at position 68:\n' + line 1132 if line[68:79].strip(): 1133 assert line[70:71] == '-', \ 1134 'LOCUS line does not contain - at position 71 in date:\n' + line 1135 assert line[74:75] == '-', \ 1136 'LOCUS line does not contain - at position 75 in date:\n' + line 1137 1138 name_and_length_str = line[GENBANK_INDENT:40] 1139 while ' ' in name_and_length_str: 1140 name_and_length_str = name_and_length_str.replace(' ', ' ') 1141 name_and_length = name_and_length_str.split(' ') 1142 assert len(name_and_length) <= 2, \ 1143 'Cannot parse the name and length in the LOCUS line:\n' + line 1144 assert len(name_and_length) != 1, \ 1145 'Name and length collide in the LOCUS line:\n' + line 1146 # Should be possible to split them based on position, if 1147 # a clear definition of the stand exists THAT AGREES with 1148 # existing files. 1149 consumer.locus(name_and_length[0]) 1150 consumer.size(name_and_length[1]) 1151 1152 if line[44:54].strip() == "" and line[40:44] == ' aa ': 1153 # Amino acids -> protein (even if there is no residue type given) 1154 # We want to use a protein alphabet in this case, rather than a 1155 # generic one. Not sure if this is the best way to achieve this, 1156 # but it works because the scanner checks for this: 1157 consumer.residue_type(("PROTEIN " + line[54:63]).strip()) 1158 else: 1159 consumer.residue_type(line[44:63].strip()) 1160 1161 consumer.data_file_division(line[64:67]) 1162 if line[68:79].strip(): 1163 consumer.date(line[68:79]) 1164 elif line[GENBANK_INDENT:].strip().count(" ") == 0: 1165 # Truncated LOCUS line, as produced by some EMBOSS tools - see bug 1762 1166 # 1167 # e.g. 1168 # 1169 # "LOCUS U00096" 1170 # 1171 # rather than: 1172 # 1173 # "LOCUS U00096 4639675 bp DNA circular BCT" 1174 # 1175 # Positions Contents 1176 # --------- -------- 1177 # 00:06 LOCUS 1178 # 06:12 spaces 1179 # 12:?? Locus name 1180 if line[GENBANK_INDENT:].strip() != "": 1181 consumer.locus(line[GENBANK_INDENT:].strip()) 1182 else: 1183 # Must just have just "LOCUS ", is this even legitimate? 1184 # We should be able to continue parsing... we need real world testcases! 1185 warnings.warn("Minimal LOCUS line found - is this " 1186 "correct?\n:%r" % line, BiopythonParserWarning) 1187 elif len(line.split()) == 8 and line.split()[3] in ("aa", "bp") and \ 1188 line.split()[5] in ('linear', 'circular'): 1189 # Cope with invalidly spaced GenBank LOCUS lines like 1190 # LOCUS AB070938 6497 bp DNA linear BCT 11-OCT-2001 1191 splitline = line.split() 1192 consumer.locus(splitline[1]) 1193 consumer.size(splitline[2]) 1194 consumer.residue_type(splitline[4]) 1195 consumer.data_file_division(splitline[6]) 1196 consumer.date(splitline[7]) 1197 warnings.warn("Attempting to parse malformed locus line:\n%r\n" 1198 "Found locus %r size %r residue_type %r\n" 1199 "Some fields may be wrong." % (line, splitline[1], 1200 splitline[2], splitline[4]), BiopythonParserWarning) 1201 elif len(line.split()) == 7 and line.split()[3] in ["aa", "bp"]: 1202 # Cope with EnsEMBL genbank files which use space separation rather 1203 # than the expected column based layout. e.g. 1204 # LOCUS HG531_PATCH 1000000 bp DNA HTG 18-JUN-2011 1205 # LOCUS HG531_PATCH 759984 bp DNA HTG 18-JUN-2011 1206 # LOCUS HG506_HG1000_1_PATCH 814959 bp DNA HTG 18-JUN-2011 1207 # LOCUS HG506_HG1000_1_PATCH 1219964 bp DNA HTG 18-JUN-2011 1208 # Notice that the 'bp' can occur in the position expected by either 1209 # the old or the new fixed column standards (parsed above). 1210 splitline = line.split() 1211 consumer.locus(splitline[1]) 1212 consumer.size(splitline[2]) 1213 consumer.residue_type(splitline[4]) 1214 consumer.data_file_division(splitline[5]) 1215 consumer.date(splitline[6]) 1216 elif len(line.split()) >= 4 and line.split()[3] in ["aa", "bp"]: 1217 # Cope with EMBOSS seqret output where it seems the locus id can cause 1218 # the other fields to overflow. We just IGNORE the other fields! 1219 warnings.warn("Malformed LOCUS line found - is this " 1220 "correct?\n:%r" % line, BiopythonParserWarning) 1221 consumer.locus(line.split()[1]) 1222 consumer.size(line.split()[2]) 1223 elif len(line.split()) >= 4 and line.split()[-1] in ["aa", "bp"]: 1224 # Cope with pseudo-GenBank files like this: 1225 # "LOCUS RNA5 complete 1718 bp" 1226 # Treat everything between LOCUS and the size as the identifier. 1227 warnings.warn("Malformed LOCUS line found - is this " 1228 "correct?\n:%r" % line, BiopythonParserWarning) 1229 consumer.locus(line[5:].rsplit(None, 2)[0].strip()) 1230 consumer.size(line.split()[-2]) 1231 else: 1232 raise ValueError('Did not recognise the LOCUS line layout:\n' + line)
1233
1234 - def _feed_header_lines(self, consumer, lines):
1235 # Following dictionary maps GenBank lines to the associated 1236 # consumer methods - the special cases like LOCUS where one 1237 # genbank line triggers several consumer calls have to be 1238 # handled individually. 1239 GENBANK_INDENT = self.HEADER_WIDTH 1240 GENBANK_SPACER = " " * GENBANK_INDENT 1241 consumer_dict = { 1242 'DEFINITION': 'definition', 1243 'ACCESSION': 'accession', 1244 'NID': 'nid', 1245 'PID': 'pid', 1246 'DBSOURCE': 'db_source', 1247 'KEYWORDS': 'keywords', 1248 'SEGMENT': 'segment', 1249 'SOURCE': 'source', 1250 'AUTHORS': 'authors', 1251 'CONSRTM': 'consrtm', 1252 'PROJECT': 'project', 1253 'DBLINK': 'dblink', 1254 'TITLE': 'title', 1255 'JOURNAL': 'journal', 1256 'MEDLINE': 'medline_id', 1257 'PUBMED': 'pubmed_id', 1258 'REMARK': 'remark'} 1259 # We have to handle the following specially: 1260 # ORIGIN (locus, size, residue_type, data_file_division and date) 1261 # COMMENT (comment) 1262 # VERSION (version and gi) 1263 # REFERENCE (eference_num and reference_bases) 1264 # ORGANISM (organism and taxonomy) 1265 lines = [_f for _f in lines if _f] 1266 lines.append("") # helps avoid getting StopIteration all the time 1267 line_iter = iter(lines) 1268 try: 1269 line = next(line_iter) 1270 while True: 1271 if not line: 1272 break 1273 line_type = line[:GENBANK_INDENT].strip() 1274 data = line[GENBANK_INDENT:].strip() 1275 1276 if line_type == 'VERSION': 1277 # Need to call consumer.version(), and maybe also consumer.gi() as well. 1278 # e.g. 1279 # VERSION AC007323.5 GI:6587720 1280 while ' ' in data: 1281 data = data.replace(' ', ' ') 1282 if ' GI:' not in data: 1283 consumer.version(data) 1284 else: 1285 if self.debug: 1286 print("Version [" + data.split(' GI:')[0] + "], gi [" + data.split(' GI:')[1] + "]") 1287 consumer.version(data.split(' GI:')[0]) 1288 consumer.gi(data.split(' GI:')[1]) 1289 # Read in the next line! 1290 line = next(line_iter) 1291 elif line_type == 'REFERENCE': 1292 if self.debug > 1: 1293 print("Found reference [" + data + "]") 1294 # Need to call consumer.reference_num() and consumer.reference_bases() 1295 # e.g. 1296 # REFERENCE 1 (bases 1 to 86436) 1297 # 1298 # Note that this can be multiline, see Bug 1968, e.g. 1299 # 1300 # REFERENCE 42 (bases 1517 to 1696; 3932 to 4112; 17880 to 17975; 21142 to 1301 # 28259) 1302 # 1303 # For such cases we will call the consumer once only. 1304 data = data.strip() 1305 1306 # Read in the next line, and see if its more of the reference: 1307 while True: 1308 line = next(line_iter) 1309 if line[:GENBANK_INDENT] == GENBANK_SPACER: 1310 # Add this continuation to the data string 1311 data += " " + line[GENBANK_INDENT:] 1312 if self.debug > 1: 1313 print("Extended reference text [" + data + "]") 1314 else: 1315 # End of the reference, leave this text in the variable "line" 1316 break 1317 1318 # We now have all the reference line(s) stored in a string, data, 1319 # which we pass to the consumer 1320 while ' ' in data: 1321 data = data.replace(' ', ' ') 1322 if ' ' not in data: 1323 if self.debug > 2: 1324 print('Reference number \"' + data + '\"') 1325 consumer.reference_num(data) 1326 else: 1327 if self.debug > 2: 1328 print('Reference number \"' + data[:data.find(' ')] + '\", \"' + data[data.find(' ') + 1:] + '\"') 1329 consumer.reference_num(data[:data.find(' ')]) 1330 consumer.reference_bases(data[data.find(' ') + 1:]) 1331 elif line_type == 'ORGANISM': 1332 # Typically the first line is the organism, and subsequent lines 1333 # are the taxonomy lineage. However, given longer and longer 1334 # species names (as more and more strains and sub strains get 1335 # sequenced) the oragnism name can now get wrapped onto multiple 1336 # lines. The NCBI say we have to recognise the lineage line by 1337 # the presence of semi-colon delimited entries. In the long term, 1338 # they are considering adding a new keyword (e.g. LINEAGE). 1339 # See Bug 2591 for details. 1340 organism_data = data 1341 lineage_data = "" 1342 while True: 1343 line = next(line_iter) 1344 if line[0:GENBANK_INDENT] == GENBANK_SPACER: 1345 if lineage_data or ";" in line: 1346 lineage_data += " " + line[GENBANK_INDENT:] 1347 else: 1348 organism_data += " " + line[GENBANK_INDENT:].strip() 1349 else: 1350 # End of organism and taxonomy 1351 break 1352 consumer.organism(organism_data) 1353 if lineage_data.strip() == "" and self.debug > 1: 1354 print("Taxonomy line(s) missing or blank") 1355 consumer.taxonomy(lineage_data.strip()) 1356 del organism_data, lineage_data 1357 elif line_type == 'COMMENT': 1358 if self.debug > 1: 1359 print("Found comment") 1360 # This can be multiline, and should call consumer.comment() once 1361 # with a list where each entry is a line. 1362 comment_list = [] 1363 comment_list.append(data) 1364 while True: 1365 line = next(line_iter) 1366 if line[0:GENBANK_INDENT] == GENBANK_SPACER: 1367 data = line[GENBANK_INDENT:] 1368 comment_list.append(data) 1369 if self.debug > 2: 1370 print("Comment continuation [" + data + "]") 1371 else: 1372 # End of the comment 1373 break 1374 consumer.comment(comment_list) 1375 del comment_list 1376 elif line_type in consumer_dict: 1377 # Its a semi-automatic entry! 1378 # Now, this may be a multi line entry... 1379 while True: 1380 line = next(line_iter) 1381 if line[0:GENBANK_INDENT] == GENBANK_SPACER: 1382 data += ' ' + line[GENBANK_INDENT:] 1383 else: 1384 # We now have all the data for this entry: 1385 getattr(consumer, consumer_dict[line_type])(data) 1386 # End of continuation - return to top of loop! 1387 break 1388 else: 1389 if self.debug: 1390 print("Ignoring GenBank header line:\n" % line) 1391 # Read in next line 1392 line = next(line_iter) 1393 except StopIteration: 1394 raise ValueError("Problem in header")
1395
1396 - def _feed_misc_lines(self, consumer, lines):
1397 # Deals with a few misc lines between the features and the sequence 1398 GENBANK_INDENT = self.HEADER_WIDTH 1399 GENBANK_SPACER = " " * GENBANK_INDENT 1400 lines.append("") 1401 line_iter = iter(lines) 1402 try: 1403 for line in line_iter: 1404 if line.startswith('BASE COUNT'): 1405 line = line[10:].strip() 1406 if line: 1407 if self.debug: 1408 print("base_count = " + line) 1409 consumer.base_count(line) 1410 if line.startswith('ORIGIN'): 1411 line = line[6:].strip() 1412 if line: 1413 if self.debug: 1414 print("origin_name = " + line) 1415 consumer.origin_name(line) 1416 if line.startswith('WGS '): 1417 line = line[3:].strip() 1418 consumer.wgs(line) 1419 if line.startswith('WGS_SCAFLD'): 1420 line = line[10:].strip() 1421 consumer.add_wgs_scafld(line) 1422 if line.startswith('CONTIG'): 1423 line = line[6:].strip() 1424 contig_location = line 1425 while True: 1426 line = next(line_iter) 1427 if not line: 1428 break 1429 elif line[:GENBANK_INDENT] == GENBANK_SPACER: 1430 # Don't need to preseve the whitespace here. 1431 contig_location += line[GENBANK_INDENT:].rstrip() 1432 elif line.startswith('ORIGIN'): 1433 # Strange, seen this in GenPept files via Entrez gbwithparts 1434 line = line[6:].strip() 1435 if line: 1436 consumer.origin_name(line) 1437 break 1438 else: 1439 raise ValueError('Expected CONTIG continuation line, got:\n' + line) 1440 consumer.contig_location(contig_location) 1441 return 1442 except StopIteration: 1443 raise ValueError("Problem in misc lines before sequence")
1444 1445 if __name__ == "__main__": 1446 from Bio._py3k import StringIO 1447 1448 gbk_example = \ 1449 """LOCUS SCU49845 5028 bp DNA PLN 21-JUN-1999 1450 DEFINITION Saccharomyces cerevisiae TCP1-beta gene, partial cds, and Axl2p 1451 (AXL2) and Rev7p (REV7) genes, complete cds. 1452 ACCESSION U49845 1453 VERSION U49845.1 GI:1293613 1454 KEYWORDS . 1455 SOURCE Saccharomyces cerevisiae (baker's yeast) 1456 ORGANISM Saccharomyces cerevisiae 1457 Eukaryota; Fungi; Ascomycota; Saccharomycotina; Saccharomycetes; 1458 Saccharomycetales; Saccharomycetaceae; Saccharomyces. 1459 REFERENCE 1 (bases 1 to 5028) 1460 AUTHORS Torpey,L.E., Gibbs,P.E., Nelson,J. and Lawrence,C.W. 1461 TITLE Cloning and sequence of REV7, a gene whose function is required for 1462 DNA damage-induced mutagenesis in Saccharomyces cerevisiae 1463 JOURNAL Yeast 10 (11), 1503-1509 (1994) 1464 PUBMED 7871890 1465 REFERENCE 2 (bases 1 to 5028) 1466 AUTHORS Roemer,T., Madden,K., Chang,J. and Snyder,M. 1467 TITLE Selection of axial growth sites in yeast requires Axl2p, a novel 1468 plasma membrane glycoprotein 1469 JOURNAL Genes Dev. 10 (7), 777-793 (1996) 1470 PUBMED 8846915 1471 REFERENCE 3 (bases 1 to 5028) 1472 AUTHORS Roemer,T. 1473 TITLE Direct Submission 1474 JOURNAL Submitted (22-FEB-1996) Terry Roemer, Biology, Yale University, New 1475 Haven, CT, USA 1476 FEATURES Location/Qualifiers 1477 source 1..5028 1478 /organism="Saccharomyces cerevisiae" 1479 /db_xref="taxon:4932" 1480 /chromosome="IX" 1481 /map="9" 1482 CDS <1..206 1483 /codon_start=3 1484 /product="TCP1-beta" 1485 /protein_id="AAA98665.1" 1486 /db_xref="GI:1293614" 1487 /translation="SSIYNGISTSGLDLNNGTIADMRQLGIVESYKLKRAVVSSASEA 1488 AEVLLRVDNIIRARPRTANRQHM" 1489 gene 687..3158 1490 /gene="AXL2" 1491 CDS 687..3158 1492 /gene="AXL2" 1493 /note="plasma membrane glycoprotein" 1494 /codon_start=1 1495 /function="required for axial budding pattern of S. 1496 cerevisiae" 1497 /product="Axl2p" 1498 /protein_id="AAA98666.1" 1499 /db_xref="GI:1293615" 1500 /translation="MTQLQISLLLTATISLLHLVVATPYEAYPIGKQYPPVARVNESF 1501 TFQISNDTYKSSVDKTAQITYNCFDLPSWLSFDSSSRTFSGEPSSDLLSDANTTLYFN 1502 VILEGTDSADSTSLNNTYQFVVTNRPSISLSSDFNLLALLKNYGYTNGKNALKLDPNE 1503 VFNVTFDRSMFTNEESIVSYYGRSQLYNAPLPNWLFFDSGELKFTGTAPVINSAIAPE 1504 TSYSFVIIATDIEGFSAVEVEFELVIGAHQLTTSIQNSLIINVTDTGNVSYDLPLNYV 1505 YLDDDPISSDKLGSINLLDAPDWVALDNATISGSVPDELLGKNSNPANFSVSIYDTYG 1506 DVIYFNFEVVSTTDLFAISSLPNINATRGEWFSYYFLPSQFTDYVNTNVSLEFTNSSQ 1507 DHDWVKFQSSNLTLAGEVPKNFDKLSLGLKANQGSQSQELYFNIIGMDSKITHSNHSA 1508 NATSTRSSHHSTSTSSYTSSTYTAKISSTSAAATSSAPAALPAANKTSSHNKKAVAIA 1509 CGVAIPLGVILVALICFLIFWRRRRENPDDENLPHAISGPDLNNPANKPNQENATPLN 1510 NPFDDDASSYDDTSIARRLAALNTLKLDNHSATESDISSVDEKRDSLSGMNTYNDQFQ 1511 SQSKEELLAKPPVQPPESPFFDPQNRSSSVYMDSEPAVNKSWRYTGNLSPVSDIVRDS 1512 YGSQKTVDTEKLFDLEAPEKEKRTSRDVTMSSLDPWNSNISPSPVRKSVTPSPYNVTK 1513 HRNRHLQNIQDSQSGKNGITPTTMSTSSSDDFVPVKDGENFCWVHSMEPDRRPSKKRL 1514 VDFSNKSNVNVGQVKDIHGRIPEML" 1515 gene complement(3300..4037) 1516 /gene="REV7" 1517 CDS complement(3300..4037) 1518 /gene="REV7" 1519 /codon_start=1 1520 /product="Rev7p" 1521 /protein_id="AAA98667.1" 1522 /db_xref="GI:1293616" 1523 /translation="MNRWVEKWLRVYLKCYINLILFYRNVYPPQSFDYTTYQSFNLPQ 1524 FVPINRHPALIDYIEELILDVLSKLTHVYRFSICIINKKNDLCIEKYVLDFSELQHVD 1525 KDDQIITETEVFDEFRSSLNSLIMHLEKLPKVNDDTITFEAVINAIELELGHKLDRNR 1526 RVDSLEEKAEIERDSNWVKCQEDENLPDNNGFQPPKIKLTSLVGSDVGPLIIHQFSEK 1527 LISGDDKILNGVYSQYEEGESIFGSLF" 1528 ORIGIN 1529 1 gatcctccat atacaacggt atctccacct caggtttaga tctcaacaac ggaaccattg 1530 61 ccgacatgag acagttaggt atcgtcgaga gttacaagct aaaacgagca gtagtcagct 1531 121 ctgcatctga agccgctgaa gttctactaa gggtggataa catcatccgt gcaagaccaa 1532 181 gaaccgccaa tagacaacat atgtaacata tttaggatat acctcgaaaa taataaaccg 1533 241 ccacactgtc attattataa ttagaaacag aacgcaaaaa ttatccacta tataattcaa 1534 301 agacgcgaaa aaaaaagaac aacgcgtcat agaacttttg gcaattcgcg tcacaaataa 1535 361 attttggcaa cttatgtttc ctcttcgagc agtactcgag ccctgtctca agaatgtaat 1536 421 aatacccatc gtaggtatgg ttaaagatag catctccaca acctcaaagc tccttgccga 1537 481 gagtcgccct cctttgtcga gtaattttca cttttcatat gagaacttat tttcttattc 1538 541 tttactctca catcctgtag tgattgacac tgcaacagcc accatcacta gaagaacaga 1539 601 acaattactt aatagaaaaa ttatatcttc ctcgaaacga tttcctgctt ccaacatcta 1540 661 cgtatatcaa gaagcattca cttaccatga cacagcttca gatttcatta ttgctgacag 1541 721 ctactatatc actactccat ctagtagtgg ccacgcccta tgaggcatat cctatcggaa 1542 781 aacaataccc cccagtggca agagtcaatg aatcgtttac atttcaaatt tccaatgata 1543 841 cctataaatc gtctgtagac aagacagctc aaataacata caattgcttc gacttaccga 1544 901 gctggctttc gtttgactct agttctagaa cgttctcagg tgaaccttct tctgacttac 1545 961 tatctgatgc gaacaccacg ttgtatttca atgtaatact cgagggtacg gactctgccg 1546 1021 acagcacgtc tttgaacaat acataccaat ttgttgttac aaaccgtcca tccatctcgc 1547 1081 tatcgtcaga tttcaatcta ttggcgttgt taaaaaacta tggttatact aacggcaaaa 1548 1141 acgctctgaa actagatcct aatgaagtct tcaacgtgac ttttgaccgt tcaatgttca 1549 1201 ctaacgaaga atccattgtg tcgtattacg gacgttctca gttgtataat gcgccgttac 1550 1261 ccaattggct gttcttcgat tctggcgagt tgaagtttac tgggacggca ccggtgataa 1551 1321 actcggcgat tgctccagaa acaagctaca gttttgtcat catcgctaca gacattgaag 1552 1381 gattttctgc cgttgaggta gaattcgaat tagtcatcgg ggctcaccag ttaactacct 1553 1441 ctattcaaaa tagtttgata atcaacgtta ctgacacagg taacgtttca tatgacttac 1554 1501 ctctaaacta tgtttatctc gatgacgatc ctatttcttc tgataaattg ggttctataa 1555 1561 acttattgga tgctccagac tgggtggcat tagataatgc taccatttcc gggtctgtcc 1556 1621 cagatgaatt actcggtaag aactccaatc ctgccaattt ttctgtgtcc atttatgata 1557 1681 cttatggtga tgtgatttat ttcaacttcg aagttgtctc cacaacggat ttgtttgcca 1558 1741 ttagttctct tcccaatatt aacgctacaa ggggtgaatg gttctcctac tattttttgc 1559 1801 cttctcagtt tacagactac gtgaatacaa acgtttcatt agagtttact aattcaagcc 1560 1861 aagaccatga ctgggtgaaa ttccaatcat ctaatttaac attagctgga gaagtgccca 1561 1921 agaatttcga caagctttca ttaggtttga aagcgaacca aggttcacaa tctcaagagc 1562 1981 tatattttaa catcattggc atggattcaa agataactca ctcaaaccac agtgcgaatg 1563 2041 caacgtccac aagaagttct caccactcca cctcaacaag ttcttacaca tcttctactt 1564 2101 acactgcaaa aatttcttct acctccgctg ctgctacttc ttctgctcca gcagcgctgc 1565 2161 cagcagccaa taaaacttca tctcacaata aaaaagcagt agcaattgcg tgcggtgttg 1566 2221 ctatcccatt aggcgttatc ctagtagctc tcatttgctt cctaatattc tggagacgca 1567 2281 gaagggaaaa tccagacgat gaaaacttac cgcatgctat tagtggacct gatttgaata 1568 2341 atcctgcaaa taaaccaaat caagaaaacg ctacaccttt gaacaacccc tttgatgatg 1569 2401 atgcttcctc gtacgatgat acttcaatag caagaagatt ggctgctttg aacactttga 1570 2461 aattggataa ccactctgcc actgaatctg atatttccag cgtggatgaa aagagagatt 1571 2521 ctctatcagg tatgaataca tacaatgatc agttccaatc ccaaagtaaa gaagaattat 1572 2581 tagcaaaacc cccagtacag cctccagaga gcccgttctt tgacccacag aataggtctt 1573 2641 cttctgtgta tatggatagt gaaccagcag taaataaatc ctggcgatat actggcaacc 1574 2701 tgtcaccagt ctctgatatt gtcagagaca gttacggatc acaaaaaact gttgatacag 1575 2761 aaaaactttt cgatttagaa gcaccagaga aggaaaaacg tacgtcaagg gatgtcacta 1576 2821 tgtcttcact ggacccttgg aacagcaata ttagcccttc tcccgtaaga aaatcagtaa 1577 2881 caccatcacc atataacgta acgaagcatc gtaaccgcca cttacaaaat attcaagact 1578 2941 ctcaaagcgg taaaaacgga atcactccca caacaatgtc aacttcatct tctgacgatt 1579 3001 ttgttccggt taaagatggt gaaaattttt gctgggtcca tagcatggaa ccagacagaa 1580 3061 gaccaagtaa gaaaaggtta gtagattttt caaataagag taatgtcaat gttggtcaag 1581 3121 ttaaggacat tcacggacgc atcccagaaa tgctgtgatt atacgcaacg atattttgct 1582 3181 taattttatt ttcctgtttt attttttatt agtggtttac agatacccta tattttattt 1583 3241 agtttttata cttagagaca tttaatttta attccattct tcaaatttca tttttgcact 1584 3301 taaaacaaag atccaaaaat gctctcgccc tcttcatatt gagaatacac tccattcaaa 1585 3361 attttgtcgt caccgctgat taatttttca ctaaactgat gaataatcaa aggccccacg 1586 3421 tcagaaccga ctaaagaagt gagttttatt ttaggaggtt gaaaaccatt attgtctggt 1587 3481 aaattttcat cttcttgaca tttaacccag tttgaatccc tttcaatttc tgctttttcc 1588 3541 tccaaactat cgaccctcct gtttctgtcc aacttatgtc ctagttccaa ttcgatcgca 1589 3601 ttaataactg cttcaaatgt tattgtgtca tcgttgactt taggtaattt ctccaaatgc 1590 3661 ataatcaaac tatttaagga agatcggaat tcgtcgaaca cttcagtttc cgtaatgatc 1591 3721 tgatcgtctt tatccacatg ttgtaattca ctaaaatcta aaacgtattt ttcaatgcat 1592 3781 aaatcgttct ttttattaat aatgcagatg gaaaatctgt aaacgtgcgt taatttagaa 1593 3841 agaacatcca gtataagttc ttctatatag tcaattaaag caggatgcct attaatggga 1594 3901 acgaactgcg gcaagttgaa tgactggtaa gtagtgtagt cgaatgactg aggtgggtat 1595 3961 acatttctat aaaataaaat caaattaatg tagcatttta agtataccct cagccacttc 1596 4021 tctacccatc tattcataaa gctgacgcaa cgattactat tttttttttc ttcttggatc 1597 4081 tcagtcgtcg caaaaacgta taccttcttt ttccgacctt ttttttagct ttctggaaaa 1598 4141 gtttatatta gttaaacagg gtctagtctt agtgtgaaag ctagtggttt cgattgactg 1599 4201 atattaagaa agtggaaatt aaattagtag tgtagacgta tatgcatatg tatttctcgc 1600 4261 ctgtttatgt ttctacgtac ttttgattta tagcaagggg aaaagaaata catactattt 1601 4321 tttggtaaag gtgaaagcat aatgtaaaag ctagaataaa atggacgaaa taaagagagg 1602 4381 cttagttcat cttttttcca aaaagcaccc aatgataata actaaaatga aaaggatttg 1603 4441 ccatctgtca gcaacatcag ttgtgtgagc aataataaaa tcatcacctc cgttgccttt 1604 4501 agcgcgtttg tcgtttgtat cttccgtaat tttagtctta tcaatgggaa tcataaattt 1605 4561 tccaatgaat tagcaatttc gtccaattct ttttgagctt cttcatattt gctttggaat 1606 4621 tcttcgcact tcttttccca ttcatctctt tcttcttcca aagcaacgat ccttctaccc 1607 4681 atttgctcag agttcaaatc ggcctctttc agtttatcca ttgcttcctt cagtttggct 1608 4741 tcactgtctt ctagctgttg ttctagatcc tggtttttct tggtgtagtt ctcattatta 1609 4801 gatctcaagt tattggagtc ttcagccaat tgctttgtat cagacaattg actctctaac 1610 4861 ttctccactt cactgtcgag ttgctcgttt ttagcggaca aagatttaat ctcgttttct 1611 4921 ttttcagtgt tagattgctc taattctttg agctgttctc tcagctcctc atatttttct 1612 4981 tgccatgact cagattctaa ttttaagcta ttcaatttct ctttgatc 1613 //""" 1614 1615 # GenBank format protein (aka GenPept) file from: 1616 # http://www.molecularevolution.org/resources/fileformats/ 1617 gbk_example2 = \ 1618 """LOCUS AAD51968 143 aa linear BCT 21-AUG-2001 1619 DEFINITION transcriptional regulator RovA [Yersinia enterocolitica]. 1620 ACCESSION AAD51968 1621 VERSION AAD51968.1 GI:5805369 1622 DBSOURCE locus AF171097 accession AF171097.1 1623 KEYWORDS . 1624 SOURCE Yersinia enterocolitica 1625 ORGANISM Yersinia enterocolitica 1626 Bacteria; Proteobacteria; Gammaproteobacteria; Enterobacteriales; 1627 Enterobacteriaceae; Yersinia. 1628 REFERENCE 1 (residues 1 to 143) 1629 AUTHORS Revell,P.A. and Miller,V.L. 1630 TITLE A chromosomally encoded regulator is required for expression of the 1631 Yersinia enterocolitica inv gene and for virulence 1632 JOURNAL Mol. Microbiol. 35 (3), 677-685 (2000) 1633 MEDLINE 20138369 1634 PUBMED 10672189 1635 REFERENCE 2 (residues 1 to 143) 1636 AUTHORS Revell,P.A. and Miller,V.L. 1637 TITLE Direct Submission 1638 JOURNAL Submitted (22-JUL-1999) Molecular Microbiology, Washington 1639 University School of Medicine, Campus Box 8230, 660 South Euclid, 1640 St. Louis, MO 63110, USA 1641 COMMENT Method: conceptual translation. 1642 FEATURES Location/Qualifiers 1643 source 1..143 1644 /organism="Yersinia enterocolitica" 1645 /mol_type="unassigned DNA" 1646 /strain="JB580v" 1647 /serotype="O:8" 1648 /db_xref="taxon:630" 1649 Protein 1..143 1650 /product="transcriptional regulator RovA" 1651 /name="regulates inv expression" 1652 CDS 1..143 1653 /gene="rovA" 1654 /coded_by="AF171097.1:380..811" 1655 /note="regulator of virulence" 1656 /transl_table=11 1657 ORIGIN 1658 1 mestlgsdla rlvrvwrali dhrlkplelt qthwvtlhni nrlppeqsqi qlakaigieq 1659 61 pslvrtldql eekglitrht candrrakri klteqsspii eqvdgvicst rkeilggisp 1660 121 deiellsgli dklerniiql qsk 1661 // 1662 """ 1663 1664 embl_example = """ID X56734; SV 1; linear; mRNA; STD; PLN; 1859 BP. 1665 XX 1666 AC X56734; S46826; 1667 XX 1668 DT 12-SEP-1991 (Rel. 29, Created) 1669 DT 25-NOV-2005 (Rel. 85, Last updated, Version 11) 1670 XX 1671 DE Trifolium repens mRNA for non-cyanogenic beta-glucosidase 1672 XX 1673 KW beta-glucosidase. 1674 XX 1675 OS Trifolium repens (white clover) 1676 OC Eukaryota; Viridiplantae; Streptophyta; Embryophyta; Tracheophyta; 1677 OC Spermatophyta; Magnoliophyta; eudicotyledons; core eudicotyledons; rosids; 1678 OC eurosids I; Fabales; Fabaceae; Papilionoideae; Trifolieae; Trifolium. 1679 XX 1680 RN [5] 1681 RP 1-1859 1682 RX PUBMED; 1907511. 1683 RA Oxtoby E., Dunn M.A., Pancoro A., Hughes M.A.; 1684 RT "Nucleotide and derived amino acid sequence of the cyanogenic 1685 RT beta-glucosidase (linamarase) from white clover (Trifolium repens L.)"; 1686 RL Plant Mol. Biol. 17(2):209-219(1991). 1687 XX 1688 RN [6] 1689 RP 1-1859 1690 RA Hughes M.A.; 1691 RT ; 1692 RL Submitted (19-NOV-1990) to the EMBL/GenBank/DDBJ databases. 1693 RL Hughes M.A., University of Newcastle Upon Tyne, Medical School, Newcastle 1694 RL Upon Tyne, NE2 4HH, UK 1695 XX 1696 FH Key Location/Qualifiers 1697 FH 1698 FT source 1..1859 1699 FT /organism="Trifolium repens" 1700 FT /mol_type="mRNA" 1701 FT /clone_lib="lambda gt10" 1702 FT /clone="TRE361" 1703 FT /tissue_type="leaves" 1704 FT /db_xref="taxon:3899" 1705 FT CDS 14..1495 1706 FT /product="beta-glucosidase" 1707 FT /EC_number="3.2.1.21" 1708 FT /note="non-cyanogenic" 1709 FT /db_xref="GOA:P26204" 1710 FT /db_xref="InterPro:IPR001360" 1711 FT /db_xref="InterPro:IPR013781" 1712 FT /db_xref="UniProtKB/Swiss-Prot:P26204" 1713 FT /protein_id="CAA40058.1" 1714 FT /translation="MDFIVAIFALFVISSFTITSTNAVEASTLLDIGNLSRSSFPRGFI 1715 FT FGAGSSAYQFEGAVNEGGRGPSIWDTFTHKYPEKIRDGSNADITVDQYHRYKEDVGIMK 1716 FT DQNMDSYRFSISWPRILPKGKLSGGINHEGIKYYNNLINELLANGIQPFVTLFHWDLPQ 1717 FT VLEDEYGGFLNSGVINDFRDYTDLCFKEFGDRVRYWSTLNEPWVFSNSGYALGTNAPGR 1718 FT CSASNVAKPGDSGTGPYIVTHNQILAHAEAVHVYKTKYQAYQKGKIGITLVSNWLMPLD 1719 FT DNSIPDIKAAERSLDFQFGLFMEQLTTGDYSKSMRRIVKNRLPKFSKFESSLVNGSFDF 1720 FT IGINYYSSSYISNAPSHGNAKPSYSTNPMTNISFEKHGIPLGPRAASIWIYVYPYMFIQ 1721 FT EDFEIFCYILKINITILQFSITENGMNEFNDATLPVEEALLNTYRIDYYYRHLYYIRSA 1722 FT IRAGSNVKGFYAWSFLDCNEWFAGFTVRFGLNFVD" 1723 FT mRNA 1..1859 1724 FT /experiment="experimental evidence, no additional details 1725 FT recorded" 1726 XX 1727 SQ Sequence 1859 BP; 609 A; 314 C; 355 G; 581 T; 0 other; 1728 aaacaaacca aatatggatt ttattgtagc catatttgct ctgtttgtta ttagctcatt 60 1729 cacaattact tccacaaatg cagttgaagc ttctactctt cttgacatag gtaacctgag 120 1730 tcggagcagt tttcctcgtg gcttcatctt tggtgctgga tcttcagcat accaatttga 180 1731 aggtgcagta aacgaaggcg gtagaggacc aagtatttgg gataccttca cccataaata 240 1732 tccagaaaaa ataagggatg gaagcaatgc agacatcacg gttgaccaat atcaccgcta 300 1733 caaggaagat gttgggatta tgaaggatca aaatatggat tcgtatagat tctcaatctc 360 1734 ttggccaaga atactcccaa agggaaagtt gagcggaggc ataaatcacg aaggaatcaa 420 1735 atattacaac aaccttatca acgaactatt ggctaacggt atacaaccat ttgtaactct 480 1736 ttttcattgg gatcttcccc aagtcttaga agatgagtat ggtggtttct taaactccgg 540 1737 tgtaataaat gattttcgag actatacgga tctttgcttc aaggaatttg gagatagagt 600 1738 gaggtattgg agtactctaa atgagccatg ggtgtttagc aattctggat atgcactagg 660 1739 aacaaatgca ccaggtcgat gttcggcctc caacgtggcc aagcctggtg attctggaac 720 1740 aggaccttat atagttacac acaatcaaat tcttgctcat gcagaagctg tacatgtgta 780 1741 taagactaaa taccaggcat atcaaaaggg aaagataggc ataacgttgg tatctaactg 840 1742 gttaatgcca cttgatgata atagcatacc agatataaag gctgccgaga gatcacttga 900 1743 cttccaattt ggattgttta tggaacaatt aacaacagga gattattcta agagcatgcg 960 1744 gcgtatagtt aaaaaccgat tacctaagtt ctcaaaattc gaatcaagcc tagtgaatgg 1020 1745 ttcatttgat tttattggta taaactatta ctcttctagt tatattagca atgccccttc 1080 1746 acatggcaat gccaaaccca gttactcaac aaatcctatg accaatattt catttgaaaa 1140 1747 acatgggata cccttaggtc caagggctgc ttcaatttgg atatatgttt atccatatat 1200 1748 gtttatccaa gaggacttcg agatcttttg ttacatatta aaaataaata taacaatcct 1260 1749 gcaattttca atcactgaaa atggtatgaa tgaattcaac gatgcaacac ttccagtaga 1320 1750 agaagctctt ttgaatactt acagaattga ttactattac cgtcacttat actacattcg 1380 1751 ttctgcaatc agggctggct caaatgtgaa gggtttttac gcatggtcat ttttggactg 1440 1752 taatgaatgg tttgcaggct ttactgttcg ttttggatta aactttgtag attagaaaga 1500 1753 tggattaaaa aggtacccta agctttctgc ccaatggtac aagaactttc tcaaaagaaa 1560 1754 ctagctagta ttattaaaag aactttgtag tagattacag tacatcgttt gaagttgagt 1620 1755 tggtgcacct aattaaataa aagaggttac tcttaacata tttttaggcc attcgttgtg 1680 1756 aagttgttag gctgttattt ctattatact atgttgtagt aataagtgca ttgttgtacc 1740 1757 agaagctatg atcataacta taggttgatc cttcatgtat cagtttgatg ttgagaatac 1800 1758 tttgaattaa aagtcttttt ttattttttt aaaaaaaaaa aaaaaaaaaa aaaaaaaaa 1859 1759 // 1760 """ 1761 1762 print("GenBank CDS Iteration") 1763 print("=====================") 1764 1765 g = GenBankScanner() 1766 for record in g.parse_cds_features(StringIO(gbk_example)): 1767 print(record) 1768 1769 g = GenBankScanner() 1770 for record in g.parse_cds_features(StringIO(gbk_example2), 1771 tags2id=('gene', 'locus_tag', 'product')): 1772 print(record) 1773 1774 g = GenBankScanner() 1775 for record in g.parse_cds_features(StringIO(gbk_example + "\n" + gbk_example2), 1776 tags2id=('gene', 'locus_tag', 'product')): 1777 print(record) 1778 1779 print("") 1780 print("GenBank Iteration") 1781 print("=================") 1782 g = GenBankScanner() 1783 for record in g.parse_records(StringIO(gbk_example), do_features=False): 1784 print("%s %s %s" % (record.id, record.name, record.description)) 1785 print(record.seq) 1786 1787 g = GenBankScanner() 1788 for record in g.parse_records(StringIO(gbk_example), do_features=True): 1789 print("%s %s %s" % (record.id, record.name, record.description)) 1790 print(record.seq) 1791 1792 g = GenBankScanner() 1793 for record in g.parse_records(StringIO(gbk_example2), do_features=False): 1794 print("%s %s %s" % (record.id, record.name, record.description)) 1795 print(record.seq) 1796 1797 g = GenBankScanner() 1798 for record in g.parse_records(StringIO(gbk_example2), do_features=True): 1799 print("%s %s %s" % (record.id, record.name, record.description)) 1800 print(record.seq) 1801 1802 print("") 1803 print("EMBL CDS Iteration") 1804 print("==================") 1805 1806 e = EmblScanner() 1807 for record in e.parse_cds_features(StringIO(embl_example)): 1808 print(record) 1809 1810 print("") 1811 print("EMBL Iteration") 1812 print("==============") 1813 e = EmblScanner() 1814 for record in e.parse_records(StringIO(embl_example), do_features=True): 1815 print("%s %s %s" % (record.id, record.name, record.description)) 1816 print(record.seq) 1817