# coding: utf-8
from __future__ import absolute_import
from pyhml.models.allele_assignment import AlleleAssignment
from pyhml.models.consensus import Consensus
from pyhml.models.typing_method import TypingMethod
from .base_model_ import Model
from datetime import date, datetime
from typing import List, Dict
from ..util import deserialize_model
from Bio.SeqFeature import SeqFeature, FeatureLocation, ExactPosition
from Bio.Seq import Seq
from Bio.SeqRecord import SeqRecord
from collections import OrderedDict
from Bio.Alphabet import IUPAC
[docs]class Typing(Model):
"""
NOTE: This class is auto generated by the swagger code generator program.
Do not edit the class manually.
"""
def __init__(self, date: str=None, gene_family: str=None, allele_assignment: List[AlleleAssignment]=None, consensus_sequence: List[Consensus]=None, typing_method: TypingMethod=None):
"""
Typing - a model defined in Swagger
:param date: The date of this Typing.
:type date: str
:param gene_family: The gene_family of this Typing.
:type gene_family: str
:param allele_assignment: The allele_assignment of this Typing.
:type allele_assignment: List[AlleleAssignment]
:param consensus_sequence: The consensus_sequence of this Typing.
:type consensus_sequence: List[Consensus]
:param typing_method: The typing_method of this Typing.
:type typing_method: TypingMethod
"""
self.swagger_types = {
'date': str,
'gene_family': str,
'allele_assignment': List[AlleleAssignment],
'consensus_sequence': List[Consensus],
'typing_method': TypingMethod,
'seq_records': List[SeqRecord]
}
self.attribute_map = {
'date': 'date',
'gene_family': 'gene_family',
'allele_assignment': 'allele_assignment',
'consensus_sequence': 'consensus_sequence',
'typing_method': 'typing_method',
'seq_records': 'seq_records'
}
self._date = date
self._gene_family = gene_family
self._allele_assignment = allele_assignment
self._consensus_sequence = consensus_sequence
self._typing_method = typing_method
self._seq_records = []
[docs] @classmethod
def from_dict(cls, dikt) -> 'Typing':
"""
Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The Typing of this Typing.
:rtype: Typing
"""
return deserialize_model(dikt, cls)
@property
def date(self) -> str:
"""
Gets the date of this Typing.
:return: The date of this Typing.
:rtype: str
"""
return self._date
@date.setter
def date(self, date: str):
"""
Sets the date of this Typing.
:param date: The date of this Typing.
:type date: str
"""
self._date = date
@property
def gene_family(self) -> str:
"""
Gets the gene_family of this Typing.
:return: The gene_family of this Typing.
:rtype: str
"""
return self._gene_family
@gene_family.setter
def gene_family(self, gene_family: str):
"""
Sets the gene_family of this Typing.
:param gene_family: The gene_family of this Typing.
:type gene_family: str
"""
self._gene_family = gene_family
@property
def allele_assignment(self) -> List[AlleleAssignment]:
"""
Gets the allele_assignment of this Typing.
:return: The allele_assignment of this Typing.
:rtype: List[AlleleAssignment]
"""
return self._allele_assignment
@allele_assignment.setter
def allele_assignment(self, allele_assignment: List[AlleleAssignment]):
"""
Sets the allele_assignment of this Typing.
:param allele_assignment: The allele_assignment of this Typing.
:type allele_assignment: List[AlleleAssignment]
"""
self._allele_assignment = allele_assignment
@property
def consensus_sequence(self) -> List[Consensus]:
"""
Gets the consensus_sequence of this Typing.
:return: The consensus_sequence of this Typing.
:rtype: List[Consensus]
"""
return self._consensus_sequence
@consensus_sequence.setter
def consensus_sequence(self, consensus_sequence: List[Consensus]):
"""
Sets the consensus_sequence of this Typing.
:param consensus_sequence: The consensus_sequence of this Typing.
:type consensus_sequence: List[Consensus]
"""
self._consensus_sequence = consensus_sequence
@property
def typing_method(self) -> TypingMethod:
"""
Gets the typing_method of this Typing.
:return: The typing_method of this Typing.
:rtype: TypingMethod
"""
return self._typing_method
@typing_method.setter
def typing_method(self, typing_method: TypingMethod):
"""
Sets the typing_method of this Typing.
:param typing_method: The typing_method of this Typing.
:type typing_method: TypingMethod
"""
self._typing_method = typing_method
@property
def seq_records(self) -> List[SeqRecord]:
"""
Gets the seq_records of this ReferenceData.
:return: The seq_records of this ReferenceData.
:rtype: List[SeqRecord]
"""
return self._seq_records
[docs] def create_seqrecord(self, subid):
als = self.allele_assignment
con = self.consensus_sequence
loc = ''
if als[0].glstring:
loc = als[0].glstring[0].split("*")[0]
elif als[0].haploid:
loc = als[0].haploid[0].locus
dbversion = []
glstrings = []
for i in range(0, len(als)):
if als[i].allele_version not in dbversion:
dbversion.append(als[i].allele_version)
for glstring in als[i].glstring:
glstrings.append(glstring)
gl = '|'.join(glstrings)
des = '|'.join(dbversion)
n = 0
seq_records = []
for cons in con:
for cb in cons.consensus_sequence_block:
rsid = 'X' + loc + "_" + str(n)
seq_record = SeqRecord(id=rsid, name=gl, seq=cb.sequence, description=des)
sf = SeqFeature(FeatureLocation(0, len(str(seq_record.seq))), type="source", strand=1)
seq_record.features.append(sf)
seq_record.annotations["sequence_version"] = 1
seq_record.annotations["molecule_type"] = "DNA"
seq_record.annotations["data_file_division"] = "HUM"
seq_record.features[0].qualifiers = OrderedDict([('organism', ['Homo sapiens']), ('mol_type', ['genomic DNA']), ('db_xref', ['taxon:9606'])])
seq_records.append(seq_record)
n += 1
self._seq_records = seq_records
return [loc, seq_records]