jpayne@69: # Copyright 2002 by Andrew Dalke. All rights reserved. jpayne@69: # Revisions 2007-2016 copyright by Peter Cock. All rights reserved. jpayne@69: # Revisions 2008-2009 copyright by Cymon J. Cox. All rights reserved. jpayne@69: # jpayne@69: # This file is part of the Biopython distribution and governed by your jpayne@69: # choice of the "Biopython License Agreement" or the "BSD 3-Clause License". jpayne@69: # Please see the LICENSE file that should have been included as part of this jpayne@69: # package. jpayne@69: # jpayne@69: # Note that BioSQL (including the database schema and scripts) is jpayne@69: # available and licensed separately. Please consult www.biosql.org jpayne@69: """Implementations of Biopython-like Seq objects on top of BioSQL. jpayne@69: jpayne@69: This allows retrieval of items stored in a BioSQL database using jpayne@69: a biopython-like SeqRecord and Seq interface. jpayne@69: jpayne@69: Note: Currently we do not support recording per-letter-annotations jpayne@69: (like quality scores) in BioSQL. jpayne@69: """ jpayne@69: jpayne@69: from typing import List, Optional jpayne@69: jpayne@69: from Bio.Seq import Seq, SequenceDataAbstractBaseClass jpayne@69: from Bio.SeqRecord import SeqRecord, _RestrictedDict jpayne@69: from Bio import SeqFeature jpayne@69: jpayne@69: jpayne@69: class _BioSQLSequenceData(SequenceDataAbstractBaseClass): jpayne@69: """Retrieves sequence data from a BioSQL database (PRIVATE).""" jpayne@69: jpayne@69: __slots__ = ("primary_id", "adaptor", "_length", "start") jpayne@69: jpayne@69: def __init__(self, primary_id, adaptor, start=0, length=0): jpayne@69: """Create a new _BioSQLSequenceData object referring to a BioSQL entry. jpayne@69: jpayne@69: You wouldn't normally create a _BioSQLSequenceData object yourself, jpayne@69: this is done for you when retrieving a DBSeqRecord object from the jpayne@69: database, which creates a Seq object using a _BioSQLSequenceData jpayne@69: instance as the data provider. jpayne@69: """ jpayne@69: self.primary_id = primary_id jpayne@69: self.adaptor = adaptor jpayne@69: self._length = length jpayne@69: self.start = start jpayne@69: super().__init__() jpayne@69: jpayne@69: def __len__(self): jpayne@69: """Return the length of the sequence.""" jpayne@69: return self._length jpayne@69: jpayne@69: def __getitem__(self, key): jpayne@69: """Return a subsequence as a bytes or a _BioSQLSequenceData object.""" jpayne@69: if isinstance(key, slice): jpayne@69: start, end, step = key.indices(self._length) jpayne@69: size = len(range(start, end, step)) jpayne@69: if size == 0: jpayne@69: return b"" jpayne@69: else: jpayne@69: # Return a single letter as an integer (consistent with bytes) jpayne@69: i = key jpayne@69: if i < 0: jpayne@69: i += self._length jpayne@69: if i < 0: jpayne@69: raise IndexError(key) jpayne@69: elif i >= self._length: jpayne@69: raise IndexError(key) jpayne@69: c = self.adaptor.get_subseq_as_string( jpayne@69: self.primary_id, self.start + i, self.start + i + 1 jpayne@69: ) jpayne@69: return ord(c) jpayne@69: jpayne@69: if step == 1: jpayne@69: if start == 0 and size == self._length: jpayne@69: # Return the full sequence as bytes jpayne@69: sequence = self.adaptor.get_subseq_as_string( jpayne@69: self.primary_id, self.start, self.start + self._length jpayne@69: ) jpayne@69: return sequence.encode("ASCII") jpayne@69: else: jpayne@69: # Return a _BioSQLSequenceData with the start and end adjusted jpayne@69: return _BioSQLSequenceData( jpayne@69: self.primary_id, self.adaptor, self.start + start, size jpayne@69: ) jpayne@69: else: jpayne@69: # Will have to extract the sequence because of the stride jpayne@69: full = self.adaptor.get_subseq_as_string( jpayne@69: self.primary_id, self.start + start, self.start + end jpayne@69: ) jpayne@69: return full[::step].encode("ASCII") jpayne@69: jpayne@69: jpayne@69: def _retrieve_seq_len(adaptor, primary_id): jpayne@69: # The database schema ensures there will be only one matching row jpayne@69: seqs = adaptor.execute_and_fetchall( jpayne@69: "SELECT length FROM biosequence WHERE bioentry_id = %s", (primary_id,) jpayne@69: ) jpayne@69: if not seqs: jpayne@69: return None jpayne@69: if len(seqs) != 1: jpayne@69: raise ValueError(f"Expected 1 response, got {len(seqs)}.") jpayne@69: (given_length,) = seqs[0] jpayne@69: return int(given_length) jpayne@69: jpayne@69: jpayne@69: def _retrieve_seq(adaptor, primary_id): jpayne@69: # The database schema ensures there will be only one matching jpayne@69: # row in the table. jpayne@69: jpayne@69: # If an undefined sequence was recorded, seq will be NULL, jpayne@69: # but length will be populated. This means length(seq) jpayne@69: # will return None. jpayne@69: seqs = adaptor.execute_and_fetchall( jpayne@69: "SELECT alphabet, length, length(seq) FROM biosequence WHERE bioentry_id = %s", jpayne@69: (primary_id,), jpayne@69: ) jpayne@69: if not seqs: jpayne@69: return jpayne@69: if len(seqs) != 1: jpayne@69: raise ValueError(f"Expected 1 response, got {len(seqs)}.") jpayne@69: moltype, given_length, length = seqs[0] jpayne@69: jpayne@69: try: jpayne@69: length = int(length) jpayne@69: given_length = int(given_length) jpayne@69: if length != given_length: jpayne@69: raise ValueError( jpayne@69: f"'length' differs from sequence length, {given_length}, {length}" jpayne@69: ) jpayne@69: have_seq = True jpayne@69: except TypeError: jpayne@69: if length is not None: jpayne@69: raise ValueError(f"Expected 'length' to be 'None', got {length}.") jpayne@69: seqs = adaptor.execute_and_fetchall( jpayne@69: "SELECT alphabet, length, seq FROM biosequence WHERE bioentry_id = %s", jpayne@69: (primary_id,), jpayne@69: ) jpayne@69: if len(seqs) != 1: jpayne@69: raise ValueError(f"Expected 1 response, got {len(seqs)}.") jpayne@69: moltype, given_length, seq = seqs[0] jpayne@69: if seq: jpayne@69: raise ValueError(f"Expected 'seq' to have a falsy value, got {seq}.") jpayne@69: length = int(given_length) jpayne@69: have_seq = False jpayne@69: del seq jpayne@69: del given_length jpayne@69: jpayne@69: if have_seq: jpayne@69: data = _BioSQLSequenceData(primary_id, adaptor, start=0, length=length) jpayne@69: return Seq(data) jpayne@69: else: jpayne@69: return Seq(None, length=length) jpayne@69: jpayne@69: jpayne@69: def _retrieve_dbxrefs(adaptor, primary_id): jpayne@69: """Retrieve the database cross references for the sequence (PRIVATE).""" jpayne@69: _dbxrefs = [] jpayne@69: dbxrefs = adaptor.execute_and_fetchall( jpayne@69: "SELECT dbname, accession, version" jpayne@69: " FROM bioentry_dbxref join dbxref using (dbxref_id)" jpayne@69: " WHERE bioentry_id = %s" jpayne@69: ' ORDER BY "rank"', jpayne@69: (primary_id,), jpayne@69: ) jpayne@69: for dbname, accession, version in dbxrefs: jpayne@69: if version and version != "0": jpayne@69: v = f"{accession}.{version}" jpayne@69: else: jpayne@69: v = accession jpayne@69: _dbxrefs.append(f"{dbname}:{v}") jpayne@69: return _dbxrefs jpayne@69: jpayne@69: jpayne@69: def _retrieve_features(adaptor, primary_id): jpayne@69: sql = ( jpayne@69: 'SELECT seqfeature_id, type.name, "rank"' jpayne@69: " FROM seqfeature join term type on (type_term_id = type.term_id)" jpayne@69: " WHERE bioentry_id = %s" jpayne@69: ' ORDER BY "rank"' jpayne@69: ) jpayne@69: results = adaptor.execute_and_fetchall(sql, (primary_id,)) jpayne@69: seq_feature_list = [] jpayne@69: for seqfeature_id, seqfeature_type, seqfeature_rank in results: jpayne@69: # Get qualifiers [except for db_xref which is stored separately] jpayne@69: qvs = adaptor.execute_and_fetchall( jpayne@69: "SELECT name, value" jpayne@69: " FROM seqfeature_qualifier_value join term using (term_id)" jpayne@69: " WHERE seqfeature_id = %s" jpayne@69: ' ORDER BY "rank"', jpayne@69: (seqfeature_id,), jpayne@69: ) jpayne@69: qualifiers = {} jpayne@69: for qv_name, qv_value in qvs: jpayne@69: qualifiers.setdefault(qv_name, []).append(qv_value) jpayne@69: # Get db_xrefs [special case of qualifiers] jpayne@69: qvs = adaptor.execute_and_fetchall( jpayne@69: "SELECT dbxref.dbname, dbxref.accession" jpayne@69: " FROM dbxref join seqfeature_dbxref using (dbxref_id)" jpayne@69: " WHERE seqfeature_dbxref.seqfeature_id = %s" jpayne@69: ' ORDER BY "rank"', jpayne@69: (seqfeature_id,), jpayne@69: ) jpayne@69: for qv_name, qv_value in qvs: jpayne@69: value = f"{qv_name}:{qv_value}" jpayne@69: qualifiers.setdefault("db_xref", []).append(value) jpayne@69: # Get locations jpayne@69: results = adaptor.execute_and_fetchall( jpayne@69: "SELECT location_id, start_pos, end_pos, strand" jpayne@69: " FROM location" jpayne@69: " WHERE seqfeature_id = %s" jpayne@69: ' ORDER BY "rank"', jpayne@69: (seqfeature_id,), jpayne@69: ) jpayne@69: locations = [] jpayne@69: # convert to Python standard form jpayne@69: # Convert strand = 0 to strand = None jpayne@69: # re: comment in Loader.py: jpayne@69: # Biopython uses None when we don't know strand information but jpayne@69: # BioSQL requires something (non null) and sets this as zero jpayne@69: # So we'll use the strand or 0 if Biopython spits out None jpayne@69: for location_id, start, end, strand in results: jpayne@69: if start: jpayne@69: start -= 1 jpayne@69: if strand == 0: jpayne@69: strand = None jpayne@69: if strand not in (+1, -1, None): jpayne@69: raise ValueError( jpayne@69: "Invalid strand %s found in database for " jpayne@69: "seqfeature_id %s" % (strand, seqfeature_id) jpayne@69: ) jpayne@69: if start is not None and end is not None and end < start: jpayne@69: import warnings jpayne@69: from Bio import BiopythonWarning jpayne@69: jpayne@69: warnings.warn( jpayne@69: "Inverted location start/end (%i and %i) for " jpayne@69: "seqfeature_id %s" % (start, end, seqfeature_id), jpayne@69: BiopythonWarning, jpayne@69: ) jpayne@69: jpayne@69: # For SwissProt unknown positions (?) jpayne@69: if start is None: jpayne@69: start = SeqFeature.UnknownPosition() jpayne@69: if end is None: jpayne@69: end = SeqFeature.UnknownPosition() jpayne@69: jpayne@69: locations.append((location_id, start, end, strand)) jpayne@69: # Get possible remote reference information jpayne@69: remote_results = adaptor.execute_and_fetchall( jpayne@69: "SELECT location_id, dbname, accession, version" jpayne@69: " FROM location join dbxref using (dbxref_id)" jpayne@69: " WHERE seqfeature_id = %s", jpayne@69: (seqfeature_id,), jpayne@69: ) jpayne@69: lookup = {} jpayne@69: for location_id, dbname, accession, version in remote_results: jpayne@69: if version and version != "0": jpayne@69: v = f"{accession}.{version}" jpayne@69: else: jpayne@69: v = accession jpayne@69: # subfeature remote location db_ref are stored as a empty string jpayne@69: # when not present jpayne@69: if dbname == "": jpayne@69: dbname = None jpayne@69: lookup[location_id] = (dbname, v) jpayne@69: jpayne@69: feature = SeqFeature.SeqFeature(type=seqfeature_type) jpayne@69: # Store the key as a private property jpayne@69: feature._seqfeature_id = seqfeature_id jpayne@69: feature.qualifiers = qualifiers jpayne@69: if len(locations) == 0: jpayne@69: pass jpayne@69: elif len(locations) == 1: jpayne@69: location_id, start, end, strand = locations[0] jpayne@69: # See Bug 2677, we currently don't record the location_operator jpayne@69: # For consistency with older versions Biopython, default to "". jpayne@69: feature.location_operator = _retrieve_location_qualifier_value( jpayne@69: adaptor, location_id jpayne@69: ) jpayne@69: dbname, version = lookup.get(location_id, (None, None)) jpayne@69: feature.location = SeqFeature.SimpleLocation(start, end) jpayne@69: feature.location.strand = strand jpayne@69: feature.location.ref_db = dbname jpayne@69: feature.location.ref = version jpayne@69: else: jpayne@69: locs = [] jpayne@69: for location in locations: jpayne@69: location_id, start, end, strand = location jpayne@69: dbname, version = lookup.get(location_id, (None, None)) jpayne@69: locs.append( jpayne@69: SeqFeature.SimpleLocation( jpayne@69: start, end, strand=strand, ref=version, ref_db=dbname jpayne@69: ) jpayne@69: ) jpayne@69: # Locations are typically in biological in order (see negative jpayne@69: # strands below), but because of remote locations for jpayne@69: # sub-features they are not necessarily in numerical order: jpayne@69: strands = {_.strand for _ in locs} jpayne@69: if len(strands) == 1 and -1 in strands: jpayne@69: # Evil hack time for backwards compatibility jpayne@69: # TODO - Check if BioPerl and (old) Biopython did the same, jpayne@69: # we may have an existing incompatibility lurking here... jpayne@69: locs = locs[::-1] jpayne@69: feature.location = SeqFeature.CompoundLocation(locs, "join") jpayne@69: # TODO - See Bug 2677 - we don't yet record location operator, jpayne@69: # so for consistency with older versions of Biopython default jpayne@69: # to assuming its a join. jpayne@69: seq_feature_list.append(feature) jpayne@69: return seq_feature_list jpayne@69: jpayne@69: jpayne@69: def _retrieve_location_qualifier_value(adaptor, location_id): jpayne@69: value = adaptor.execute_and_fetch_col0( jpayne@69: "SELECT value FROM location_qualifier_value WHERE location_id = %s", jpayne@69: (location_id,), jpayne@69: ) jpayne@69: try: jpayne@69: return value[0] jpayne@69: except IndexError: jpayne@69: return "" jpayne@69: jpayne@69: jpayne@69: def _retrieve_annotations(adaptor, primary_id, taxon_id): jpayne@69: annotations = {} jpayne@69: annotations.update(_retrieve_alphabet(adaptor, primary_id)) jpayne@69: annotations.update(_retrieve_qualifier_value(adaptor, primary_id)) jpayne@69: annotations.update(_retrieve_reference(adaptor, primary_id)) jpayne@69: annotations.update(_retrieve_taxon(adaptor, primary_id, taxon_id)) jpayne@69: annotations.update(_retrieve_comment(adaptor, primary_id)) jpayne@69: return annotations jpayne@69: jpayne@69: jpayne@69: def _retrieve_alphabet(adaptor, primary_id): jpayne@69: results = adaptor.execute_and_fetchall( jpayne@69: "SELECT alphabet FROM biosequence WHERE bioentry_id = %s", (primary_id,) jpayne@69: ) jpayne@69: if len(results) != 1: jpayne@69: raise ValueError(f"Expected 1 response, got {len(results)}.") jpayne@69: alphabets = results[0] jpayne@69: if len(alphabets) != 1: jpayne@69: raise ValueError(f"Expected 1 alphabet in response, got {len(alphabets)}.") jpayne@69: alphabet = alphabets[0] jpayne@69: if alphabet == "dna": jpayne@69: molecule_type = "DNA" jpayne@69: elif alphabet == "rna": jpayne@69: molecule_type = "RNA" jpayne@69: elif alphabet == "protein": jpayne@69: molecule_type = "protein" jpayne@69: else: jpayne@69: molecule_type = None jpayne@69: if molecule_type is not None: jpayne@69: return {"molecule_type": molecule_type} jpayne@69: else: jpayne@69: return {} jpayne@69: jpayne@69: jpayne@69: def _retrieve_qualifier_value(adaptor, primary_id): jpayne@69: qvs = adaptor.execute_and_fetchall( jpayne@69: "SELECT name, value" jpayne@69: " FROM bioentry_qualifier_value JOIN term USING (term_id)" jpayne@69: " WHERE bioentry_id = %s" jpayne@69: ' ORDER BY "rank"', jpayne@69: (primary_id,), jpayne@69: ) jpayne@69: qualifiers = {} jpayne@69: for name, value in qvs: jpayne@69: if name == "keyword": jpayne@69: name = "keywords" jpayne@69: # See handling of "date" in Loader.py jpayne@69: elif name == "date_changed": jpayne@69: name = "date" jpayne@69: elif name == "secondary_accession": jpayne@69: name = "accessions" jpayne@69: qualifiers.setdefault(name, []).append(value) jpayne@69: return qualifiers jpayne@69: jpayne@69: jpayne@69: def _retrieve_reference(adaptor, primary_id): jpayne@69: # XXX dbxref_qualifier_value jpayne@69: jpayne@69: refs = adaptor.execute_and_fetchall( jpayne@69: "SELECT start_pos, end_pos, " jpayne@69: " location, title, authors," jpayne@69: " dbname, accession" jpayne@69: " FROM bioentry_reference" jpayne@69: " JOIN reference USING (reference_id)" jpayne@69: " LEFT JOIN dbxref USING (dbxref_id)" jpayne@69: " WHERE bioentry_id = %s" jpayne@69: ' ORDER BY "rank"', jpayne@69: (primary_id,), jpayne@69: ) jpayne@69: references = [] jpayne@69: for start, end, location, title, authors, dbname, accession in refs: jpayne@69: reference = SeqFeature.Reference() jpayne@69: # If the start/end are missing, reference.location is an empty list jpayne@69: if (start is not None) or (end is not None): jpayne@69: if start is not None: jpayne@69: start -= 1 # python counting jpayne@69: reference.location = [SeqFeature.SimpleLocation(start, end)] jpayne@69: # Don't replace the default "" with None. jpayne@69: if authors: jpayne@69: reference.authors = authors jpayne@69: if title: jpayne@69: reference.title = title jpayne@69: reference.journal = location jpayne@69: if dbname == "PUBMED": jpayne@69: reference.pubmed_id = accession jpayne@69: elif dbname == "MEDLINE": jpayne@69: reference.medline_id = accession jpayne@69: references.append(reference) jpayne@69: if references: jpayne@69: return {"references": references} jpayne@69: else: jpayne@69: return {} jpayne@69: jpayne@69: jpayne@69: def _retrieve_taxon(adaptor, primary_id, taxon_id): jpayne@69: a = {} jpayne@69: common_names = adaptor.execute_and_fetch_col0( jpayne@69: "SELECT name FROM taxon_name WHERE taxon_id = %s" jpayne@69: " AND name_class = 'genbank common name'", jpayne@69: (taxon_id,), jpayne@69: ) jpayne@69: if common_names: jpayne@69: a["source"] = common_names[0] jpayne@69: scientific_names = adaptor.execute_and_fetch_col0( jpayne@69: "SELECT name FROM taxon_name WHERE taxon_id = %s" jpayne@69: " AND name_class = 'scientific name'", jpayne@69: (taxon_id,), jpayne@69: ) jpayne@69: if scientific_names: jpayne@69: a["organism"] = scientific_names[0] jpayne@69: ncbi_taxids = adaptor.execute_and_fetch_col0( jpayne@69: "SELECT ncbi_taxon_id FROM taxon WHERE taxon_id = %s", (taxon_id,) jpayne@69: ) jpayne@69: if ncbi_taxids and ncbi_taxids[0] and ncbi_taxids[0] != "0": jpayne@69: a["ncbi_taxid"] = ncbi_taxids[0] jpayne@69: jpayne@69: # Old code used the left/right values in the taxon table to get the jpayne@69: # taxonomy lineage in one SQL command. This was actually very slow, jpayne@69: # and would fail if the (optional) left/right values were missing. jpayne@69: # jpayne@69: # The following code is based on a contribution from Eric Gibert, and jpayne@69: # relies on the taxon table's parent_taxon_id field only (ignoring the jpayne@69: # optional left/right values). This means that it has to make a jpayne@69: # separate SQL query for each entry in the lineage, but it does still jpayne@69: # appear to be *much* faster. See Bug 2494. jpayne@69: taxonomy = [] jpayne@69: while taxon_id: jpayne@69: name, rank, parent_taxon_id = adaptor.execute_one( jpayne@69: "SELECT taxon_name.name, taxon.node_rank, taxon.parent_taxon_id" jpayne@69: " FROM taxon, taxon_name" jpayne@69: " WHERE taxon.taxon_id=taxon_name.taxon_id" jpayne@69: " AND taxon_name.name_class='scientific name'" jpayne@69: " AND taxon.taxon_id = %s", jpayne@69: (taxon_id,), jpayne@69: ) jpayne@69: if taxon_id == parent_taxon_id: jpayne@69: # If the taxon table has been populated by the BioSQL script jpayne@69: # load_ncbi_taxonomy.pl this is how top parent nodes are stored. jpayne@69: # Personally, I would have used a NULL parent_taxon_id here. jpayne@69: break jpayne@69: jpayne@69: taxonomy.insert(0, name) jpayne@69: taxon_id = parent_taxon_id jpayne@69: jpayne@69: if taxonomy: jpayne@69: a["taxonomy"] = taxonomy jpayne@69: return a jpayne@69: jpayne@69: jpayne@69: def _retrieve_comment(adaptor, primary_id): jpayne@69: qvs = adaptor.execute_and_fetchall( jpayne@69: 'SELECT comment_text FROM comment WHERE bioentry_id=%s ORDER BY "rank"', jpayne@69: (primary_id,), jpayne@69: ) jpayne@69: comments = [comm[0] for comm in qvs] jpayne@69: # Don't want to add an empty list... jpayne@69: if comments: jpayne@69: return {"comment": comments} jpayne@69: else: jpayne@69: return {} jpayne@69: jpayne@69: jpayne@69: class DBSeqRecord(SeqRecord): jpayne@69: """BioSQL equivalent of the Biopython SeqRecord object.""" jpayne@69: jpayne@69: def __init__(self, adaptor, primary_id): jpayne@69: """Create a DBSeqRecord object. jpayne@69: jpayne@69: Arguments: jpayne@69: - adaptor - A BioSQL.BioSeqDatabase.Adaptor object jpayne@69: - primary_id - An internal integer ID used by BioSQL jpayne@69: jpayne@69: You wouldn't normally create a DBSeqRecord object yourself, jpayne@69: this is done for you when using a BioSeqDatabase object jpayne@69: """ jpayne@69: self._adaptor = adaptor jpayne@69: self._primary_id = primary_id jpayne@69: jpayne@69: ( jpayne@69: self._biodatabase_id, jpayne@69: self._taxon_id, jpayne@69: self.name, jpayne@69: accession, jpayne@69: version, jpayne@69: self._identifier, jpayne@69: self._division, jpayne@69: self.description, jpayne@69: ) = self._adaptor.execute_one( jpayne@69: "SELECT biodatabase_id, taxon_id, name, accession, version," jpayne@69: " identifier, division, description" jpayne@69: " FROM bioentry" jpayne@69: " WHERE bioentry_id = %s", jpayne@69: (self._primary_id,), jpayne@69: ) jpayne@69: if version and version != "0": jpayne@69: self.id = f"{accession}.{version}" jpayne@69: else: jpayne@69: self.id = accession jpayne@69: # We don't yet record any per-letter-annotations in the jpayne@69: # BioSQL database, but we should set this property up jpayne@69: # for completeness (and the __str__ method). jpayne@69: # We do NOT want to load the sequence from the DB here! jpayne@69: length = _retrieve_seq_len(adaptor, primary_id) jpayne@69: self._per_letter_annotations = _RestrictedDict(length=length) jpayne@69: jpayne@69: def __get_seq(self): jpayne@69: if not hasattr(self, "_seq"): jpayne@69: self._seq = _retrieve_seq(self._adaptor, self._primary_id) jpayne@69: return self._seq jpayne@69: jpayne@69: def __set_seq(self, seq): jpayne@69: # TODO - Check consistent with self._per_letter_annotations jpayne@69: self._seq = seq jpayne@69: jpayne@69: def __del_seq(self): jpayne@69: del self._seq jpayne@69: jpayne@69: seq = property(__get_seq, __set_seq, __del_seq, "Seq object") jpayne@69: jpayne@69: @property jpayne@69: def dbxrefs(self) -> List[str]: jpayne@69: """Database cross references.""" jpayne@69: if not hasattr(self, "_dbxrefs"): jpayne@69: self._dbxrefs = _retrieve_dbxrefs(self._adaptor, self._primary_id) jpayne@69: return self._dbxrefs jpayne@69: jpayne@69: @dbxrefs.setter jpayne@69: def dbxrefs(self, value: List[str]) -> None: jpayne@69: self._dbxrefs = value jpayne@69: jpayne@69: @dbxrefs.deleter jpayne@69: def dbxrefs(self) -> None: jpayne@69: del self._dbxrefs jpayne@69: jpayne@69: def __get_features(self): jpayne@69: if not hasattr(self, "_features"): jpayne@69: self._features = _retrieve_features(self._adaptor, self._primary_id) jpayne@69: return self._features jpayne@69: jpayne@69: def __set_features(self, features): jpayne@69: self._features = features jpayne@69: jpayne@69: def __del_features(self): jpayne@69: del self._features jpayne@69: jpayne@69: features = property(__get_features, __set_features, __del_features, "Features") jpayne@69: jpayne@69: @property jpayne@69: def annotations(self) -> SeqRecord._AnnotationsDict: jpayne@69: """Annotations.""" jpayne@69: if not hasattr(self, "_annotations"): jpayne@69: self._annotations = _retrieve_annotations( jpayne@69: self._adaptor, self._primary_id, self._taxon_id jpayne@69: ) jpayne@69: if self._identifier: jpayne@69: self._annotations["gi"] = self._identifier jpayne@69: if self._division: jpayne@69: self._annotations["data_file_division"] = self._division jpayne@69: return self._annotations jpayne@69: jpayne@69: @annotations.setter jpayne@69: def annotations(self, value: Optional[SeqRecord._AnnotationsDict]) -> None: jpayne@69: if value: jpayne@69: self._annotations = value jpayne@69: else: jpayne@69: self._annotations = {} jpayne@69: jpayne@69: @annotations.deleter jpayne@69: def annotations(self) -> None: jpayne@69: del self._annotations