示例#1
0
class Table(db.Model):

    pmid = db.Column(db.Integer, primary_key=True)
    doi = db.Column(db.String(200))
    title = db.Column(db.String(1000))
    authors = db.Column(db.String(1000))
    journal = db.Column(db.String(200))
    study = db.relationship('Study', backref=db.backref('tables'))
    peaks = db.relationship('Peak',
                            backref=db.backref('table', lazy='joined'),
                            lazy='dynamic')
    analyses = association_proxy('frequencies', 'analyses')
示例#2
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'))
示例#3
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')
示例#4
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]
示例#5
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'
    }
示例#6
0
class Gene(db.Model):

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(200))
    symbol = db.Column(db.String(20), unique=True)
    locus_type = db.Column(db.String(40))
    synonyms = db.Column(db.String(200))
    images = db.relationship('GeneImage',
                             backref=db.backref('gene', lazy='joined'),
                             lazy='dynamic')
示例#7
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)
示例#8
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)
示例#9
0
class Location(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    x = db.Column(db.Float)
    y = db.Column(db.Float)
    z = db.Column(db.Float)
    location_analysis = association_proxy('location_analysis',
                                          'LocationAnalysis')
    images = db.relationship(
        'LocationImage', backref=db.backref('location', lazy='joined'))

    def __init__(self, x, y, z):
        self.x = x
        self.y = y
        self.z = z
示例#10
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)
示例#11
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]
示例#12
0
class Study(db.Model):

    pmid = db.Column(db.Integer, primary_key=True)
    doi = db.Column(db.String(200))
    title = db.Column(db.String(1000))
    authors = db.Column(db.String(1000))
    journal = db.Column(db.String(200))
    year = db.Column(db.Integer)
    space = db.Column(db.String(10))
    peaks = db.relationship('Peak',
                            backref=db.backref('study', lazy='joined'),
                            lazy='dynamic')
    analyses = association_proxy('frequencies', 'analysis')

    # analyses = association_proxy('inclusions', 'analysis')

    def serialize(self):
        return {
            'pmid': self.pmid,
            'authors': self.authors,
            'journal': self.journal,
            'year': self.year,
            'title': '<a href="/studies/%s">%s</a>' % (self.pmid, self.title)
        }