Esempio n. 1
0
def make_location(x, y, z):

    location = Location(x, y, z)

    # Add Neurosynth coactivation image if it exists
    filename = 'metaanalytic_coactivation_%d_%d_%d_pFgA_z_FDR_0.01.nii.gz' % (
        x, y, z)
    filename = join(settings.IMAGE_DIR, 'coactivation', filename)
    if not exists(filename):
        tasks.make_coactivation_map.delay(x, y, z).wait()
    if exists(filename):
        ma_image = LocationImage(
            name='Meta-analytic coactivation for seed (%d, %d, %d)' % (
                x, y, z),
            image_file=filename,
            label='Meta-analytic coactivation',
            stat='z-score',
            display=1,
            download=1,
            description='This image displays regions coactivated with the seed'
            ' region across all studies in the Neurosynth database. It '
            'represents meta-analytic coactivation rather than time '
            'series-based connectivity.'
        )
        location.images.append(ma_image)

    # Add Yeo FC image if it exists
    filename = join(settings.IMAGE_DIR, 'fcmri',
                    'functional_connectivity_%d_%d_%d.nii.gz' % (x, y, z))
    if exists(filename):
        fc_image = LocationImage(
            name='YeoBucknerFCMRI for seed (%d, %d, %d)' % (x, y, z),
            image_file=filename,
            label='Functional connectivity',
            stat='corr. (r)',
            description='This image displays resting-state functional '
            'connectivity for the seed region in a sample of 1,000 subjects. '
            'To reduce blurring of signals across cerebro-cerebellar and '
            'cerebro-striatal boundaries, fMRI signals from adjacent cerebral '
            'cortex were regressed from the cerebellum and striatum. For '
            'details, see '
            '<a href="http://jn.physiology.org/content/106/3/1125.long">Yeo et'
            'al (2011)</a>, <a href="http://jn.physiology.org/cgi/pmidlookup?'
            'view=long&pmid=21795627">Buckner et al (2011)</a>, and '
            '<a href="http://jn.physiology.org/cgi/pmidlookup?view=long&'
            'pmid=22832566">Choi et al (2012)</a>.',
            display=1,
            download=1
        )
        location.images.append(fc_image)

    db.session.add(location)
    db.session.commit()

    # Decode both images
    for img in location.images:
        decode_analysis_image(img.id)

    return location
Esempio n. 2
0
def get_decoding():
    """
    Retrieve decoding data for a single image
    ---
    tags:
        - decode
    responses:
        200:
            description: Decoding data
        default:
            description: Decoding not found
    parameters:
        - in: query
          name: uuid
          description: UUID of the decoding
          required: false
          type: string
        - in: query
          name: image
          description: ID of image to decode
          type: integer
          required: false
        - in: query
          name: neurovault
          description: NeuroVault ID of image to decode
          type: integer
          required: false
        - in: query
          name: url
          description: URL of Nifti image to decode
          type: string
          required: false
    """
    dec = Decoding.query.filter_by(display=1)

    if 'uuid' in request.args:
        dec = dec.filter_by(uuid=request.args['uuid']).first()

    elif 'image' in request.args:
        dec = decode.decode_analysis_image(request.args['image'])

    elif 'neurovault' in request.args:
        dec_id = decode.decode_neurovault(request.args['neurovault'],
                                          render=False)
        dec = dec.filter_by(uuid=dec_id).first()

    elif 'url' in request.args:
        dec_id = decode.decode_url(request.args['url'], render=False)
        dec = dec.filter_by(uuid=dec_id).first()

    schema = DecodingSchema()
    return jsonify(data=schema.dump(dec).data)
Esempio n. 3
0
def get_decoding():
    """
    Retrieve decoding data for a single image
    ---
    tags:
        - decode
    responses:
        200:
            description: Decoding data
        default:
            description: Decoding not found
    parameters:
        - in: query
          name: uuid
          description: UUID of the decoding
          required: false
          type: string
        - in: query
          name: image
          description: ID of image to decode
          type: integer
          required: false
        - in: query
          name: neurovault
          description: NeuroVault ID of image to decode
          type: integer
          required: false
        - in: query
          name: url
          description: URL of Nifti image to decode
          type: string
          required: false
    """
    dec = Decoding.query.filter_by(display=1)

    if 'uuid' in request.args:
        dec = dec.filter_by(uuid=request.args['uuid']).first()

    elif 'image' in request.args:
        dec = decode.decode_analysis_image(request.args['image'])

    elif 'neurovault' in request.args:
        dec_id = decode.decode_neurovault(request.args['neurovault'],
                                          render=False)
        dec = dec.filter_by(uuid=dec_id).first()

    elif 'url' in request.args:
        dec_id = decode.decode_url(request.args['url'], render=False)
        dec = dec.filter_by(uuid=dec_id).first()

    schema = DecodingSchema()
    return jsonify(data=schema.dump(dec).data)
Esempio n. 4
0
def get_decoding_data(image, get_json=True):

    if Image.query.get(image) is None:
        return error_page("Invalid image requested for decoding. Please check"
                          " to make sure there is a valid image with id=%d." %
                          image)
    dec = decode_analysis_image(image)
    df = os.path.join(settings.DECODING_RESULTS_DIR, dec.uuid + '.txt')
    if not os.path.exists(df):
        return error_page("An unspecified error occurred during decoding.")
    data = open(df).read().splitlines()
    data = [x.split('\t') for x in data]
    data = [[f, round(float(v or '0'), 3)] for (f, v) in data]
    return jsonify(data=data) if get_json else data
Esempio n. 5
0
def get_decoding_data(image, get_json=True):

    if Image.query.get(image) is None:
        return error_page("Invalid image requested for decoding. Please check"
                          " to make sure there is a valid image with id=%d." %
                          image)
    dec = decode_analysis_image(image)
    df = os.path.join(settings.DECODING_RESULTS_DIR, dec.uuid + '.txt')
    if not os.path.exists(df):
        return error_page("An unspecified error occurred during decoding.")
    data = open(df).read().splitlines()
    data = [x.split('\t') for x in data]
    data = [[f, round(float(v or '0'), 3)] for (f, v) in data]
    return jsonify(data=data) if get_json else data
Esempio n. 6
0
def show(symbol):
    gene = Gene.query.filter_by(symbol=symbol).first()
    if gene is None:
        return error_page("We have no data for the gene '%s'" % symbol)
    image = gene.images[0]
    # Run decoder if it hasn't been run before
    dec = decode_analysis_image(image.id)
    url = '/images/%s' % image.id
    images = [{
        'id': image.id,
        'name': symbol,
        'url':  url,
        'colorPalette': 'intense red-blue',
        'download': url,
        'sign': 'both'
    }]
    return render_template('genes/show.html.slim', gene=gene,
                           images=json.dumps(images), image_id=dec.uuid)
Esempio n. 7
0
def show(symbol):
    gene = Gene.query.filter_by(symbol=symbol).first()
    if gene is None:
        return error_page("We have no data for the gene '%s'" % symbol)
    image = gene.images[0]
    # Run decoder if it hasn't been run before
    dec = decode_analysis_image(image.id)
    url = '/images/%s' % image.id
    images = [{
        'id': image.id,
        'name': symbol,
        'url': url,
        'colorPalette': 'intense red-blue',
        'download': url,
        'sign': 'both'
    }]
    return render_template('genes/show.html.slim',
                           gene=gene,
                           images=json.dumps(images),
                           image_id=dec.uuid)