class ProjectMemship(db.Model): user_email = db.Column(db.String(120), db.ForeignKey('user.email'), primary_key=True) project_id = db.Column(db.Integer, db.ForeignKey('project.id'), primary_key=True) is_project_admin = db.Column(db.Boolean, nullable=False) def __repr__(self): return "<ProjectMemship - User: {} - Project: {}>".format( self.user_email, self.project_id)
class MarkerAllele(db.Model): marker = db.Column(db.String(15), db.ForeignKey('marker.id'), primary_key=True) allele = db.Column(db.String(1), primary_key=True) def __repr__(self): return "<MarkerAllele - Marker: {} - Allele: {}>".format( self.marker, self.allele)
class Genotype(db.Model): id = db.Column(db.Integer, primary_key=True) ind_id = db.Column(db.Integer, db.ForeignKey('individual.id'), nullable=False) marker = db.Column(db.String(20), db.ForeignKey('marker.id'), nullable=False) call_1 = db.Column(db.String(1), nullable=False) call_2 = db.Column(db.String(2), nullable=False) __table_args__ = (UniqueConstraint('ind_id', 'marker', name="_geno_uc"), {}) def __repr__(self): return "<Genotype - ID: {}>".format(self.id) @staticmethod def query_by_project(proj_id): subquery = db.session.query( Individual.id).filter_by(project_id=proj_id) return Genotype.query.filter(Genotype.ind_id.in_(subquery))
class Phenotype(db.Model): id = db.Column(db.Integer, primary_key=True) ind_id = db.Column(db.Integer, db.ForeignKey('individual.id'), nullable=False) name = db.Column(db.String(30), nullable=False) value = db.Column(db.String(50), nullable=False) __table_args__ = (UniqueConstraint('ind_id', 'name', name="_pheno_uc"), {}) def __repr__(self): return "<Phenotype - ID: {}>".format(self.id) @staticmethod def query_by_project(proj_id): subquery = db.session.query( Individual.id).filter_by(project_id=proj_id) return Phenotype.query.filter(Phenotype.ind_id.in_(subquery))
class Individual(db.Model): id = db.Column(db.Integer, primary_key=True) project_id = db.Column(db.Integer, db.ForeignKey('project.id'), nullable=False) clinic_id = db.Column(db.String(5), nullable=False) family_id = db.Column(db.String(15), nullable=False) member_id = db.Column(db.Integer, nullable=False) gender = db.Column(db.Integer, nullable=False) __table_args__ = (UniqueConstraint('project_id', 'clinic_id', 'family_id', 'member_id', name="_individual_uc"), {}) def __repr__(self): return "<Individual - ID: {}>".format(self.id) def get_full_id(self): return self.clinic_id + "_" + self.family_id + "_" + self.member_id