Exemplo n.º 1
0
class ImagePaneAssocView(db.Model, MGIModel):
    __tablename__ = "img_imagepane_assoc_view"
    _assoc_key = db.Column(db.Integer, primary_key=True)
    _imagepane_key = db.Column(db.Integer,
                               mgi_fk("img_imagepane._imagepane_key"),
                               primary_key=True)
    _object_key = db.Column(db.Integer())
    _mgitype_key = db.Column(db.Integer())
    _imageclass_key = db.Column(db.Integer())
    isprimary = db.Column(db.Integer())
    mgiid = db.Column(db.String())

    allele = db.relationship(
        "Allele",
        primaryjoin="and_(ImagePaneAssocView._object_key==Allele._allele_key, "
        "ImagePaneAssocView._mgitype_key==11) ",
        foreign_keys="[Allele._allele_key]",
        uselist=False)

    genotype = db.relationship(
        "Genotype",
        primaryjoin=
        "and_(ImagePaneAssocView._object_key==Genotype._genotype_key, "
        "ImagePaneAssocView._mgitype_key==12) ",
        foreign_keys="[Genotype._genotype_key]",
        uselist=False)
Exemplo n.º 2
0
class ImagePane(db.Model, MGIModel):
    __tablename__ = "img_imagepane"
    _imagepane_key = db.Column(db.Integer, primary_key=True)
    _image_key = db.Column(db.Integer(), mgi_fk("img_image._image_key"))
    panelabel = db.Column(db.String())
    x = db.Column(db.Integer())
    y = db.Column(db.Integer())
    width = db.Column(db.Integer())
    height = db.Column(db.Integer())

    image = db.relationship("Image", uselist=False)

    imagePaneAlleleAssocs = db.relationship(
        "ImagePaneAssocView",
        primaryjoin=
        "and_(ImagePane._imagepane_key==ImagePaneAssocView._imagepane_key, "
        "ImagePaneAssocView._mgitype_key==11) ",
        foreign_keys="[ImagePaneAssocView._imagepane_key]")

    imagePaneGenotypeAssocs = db.relationship(
        "ImagePaneAssocView",
        primaryjoin=
        "and_(ImagePane._imagepane_key==ImagePaneAssocView._imagepane_key, "
        "ImagePaneAssocView._mgitype_key==12) ",
        foreign_keys="[ImagePaneAssocView._imagepane_key]")

    # gel_assays
    # backref defined in gxd.Assay class

    # insituresults
    # backref defined in InsituResult class

    @property
    def figurelabel(self):
        figurelabel = self.image.figurelabel or ''
        panelabel = self.panelabel or ''
        return '%s%s' % (figurelabel, panelabel)

    @property
    def distinctInsituAssays(self):
        distinctAssays = []
        distinctAssaysKeys = []
        for result in self.insituresults:
            if result.specimen.assay._assay_key not in distinctAssaysKeys:
                distinctAssays.append(result.specimen.assay)
                distinctAssaysKeys.append(result.specimen.assay._assay_key)
        distinctAssays.sort(key=lambda x: x.mgiid)
        #ut.sort(key=lambda x: x.count, reverse=True)
        return distinctAssays
Exemplo n.º 3
0
class MarkerLocationCache(db.Model, MGIModel):
    __tablename__ = "mrk_location_cache"
    _cache_key = db.Column(db.Integer, primary_key=True)
    _marker_key = db.Column(db.Integer,
                            db.ForeignKey("mrk_marker._marker_key"))
    _organism_key = db.Column(db.Integer())
    chromosome = db.Column(db.String())
    cytogeneticoffset = db.Column(db.String())
    cmoffset = db.Column(db.Float())
    genomicchromosome = db.Column(db.String())
    startcoordinate = db.Column(db.Float())
    endcoordinate = db.Column(db.Float())
    strand = db.Column(db.String())
    mapunits = db.Column(db.String())
    provider = db.Column(db.String())
    version = db.Column(db.String())

    @property
    def providerString(self):
        if not self.provider:
            return ""
        return "From %s annotation of %s" % (self.provider, self.version)

    def __repr__(self):
        if not self.startcoordinate or not self.endcoordinate:
            return "Chr%s" % (self.chromosome)

        return "Chr%s:%d-%d bp, %s strand" % (self.chromosome,
                                              self.startcoordinate,
                                              self.endcoordinate, self.strand)
Exemplo n.º 4
0
class AlleleMutation(db.Model, MGIModel):
    __tablename__ = "all_allele_mutation"
    _allele_key = db.Column(db.Integer,
                            mgi_fk("all_allele._allele_key"),
                            primary_key=True)
    _mutation_key = db.Column(db.Integer(),
                              mgi_fk("voc_term._term_key"),
                              primary_key=True)
Exemplo n.º 5
0
class ProbeAlleleStrain(db.Model, MGIModel):
    __tablename__ = "prb_allele_strain"
    _allele_key = db.Column(db.Integer,
                            mgi_fk("prb_allele._allele_key"),
                            primary_key=True)
    _strain_key = db.Column(db.Integer(),
                            mgi_fk("prb_strain._strain_key"),
                            primary_key=True)

    strain = db.relationship("Strain", uselist=False)
Exemplo n.º 6
0
class MappingExperiment(db.Model, MGIModel):
    __tablename__ = "mld_expts"
    _expt_key = db.Column(db.Integer, primary_key=True)
    _refs_key = db.Column(db.Integer, mgi_fk("bib_refs._refs_key"))
    expttype = db.Column(db.String())
    tag = db.Column(db.Integer())
    chromosome = db.Column(db.String())

    # key constants
    _mgitype_key = 4

    # other constants

    # these are expttypes that are valid to display in the P-WI
    VALID_EXPTTYPES = [
        'TEXT', 'TEXT-Genetic Cross', 'TEXT-Physical Mapping', 'TEXT-QTL',
        'TEXT-Congenic', 'TEXT-Meta Analysis', 'TEXT-QTL-Candidate Genes'
    ]

    # column properties
    mgiid = db.column_property(
        db.select([Accession.accid]).where(
            db.and_(Accession._mgitype_key == _mgitype_key,
                    Accession.prefixpart == 'MGI:', Accession.preferred == 1,
                    Accession._logicaldb_key == 1,
                    Accession._object_key == _expt_key)))

    # relationships

    mgiid_object = db.relationship(
        "Accession",
        primaryjoin="and_(Accession._object_key==MappingExperiment._expt_key,"
        "Accession.prefixpart=='MGI:',"
        "Accession.preferred==1,"
        "Accession._logicaldb_key==1,"
        "Accession._mgitype_key==%d)" % _mgitype_key,
        foreign_keys="[Accession._object_key]",
        uselist=False)

    experiment_notechunks = db.relationship("ExperimentNoteChunk")

    # beware, this field is limitting its search to only displayable experiment types in the P-WI
    # this lets the marker detail know when to display a summary link to mapping data
    marker_assocs = db.relationship(
        "ExperimentMarkerAssoc",
        primaryjoin=
        "and_(ExperimentMarkerAssoc._expt_key==MappingExperiment._expt_key,"
        "MappingExperiment.expttype.in_(%s))" % VALID_EXPTTYPES,
        order_by="ExperimentMarkerAssoc.sequencenum")

    reference = db.relationship("Reference", backref="mapping_experiments")

    @property
    def experimentnote(self):
        return "".join([nc.note for nc in self.experiment_notechunks])
Exemplo n.º 7
0
class AlleleAnnotView(db.Model, MGIModel):
    """
    Allele to Annotation association view
    """
    __tablename__ = "all_annot_view"
    _allele_key = db.Column(db.Integer,
                            mgi_fk("all_allele._allele_key"),
                            primary_key=True)
    _annot_key = db.Column(db.Integer(),
                           mgi_fk("voc_annot._annot_key"),
                           primary_key=True)
Exemplo n.º 8
0
class Accession(db.Model,MGIModel):
    __tablename__ = "acc_accession"
    _accession_key = db.Column(db.Integer,primary_key=True)
    accid = db.Column(db.String())
    prefixpart = db.Column(db.String())
    numericpart = db.Column(db.Integer())
    _logicaldb_key = db.Column(db.Integer(), mgi_fk("acc_logicaldb._logicaldb_key"))
    _object_key = db.Column(db.Integer())
    _mgitype_key = db.Column(db.Integer())
    private = db.Column(db.Integer())
    preferred = db.Column(db.Integer())
    _createdby_key = db.Column(db.Integer())
    _modifiedby_key = db.Column(db.Integer())
    
    logicaldb = db.column_property(
            db.select([LogicalDb.name]).
            where(LogicalDb._logicaldb_key==_logicaldb_key)
    )
    
    
    # relationships
    
    logicaldb_object = db.relationship("LogicalDb",
        uselist=False)
    
    mgitype = db.relationship("MGIType",
        uselist=False,
        primaryjoin="MGIType._mgitype_key==Accession._mgitype_key",
        foreign_keys="[MGIType._mgitype_key]")
    
    references = db.relationship("Reference",
                secondary=AccessionReference.__table__,
                backref="accessions")
    
    emapsids = db.relationship("Accession",
        primaryjoin="Accession.accid==EmapSMapping.accid",
        secondary=EmapSMapping.__table__,
        secondaryjoin="Accession.accid==EmapSMapping.emapsid",
        foreign_keys="[EmapSMapping.emapsid, Accession.accid]",
        backref="adstructureids")
    
    vocterm = db.relationship("VocTerm",
        primaryjoin="VocTerm._term_key==Accession._object_key",
        foreign_keys="VocTerm._term_key",
        uselist=False
    )
    
    def __repr__(self):
        return "<AccID %s>"%(self.accid,)
Exemplo n.º 9
0
class AccessionMax(db.Model,MGIModel):
    __tablename__ = "acc_accessionmax"
    prefixpart = db.Column(db.String(),primary_key=True)
    maxnumericpart = db.Column(db.Integer())
Exemplo n.º 10
0
class Allele(db.Model, MGIModel):

    __tablename__ = "all_allele"
    _allele_key = db.Column(db.Integer, primary_key=True)
    _marker_key = db.Column(db.Integer, mgi_fk("mrk_marker._marker_key"))
    _allele_status_key = db.Column(db.Integer)
    _allele_type_key = db.Column(db.Integer())
    _mode_key = db.Column(db.Integer())
    _transmission_key = db.Column(db.Integer())
    _collection_key = db.Column(db.Integer())
    _strain_key = db.Column(db.Integer(), mgi_fk("prb_strain._strain_key"))
    iswildtype = db.Column(db.Integer())
    name = db.Column(db.String())
    symbol = db.Column(db.String())

    # key constants
    _mgitype_key = 11
    _allele_status_vocab_key = 37
    _molecular_mutation_key = 36
    _allele_type_vocab_key = 38
    _transmission_vocab_key = 61
    _collection_vocab_key = 92
    _mode_vocab_key = 35
    _allele_subtype_voc_annot_key = 1014
    _allele_driver_note_type = 1034
    _nomen_note_type = 1022
    _mp_annottype_key = 1002
    _disease_geno_anottype_key = 1005
    _disease_allele_annottype_key = 1012
    # joined fields

    alleletype = db.column_property(
        db.select([VocTerm.term]).
        where(db.and_(VocTerm._term_key==_allele_type_key, \
            VocTerm._vocab_key==_allele_type_vocab_key))
    )

    collection = db.column_property(
        db.select([VocTerm.term]).
        where(db.and_(VocTerm._term_key==_collection_key, \
            VocTerm._vocab_key==_collection_vocab_key))
    )

    #mgiid = db.Column(db.String())
    mgiid = db.column_property(
        db.select([Accession.accid]).where(
            db.and_(Accession._mgitype_key == _mgitype_key,
                    Accession.prefixpart == 'MGI:', Accession.preferred == 1,
                    Accession._logicaldb_key == 1,
                    Accession._object_key == _allele_key)))

    modeRaw = db.column_property(
        db.select([VocTerm.term]).
        where(db.and_(VocTerm._term_key==_mode_key, \
            VocTerm._vocab_key==_mode_vocab_key))
    )

    status = db.column_property(
        db.select([VocTerm.term]).
        where(db.and_(VocTerm._term_key==_allele_status_key, \
            VocTerm._vocab_key==_allele_status_vocab_key))
    )

    transmission = db.column_property(
        db.select([VocTerm.term]).
        where(db.and_(VocTerm._term_key==_transmission_key, \
            VocTerm._vocab_key==_transmission_vocab_key))
    )

    # relationships
    mgiid_object = db.relationship(
        "Accession",
        primaryjoin="and_(Accession._object_key==Allele._allele_key,"
        "Accession.prefixpart=='MGI:',"
        "Accession.preferred==1,"
        "Accession._logicaldb_key==1,"
        "Accession._mgitype_key==%d)" % _mgitype_key,
        foreign_keys="[Accession._object_key]",
        uselist=False)

    strain = db.relationship("Strain", uselist=False, backref="alleles")

    allelecelllineassoc = db.relationship("AlleleCelllineAssoc")

    molecularmutation = db.relationship(
        "VocTerm",
        secondary=AlleleMutation.__table__,
        secondaryjoin="and_(VocTerm._term_key==AlleleMutation._mutation_key,"
        "VocTerm._vocab_key ==%d)" % _molecular_mutation_key)

    transmissionref = db.relationship(
        "ReferenceAssoc",
        primaryjoin=
        "and_(Allele._allele_key==ReferenceAssoc._object_key, ReferenceAssoc._refassoctype_key==1023, ReferenceAssoc._mgitype_key==%d)"
        % _mgitype_key,
        foreign_keys="[ReferenceAssoc._object_key]",
        uselist=False)

    molecularrefs = db.relationship(
        "ReferenceAssoc",
        primaryjoin=
        "and_(Allele._allele_key==ReferenceAssoc._object_key, ReferenceAssoc._refassoctype_key==1012, ReferenceAssoc._mgitype_key==%d)"
        % _mgitype_key,
        foreign_keys="[ReferenceAssoc._object_key]")

    primaryimagepane = db.relationship(
        "ImagePane",
        primaryjoin="and_(Allele._allele_key==ImagePaneAssocView._object_key, "
        "ImagePaneAssocView._imageclass_key==6481782, "
        "ImagePaneAssocView.isprimary==1, "
        "ImagePaneAssocView._mgitype_key==%d)" % _mgitype_key,
        secondary=ImagePaneAssocView.__table__,
        secondaryjoin=
        "ImagePaneAssocView._imagepane_key==ImagePane._imagepane_key",
        foreign_keys=
        "[ImagePaneAssocView._object_key, ImagePaneAssocView._imagepane_key]",
        uselist=False)

    phenoimagepanes = db.relationship(
        "ImagePane",
        primaryjoin="and_(Allele._allele_key==ImagePaneAssocView._object_key, "
        "ImagePaneAssocView._imageclass_key==6481782, "
        "ImagePaneAssocView._mgitype_key==%d)" % _mgitype_key,
        secondary=ImagePaneAssocView.__table__,
        secondaryjoin=
        "ImagePaneAssocView._imagepane_key==ImagePane._imagepane_key",
        foreign_keys=
        "[ImagePaneAssocView._object_key, ImagePaneAssocView._imagepane_key]",
        order_by="desc(ImagePaneAssocView.isprimary)")

    molecularimagepanes = db.relationship(
        "ImagePane",
        primaryjoin="and_(Allele._allele_key==ImagePaneAssocView._object_key, "
        "ImagePaneAssocView._imageclass_key==6481783, "
        "ImagePaneAssocView._mgitype_key==%d)" % _mgitype_key,
        secondary=ImagePaneAssocView.__table__,
        secondaryjoin=
        "ImagePaneAssocView._imagepane_key==ImagePane._imagepane_key",
        foreign_keys=
        "[ImagePaneAssocView._object_key, ImagePaneAssocView._imagepane_key]",
        order_by="ImagePaneAssocView.isprimary")

    imageAssocs = db.relationship(
        "ImagePaneAssocView",
        primaryjoin="and_(Allele._allele_key==ImagePaneAssocView._object_key, "
        "ImagePaneAssocView._mgitype_key==%d)" % _mgitype_key,
        foreign_keys="[ImagePaneAssocView._object_key]")

    molecularimage = db.relationship(
        "ImagePaneAssocView",
        primaryjoin="and_(Allele._allele_key==ImagePaneAssocView._object_key, "
        "ImagePaneAssocView._imageclass_key==6481783, "
        "ImagePaneAssocView._mgitype_key==%d)" % _mgitype_key,
        foreign_keys="[ImagePaneAssocView._object_key]")

    synonyms = db.relationship(
        "Synonym",
        primaryjoin="and_(Allele._allele_key==Synonym._object_key, "
        "Synonym._mgitype_key==%d)" % _mgitype_key,
        order_by="Synonym.synonym",
        foreign_keys="[Synonym._object_key]")

    subtypes = db.relationship(
        "VocTerm",
        secondary=VocAnnot.__table__,
        primaryjoin="and_(Allele._allele_key==VocAnnot._object_key, "
        "VocAnnot._annottype_key==%d)" % _allele_subtype_voc_annot_key,
        secondaryjoin="VocAnnot._term_key==VocTerm._term_key",
        foreign_keys="[Allele._allele_key,VocTerm._term_key]",
        backref="explicit_subtypes")

    drivernote = db.relationship(
        "Note",
        primaryjoin="and_(Allele._allele_key==Note._object_key, "
        "Note._mgitype_key==11, Note._notetype_key==1034) ",
        foreign_keys="[Note._object_key]",
        uselist=False)

    induciblenote = db.relationship(
        "Note",
        primaryjoin="and_(Allele._allele_key==Note._object_key, "
        "Note._mgitype_key==11, Note._notetype_key==1032) ",
        foreign_keys="[Note._object_key]",
        uselist=False)

    nomennoteRaw = db.relationship(
        "Note",
        primaryjoin="and_(Allele._allele_key==Note._object_key, "
        "Note._mgitype_key==11, Note._notetype_key==1022) ",
        foreign_keys="[Note._object_key]",
        uselist=False)

    generalnoteRaw = db.relationship(
        "Note",
        primaryjoin="and_(Allele._allele_key==Note._object_key, "
        "Note._mgitype_key==11, Note._notetype_key==1020) ",
        foreign_keys="[Note._object_key]",
        uselist=False)

    molecularnote = db.relationship(
        "Note",
        primaryjoin="and_(Allele._allele_key==Note._object_key, "
        "Note._mgitype_key==11, Note._notetype_key==1021) ",
        foreign_keys="[Note._object_key]",
        uselist=False)

    marker = db.relationship("Marker", uselist=False, backref="alleles")

    mp_annots = db.relationship(
        "VocAnnot",
        secondary=AlleleAnnotView.__table__,
        secondaryjoin="and_(VocAnnot._annot_key==AlleleAnnotView._annot_key,"
        "VocAnnot._annottype_key==%d)" % _mp_annottype_key)

    disease_annots = db.relationship(
        "VocAnnot",
        secondary=AlleleAnnotView.__table__,
        secondaryjoin="and_(VocAnnot._annot_key==AlleleAnnotView._annot_key,"
        "VocAnnot._annottype_key.in_(%s))" %
        [_disease_geno_anottype_key, _disease_allele_annottype_key])

    explicit_references = db.relationship(
        "Reference",
        secondary=ReferenceAssoc.__table__,
        primaryjoin="and_(Allele._allele_key==ReferenceAssoc._object_key, "
        "ReferenceAssoc._mgitype_key==%d)" % _mgitype_key,
        secondaryjoin="ReferenceAssoc._refs_key==Reference._refs_key",
        foreign_keys="[ReferenceAssoc._object_key, Reference._refs_key]",
        backref="explicit_alleles")

    genotypes = db.relationship("Genotype",
                                secondary=AlleleGenotype.__table__,
                                order_by="AlleleGenotype.sequencenum")

    # assays
    # assays backref defined in GxdAssay class

    # transient property methods

    @property
    def allelecelllines(self):
        return ", ".join([
            assoc.allelecelllineview.cellline
            for assoc in self.allelecelllineassoc
        ])

    @property
    def alleleparentcellline(self):
        parentCellLine = ""
        if (self.allelecelllineassoc):
            # use first allele assoc - data identical for this field
            parentCellLine = self.allelecelllineassoc[
                0].allelecelllineview.parentcellline
        return parentCellLine

    @property
    def celllinetype(self):
        celllinetype = ""
        if (self.allelecelllineassoc):
            # use first allele assoc - data identical for this field
            celllinetype = self.allelecelllineassoc[
                0].allelecelllineview.celllinetype
        return celllinetype

    @property
    def disease_terms(self):
        terms = [d.term for d in self.disease_annots]
        terms.sort()
        return terms

    @property
    def generalnote(self):
        generalnote = self.generalnoteRaw or ''
        return generalnote

    @property
    def mode(self):
        mode = self.modeRaw or ''
        return mode

    @property
    def molecularimageid(self):
        imageMgiID = ""
        if (self.molecularimage):
            # use first allele assoc - data identical for this field
            imageMgiID = self.molecularimage[0].mgiid
        return imageMgiID

    @property
    def nomennote(self):
        nomennote = self.nomennoteRaw or ''
        return nomennote

    @property
    def primaryimageid(self):
        imageMgiID = ""
        if (self.primaryimage):
            # use first allele assoc - data identical for this field
            imageMgiID = self.primaryimage[0].mgiid
        return imageMgiID

    @property
    def summary_mp_display(self):
        """
        mp column on allele  summary
        """
        val = ''
        if self.mp_annots:
            if len(self.mp_annots) == len(
                [m for m in self.mp_annots if m.qualifier == 'normal']):
                val = 'no abnormal phenotype observed'
            else:
                val = 'has data'
        return val

    @property
    def vector(self):
        vector = ""
        if (self.allelecelllineassoc):
            # use first allele assoc - data identical for this field
            vector = self.allelecelllineassoc[0].allelecelllineview.vector
        return vector

    @property
    def vectortype(self):
        vectortype = ""
        if (self.allelecelllineassoc):
            # use first allele assoc - data identical for this field
            vectortype = self.allelecelllineassoc[
                0].allelecelllineview.vectortype
        return vectortype

    @property
    def genotypes_with_phenotypes(self):
        """
        Filters out any genotypes with no mp_annots
        (tip: might want to pre-load all the mp_annot objects
            with batchLoadAttribute to avoid numerous queries)
        """
        return [geno for geno in self.genotypes if geno.mp_annots]

    @property
    def hasImages(self):
        hasImages = False
        if (self.phenoimagepanes):
            hasImages = True
        if (self.molecularimagepanes):
            hasImages = True
        return hasImages

#     @classmethod
#     def has_explicit_references(self):
#         q = self.query.filter(Allele.explicit_references.any())
#         return db.object_session(self).query(db.literal(True)) \
#             .filter(q.exists()).scalar()

    def __repr__(self):
        return "<Allele %s>" % (self.mgiid, )
Exemplo n.º 11
0
class Marker(db.Model, MGIModel):
    __tablename__ = "mrk_marker"
    _marker_key = db.Column(db.Integer, primary_key=True)
    _organism_key = db.Column(db.Integer())
    _organism_key.hidden = True
    _marker_type_key = db.Column(db.Integer())
    _marker_type_key.hidden = True
    _marker_status_key = db.Column(db.Integer())
    _marker_status_key.hidden = True
    symbol = db.Column(db.String())
    name = db.Column(db.String())
    chromosome = db.Column(db.String())
    cytogeneticoffset = db.Column(db.String())

    #constants
    _mgitype_key = 2
    _mcv_annottype_key = 1011
    # the biotype conflict term
    _biotypeconflict_yes_key = 5420767

    # joined fields
    organism = db.column_property(
        db.select([Organism.commonname
                   ]).where(Organism._organism_key == _organism_key))
    markertype = db.column_property(
        db.select([MarkerType.name
                   ]).where(MarkerType._marker_type_key == _marker_type_key))

    markerstatus = db.column_property(
        db.select([MarkerStatus.status
                   ]).where(MarkerStatus._marker_status_key ==
                            _marker_status_key).label("markerstatus"))

    #mgiid = db.Column(db.String())
    mgiid = db.column_property(
        db.select([Accession.accid]).where(
            db.and_(Accession._mgitype_key == _mgitype_key,
                    Accession.prefixpart == 'MGI:', Accession.preferred == 1,
                    Accession._logicaldb_key == 1,
                    Accession._object_key == _marker_key)))

    # joined relationship

    # alleles
    # alleles backref defined in Allele class

    mgiid_object = db.relationship(
        "Accession",
        primaryjoin="and_(Accession._object_key==Marker._marker_key,"
        "Accession.prefixpart=='MGI:',"
        "Accession.preferred==1,"
        "Accession._logicaldb_key==1,"
        "Accession._mgitype_key==%d)" % _mgitype_key,
        foreign_keys="[Accession._object_key]",
        uselist=False)

    featuretype_vocterms = db.relationship(
        "VocTerm",
        primaryjoin="and_(MarkerMCVCache._marker_key==Marker._marker_key,"
        "MarkerMCVCache.qualifier=='D')",
        secondary=MarkerMCVCache.__table__,
        foreign_keys="[MarkerMCVCache._marker_key, MarkerMCVCache._mcvterm_key]"
    )

    secondary_mgiids = db.relationship(
        "Accession",
        primaryjoin="and_(Accession._object_key==Marker._marker_key,"
        "Accession.preferred==0,"
        "Accession.prefixpart=='MGI:',"
        "Accession._logicaldb_key==1,"
        "Accession._mgitype_key==%s)" % _mgitype_key,
        foreign_keys="[Accession._object_key]",
        order_by="Accession.accid")

    biotype_sequences = db.relationship(
        "SeqMarkerCache",
        primaryjoin="and_(SeqMarkerCache._marker_key==Marker._marker_key,"
        "SeqMarkerCache.rawbiotype!=None)",
        foreign_keys="[SeqMarkerCache._marker_key]",
        order_by="SeqMarkerCache._logicaldb_key,SeqMarkerCache.accid")

    locations = db.relationship(
        "MarkerLocationCache",
        primaryjoin="Marker._marker_key==MarkerLocationCache._marker_key",
        foreign_keys="[MarkerLocationCache._marker_key]")

    synonyms = db.relationship(
        "Synonym",
        primaryjoin="and_(Marker._marker_key==Synonym._object_key, "
        "Synonym._mgitype_key==%d)" % _mgitype_key,
        order_by="Synonym.synonym",
        foreign_keys="[Synonym._object_key]")

    detailclipchunks = db.relationship(
        "MarkerDetailClipNoteChunk",
        primaryjoin="MarkerDetailClipNoteChunk._marker_key==Marker._marker_key",
        order_by="MarkerDetailClipNoteChunk.sequencenum",
        foreign_keys="[MarkerDetailClipNoteChunk._marker_key]")

    # only direct references via mgi_reference_assoc
    explicit_references = db.relationship(
        "Reference",
        secondary=ReferenceAssoc.__table__,
        primaryjoin="and_(Marker._marker_key==ReferenceAssoc._object_key, "
        "ReferenceAssoc._mgitype_key==%d)" % _mgitype_key,
        secondaryjoin="ReferenceAssoc._refs_key==Reference._refs_key",
        foreign_keys="[Marker._marker_key,Reference._refs_key]",
        backref="explicit_markers")

    # all marker references
    all_references = db.relationship("Reference",
                                     secondary=MarkerReferenceCache.__table__,
                                     backref="all_markers")

    expression_assays = db.relationship(
        "Assay",
        primaryjoin="Marker._marker_key==Assay._marker_key",
        foreign_keys="[Assay._marker_key]",
        backref=db.backref("marker", uselist=False))

    # antibodies
    # backref defined in Antibody class

    # antibodypreps
    # backref in AntibodyPrep class

    # mapping_experiment_assocs
    # backref in ExperimentMarkerAssoc class

    # sequences
    # backref in Sequence class

    @classmethod
    def has_explicit_references(self):
        q = self.query.filter(Marker.explicit_references.any())
        return db.object_session(self).query(db.literal(True)) \
            .filter(q.exists()).scalar()

    @property
    def has_biotypeconflict(self):
        """
        Requires loading self.biotype_sequences
        """
        conflict = False
        if self.biotype_sequences:

            for seq_cache in self.biotype_sequences:

                if seq_cache._biotypeconflict_key == self._biotypeconflict_yes_key:
                    conflict = True

        return conflict

    @property
    def featuretype(self):
        featuretype = ''
        if self.featuretype_vocterms:
            featuretype = ", ".join(
                [t.term for t in self.featuretype_vocterms])
        return featuretype

    @property
    def secondaryids(self):
        ids = [a.accid for a in self.secondary_mgiids]
        return ids

    @property
    def replocation(self):
        return self.locations and self.locations[0] or None

    @property
    def detailclipnote(self):
        return "".join([nc.note for nc in self.detailclipchunks])

    def __repr__(self):
        return "<Marker %s>" % self.symbol
Exemplo n.º 12
0
class Reference(db.Model, MGIModel):
    __tablename__ = "bib_refs"
    _refs_key = db.Column(db.Integer, primary_key=True)
    _reviewstatus_key = db.Column(db.Integer())
    # hide the join key from views
    _reviewstatus_key.hidden = True
    reftype = db.Column(db.String())
    authors = db.Column(db.String())
    _primary = db.Column(db.String())
    title = db.Column(db.String())
    # this is a way to fix unicode.decode errors, but has a slight performance cost
    abstract = db.Column(
        db.String(convert_unicode='force', unicode_error="ignore"))
    #abstract = db.Column(db.String())
    journal = db.Column(db.String())
    year = db.Column(db.Integer())
    date = db.Column(db.Integer())
    nlmstatus = db.Column(db.String())
    isreviewarticle = db.Column(db.Integer())
    #date.quote=False
    vol = db.Column(db.Integer())
    issue = db.Column(db.Integer())
    pgs = db.Column(db.Integer())

    # constants
    _mgitype_key = 1

    # mapped columns
    #jnumid = db.Column(db.String())
    jnumid = db.column_property(
        db.select([Accession.accid]). \
        where(db.and_(Accession._mgitype_key==_mgitype_key,
            Accession.prefixpart=='J:',
            Accession._object_key==_refs_key))
    )
    #pubmedid = db.Column(db.String())
    pubmedid = db.column_property(
         db.select([Accession.accid]). \
         where(db.and_(Accession._mgitype_key==_mgitype_key,
             Accession._logicaldb_key==29,
             Accession._object_key==_refs_key))
     )
    reviewstatus = db.column_property(
        db.select([ReviewStatus.name]). \
        where(ReviewStatus._reviewstatus_key==_reviewstatus_key)
    )

    # Relationships

    # accessions
    # backref defined in Accession class

    jnumid_object = db.relationship(
        "Accession",
        primaryjoin="and_(Accession._object_key==Reference._refs_key,"
        "Accession.prefixpart=='J:',"
        "Accession.preferred==1,"
        "Accession._logicaldb_key==1,"
        "Accession._mgitype_key==%d)" % _mgitype_key,
        foreign_keys="[Accession._object_key]",
        uselist=False)

    pubmedid_object = db.relationship(
        "Accession",
        primaryjoin="and_(Accession._object_key==Reference._refs_key,"
        "Accession.preferred==1,"
        "Accession._logicaldb_key==29,"
        "Accession._mgitype_key==%d)" % _mgitype_key,
        foreign_keys="[Accession._object_key]",
        uselist=False)

    # explicit_alleles
    # backref defined in Allele class

    # explicit_markers
    # backref defined in Marker class

    # all_markers
    # backref defined in Marker class

    experiment_notechunks = db.relationship("MLDReferenceNoteChunk")

    expression_assays = db.relationship(
        "Assay",
        primaryjoin="Reference._refs_key==Assay._refs_key",
        foreign_keys="[Assay._refs_key]",
        backref=db.backref("reference", uselist=False))

    # mapping_experiments
    # backref in MappingExperiment class

    # antibodypreps
    # backref in AntibodyPrep class

    @property
    def citation(self):
        authors = self.authors or ''
        title = self.title or ''
        journal = self.journal or ''
        rdate = self.date or ''
        vol = self.vol or ''
        issue = self.issue or ''
        pgs = self.pgs or ''

        return "%s, %s, %s %s;%s(%s):%s"% \
            (authors,title,journal, \
            rdate,vol,issue,pgs)

    @property
    def experimentnote(self):
        return "".join([nc.note for nc in self.experiment_notechunks])

    @property
    def short_citation(self):
        primary = self._primary or ''
        journal = self.journal or ''
        rdate = self.date or ''
        vol = self.vol or ''
        issue = self.issue or ''
        pgs = self.pgs or ''
        return "%s, %s %s;%s(%s):%s" % (primary, journal, rdate, vol, issue,
                                        pgs)

    def __repr__(self):
        return "<Reference %s,%s>" % (self.title, self.authors)