示例#1
0
class Download(db.Model):
    ''' Track all image downloads. '''
    id = db.Column(db.Integer, primary_key=True)
    image_id = db.Column(db.Integer, db.ForeignKey(Image.id))
    image = db.relationship(Image,
                            backref=db.backref('downloads',
                                               cascade='all, delete-orphan'))
    ip = db.Column(db.String(15))
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    user_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=True)
    user = db.relationship(User,
                           backref=db.backref('downloads',
                                              cascade='all, delete-orphan'))
示例#2
0
class Frequency(db.Model):
    analysis_id = db.Column(db.Integer,
                            db.ForeignKey('analysis.id'),
                            primary_key=True)
    pmid = db.Column(db.Integer, db.ForeignKey('study.pmid'), primary_key=True)
    frequency = db.Column(db.Float, default=1.)
    analysis = db.relationship(
        'Analysis',
        backref=db.backref('frequencies', cascade='all, delete-orphan'),
        lazy='joined')
    study = db.relationship('Study',
                            backref=db.backref('frequencies',
                                               cascade='all, delete-orphan'),
                            lazy='joined')
示例#3
0
class Analysis(db.Model):

    __tablename__ = 'analysis'
    id = db.Column(db.Integer, primary_key=True)
    analysis_set_id = db.Column(db.Integer, db.ForeignKey(AnalysisSet.id))
    name = db.Column(db.String(100), unique=False)
    n_studies = db.Column(db.Integer, default=0)
    n_activations = db.Column(db.Integer, default=0)
    description = db.Column(db.Text)
    type = db.Column(db.String(50))
    studies = association_proxy('frequencies', 'study')
    # images = db.relationship('AnalysisImage', backref=db.backref('analysis', lazy='joined'), lazy='dynamic')
    analysis_set = db.relationship('AnalysisSet', backref=db.backref(
        'analyses', cascade='all'))
    display = db.Column(db.Boolean)
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.datetime.utcnow,
                           onupdate=datetime.datetime.utcnow)

    __mapper_args__ = {
        'polymorphic_identity': 'analysis',
        'polymorphic_on': type
    }

    @property
    def reverse_inference_image(self):
        """ Convenience method for accessing the reverse inference image. """
        return self.images[1]
示例#4
0
class TermAnalysis(Analysis):
    __tablename__ = 'term_analysis'
    id = db.Column(db.Integer, db.ForeignKey('analysis.id'), primary_key=True)
    images = db.relationship('TermAnalysisImage', backref=db.backref('analysis',
                             cascade='all'))
    cog_atlas = db.Column(db.Text, nullable=True)  # Cognitive Atlas RDF data
    __mapper_args__ = {
        'polymorphic_identity': 'term'
    }
示例#5
0
class DecodingSet(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    analysis_set_id = db.Column(db.Integer,
                                db.ForeignKey(AnalysisSet.id),
                                nullable=True)
    analysis_set = db.relationship(AnalysisSet,
                                   backref=db.backref('decoding_set'))
    name = db.Column(db.String(20))
    n_images = db.Column(db.Integer)
    n_voxels = db.Column(db.Integer)
    is_subsampled = db.Column(db.Boolean)
示例#6
0
class Decoding(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    url = db.Column(db.String(255), nullable=True)
    neurovault_id = db.Column(db.String(100), nullable=True)
    filename = db.Column(db.String(200))
    uuid = db.Column(db.String(32), unique=True)
    name = db.Column(db.String(200))
    comments = db.Column(db.Text, nullable=True)
    display = db.Column(db.Boolean)
    download = db.Column(db.Boolean)
    _data = db.Column('data', db.Text, nullable=True)
    ip = db.Column(db.String(15))
    created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)
    image_decoded_at = db.Column(db.DateTime,
                                 onupdate=datetime.datetime.utcnow)
    image_modified_at = db.Column(db.DateTime, nullable=True)

    # Relationships
    decoding_set_id = db.Column(db.Integer, db.ForeignKey(DecodingSet.id))
    decoding_set = db.relationship(DecodingSet,
                                   backref=db.backref(
                                       'decodings',
                                       cascade='all, delete-orphan'))
    image_id = db.Column(db.Integer, db.ForeignKey(Image.id), nullable=True)
    image = db.relationship(Image,
                            backref=db.backref('decodings',
                                               cascade='all, delete-orphan'))
    user_id = db.Column(db.Integer, db.ForeignKey(User.id), nullable=True)
    user = db.relationship(User,
                           backref=db.backref('uploads',
                                              cascade='all, delete-orphan'))

    @hybrid_property
    def data(self):
        return json.loads(self._data)

    @data.setter
    def data(self, value):
        self._data = json.dumps(value)
示例#7
0
class CustomAnalysis(Analysis):

    __tablename__ = 'custom_analysis'
    id = db.Column(db.Integer, db.ForeignKey('analysis.id'), primary_key=True)
    uuid = db.Column(db.String(32), unique=True)
    ip = db.Column(db.String(15))
    images = db.relationship('CustomAnalysisImage', backref=db.backref('analysis',
                             cascade='all'))
    user_id = db.Column(db.Integer, db.ForeignKey(User.id))
    user = db.relationship(User, backref=db.backref('analyses',
                           cascade='all'))
    private = db.Column(db.Boolean, default=False)

    last_run_at = db.Column(db.DateTime)
    __mapper_args__ = {
        'polymorphic_identity': 'custom'
    }

    def serialize(self):
        return dict(id=self.id, uuid=self.uuid, name=self.name,
                    description=self.description,
                    studies=[f.pmid for f in self.studies],
                    private=self.private, user=self.user.username)
示例#8
0
class TopicAnalysis(Analysis):

    __tablename__ = 'topic_analysis'
    id = db.Column(db.Integer, db.ForeignKey('analysis.id'), primary_key=True)
    terms = db.Column(db.Text)
    number = db.Column(db.Integer)
    images = db.relationship('TopicAnalysisImage', backref=db.backref('analysis',
                             cascade='all'))
    __mapper_args__ = {
        'polymorphic_identity': 'topic'
    }

    @property
    def reverse_inference_image(self):
        """ Convenience method for accessing the reverse inference image. """
        return self.images[1]
示例#9
0
class Peak(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    pmid = db.Column(db.Integer, db.ForeignKey('study.pmid'))
    table = db.Column(db.String(10))
    x = db.Column(db.Float)
    y = db.Column(db.Float)
    z = db.Column(db.Float)

    @classmethod
    def closestPeaks(cls, radius, x, y, z):
        '''
        Returns an optimized query using euclidean distance to find closest peaks within a radius of x, y, z
        '''
        # find peaks in a box then run heavier euclidean distance formula on what's left
        return Peak.query.filter(
            cls.x <= x + radius, cls.x >= x - radius, cls.y <= y + radius,
            cls.y >= y - radius, cls.z <= z + radius, cls.z >= z - radius,
            (x - cls.x) * (x - cls.x) + (y - cls.y) * (y - cls.y) +
            (z - cls.z) * (z - cls.z) <= radius**2)
示例#10
0
class GeneImage(Image):
    __mapper_args__ = {'polymorphic_identity': 'gene'}
    gene_id = db.Column(db.Integer, db.ForeignKey(Gene.id), nullable=True)
示例#11
0
class TopicAnalysisImage(Image):
    __mapper_args__ = {'polymorphic_identity': 'topic'}
    topic_analysis_id = db.Column(db.Integer, db.ForeignKey(TopicAnalysis.id), nullable=True)
示例#12
0
class LocationImage(Image):
    __mapper_args__ = {'polymorphic_identity': 'location'}
    location_id = db.Column(db.Integer, db.ForeignKey(Location.id), nullable=True)
示例#13
0
class CustomAnalysisImage(Image):
    __mapper_args__ = {'polymorphic_identity': 'custom'}
    custom_analysis_id = db.Column(db.Integer, db.ForeignKey(CustomAnalysis.id), nullable=True)