class BioObject(db.Model): __tablename__ = "bioobject" # Add table name to be None __mapper_args__ = { 'polymorphic_identity': 'bioobject', 'polymorphic_on': 'type', } object_collection_id = db.Column(db.Integer, db.ForeignKey('bioobjectcollection.id')) collection = db.relationship(BioObjectCollection) type = db.Column(db.String(32))
class Synapse(BioObject): __tablename__ = None # Add table name to be None __mapper_args__ = {'polymorphic_identity': 'synapse'} oid = db.Column(db.String(50)) areas = db.Column( Geometry(geometry_type="MULTIPOLYGONZ", management=True, use_typmod=False, srid=SYNAPSE_SRID, dimension=3))
class SourceChannel(NamedModel, db.Model): __tablename__ = 'sourcechannel' volume_id = db.Column(db.Integer, db.ForeignKey('volume.id')) source_url = db.Column(db.String(250), nullable=False) default_channel = db.Column(db.Boolean, nullable=False, default=False) type = db.Column(db.String(32), default='image') __mapper_args__ = { 'polymorphic_on': 'type', 'polymorphic_identity': '' }
class Link(NamedModel, db.Model): __tablename__ = 'link' type = db.Column(db.String(32)) link = db.Column(db.String(10000)) __mapper_args__ = { 'polymorphic_on': 'type', 'polymorphic_identity': 'link' } def get_link_html(self): return '<a href="{}">{}</a>'.format(self.link, self.name)
class BioObjectCollection(NamedModel, db.Model): __tablename__ = 'bioobjectcollection' volume_id = db.Column(db.Integer, db.ForeignKey('volume.id')) volume = db.relationship('Volume') link_id = db.Column(db.Integer, db.ForeignKey('link.id')) link = db.relationship('Link') objects = db.relationship('BioObject') type = db.Column(db.String(32)) __mapper_args__ = { 'polymorphic_on': 'type', 'polymorphic_identity': 'employee' }
class RatingSource(NamedModel, db.Model): __tablename__ = "ratingsource" type = db.Column(db.String(32)) __mapper_args__ = { 'polymorphic_identity': 'ratingsource', 'polymorphic_on': 'type', }
class Rating(TimestampMixin, db.Model): __tablename__ = "rating" type = db.Column(db.String(32)) object_id = db.Column( db.Integer, db.ForeignKey('bioobject.id'), nullable=False, ) rating_source_id = db.Column( db.Integer, db.ForeignKey('ratingsource.id'), nullable=False, ) classificationtype_id = db.Column(db.Integer, db.ForeignKey('classificationtype.id'), nullable=False) confidence = db.Column(db.Float) classificationtype = db.relationship('ClassificationType') rating_source = db.relationship('RatingSource') object = db.relationship('BioObject') bool_rating = db.Column(db.Boolean) tert_rating = db.Column(db.Integer) def get_rating(self): '''generic function, need to implement for class''' pass __mapper_args__ = { 'polymorphic_identity': 'rating', 'polymorphic_on': 'type', }
class Volume(NamedModel, db.Model): channels = db.relationship('SourceChannel', backref='volume') dataset_id = db.Column(db.Integer, db.ForeignKey('data_set.id')) dataset = db.relationship('DataSet') links = db.relationship('VolumeLink', backref='volume') synapse_collections = db.relationship('SynapseCollection', backref='synvolume') def get_neuroglancer_layers(self): ds = [] for chan in self.channels: if chan.default_channel: d = { 'source': chan.source_url, 'blend': 'additive' } if chan.default_color: d['color'] = chan.default_color ds.append(d) return ds
class NamedModel(object): name = db.Column(db.String(100), nullable=False) def __repr__(self): return "{}({})".format(self.name, self.id)
class MachineLearningSource(RatingSource): algorithm = db.Column(db.String(100)) __tablename__ = None __mapper_args__ = { 'polymorphic_identity': 'machinelearning', }
class UserRatingSource(RatingSource): user_id = db.Column(db.Integer) __tablename__ = None __mapper_args__ = { 'polymorphic_identity': 'user', }
class SynapseCollection(BioObjectCollection): __tablename__ = None # Add table name to be None __mapper_args__ = {'polymorphic_identity': 'synapsecollection'} synapse_collection_type = db.Column(db.String(100))
class ClassificationType(NamedModel, db.Model): __tablename__ = "classificationtype" rating_type = db.Column(db.String(40))
class VolumeLink(Link): __tablename__ = None volume_id = db.Column(db.Integer, db.ForeignKey('volume.id')) __mapper_args__ = { 'polymorphic_identity': 'volumelink' }
class TimestampMixin(object): created = db.Column(db.DateTime, nullable=False, default=datetime.now()) updated = db.Column(db.DateTime, onupdate=datetime.now())
class ImageChannel(SourceChannel): __tablename__ = None default_color = db.Column(db.String(1)) __mapper_args__ = { 'polymorphic_identity': 'image' }
class ConsensusSource(RatingSource): rating_sources = db.Column(ARRAY(db.Integer)) __tablename__ = None __mapper_args__ = { 'polymorphic_identity': 'consensus', }
class DataSet(NamedModel, db.Model): render_project = db.Column(db.String(50)) render_owner = db.Column(db.String(50)) volumes = db.relationship('Volume', backref='data_set')