Simplified Data Visualization #1

This is a simple Python script that uses the MySQLdb module and AFNI’s DriveSuma program for querying a database and taking jpeg snapshots to get an immediate representation of surface data. This particular code iterates over a set of subjects – established here via an environment variable called “LV_SS_LIST” that is a list of subject number identifiers for a particular group of subjects that were given the same experimental stimuli. The query:
select emblemfemlh.voxel, round(speechT,4) from emblemfemlh where speechT > 1.796 and subject = "+ss+";"
selects the voxel and a T value for the speech condition “speechT” with the parameters that those T values are greater than a threshold (1.796) for each subject.

#!/usr/bin/python
# this is to get query output onto SUMA brains

import commands
import os
import sys
import MySQLdb

subjs = os.getenv("LV_SS_LIST").split()

os.system("suma -niml &" )
os.system("DriveSuma -com show_surf -label mamba -i_fs $SUBJECTS_DIR/HORRY/SUMA/HORRY.lh.mesh140_std.smoothwm.asc -com viewer_cont -load_view $gpfsemb/sweetview.niml.vvs -key ctrl+right -key R" )

#--------------------------- connection mechanism, query and creation of tmp file ---------------
try:
        connection = MySQLdb.connect(db = "yourdb",read_default_file="~/.my.cnf" )
except MySQLdb.Error, e:
        print "Error %d: %s" % (e.args[0], e.args[1])
        sys.exit (1)

for ss in subjs:
        id = commands.getoutput("echo $$" )
        outfile = "/tmp/outfile."+id+".threshd"+ss+".1D"
        query = "select emblemfemlh.voxel, round(speechT,4) from emblemfemlh where speechT > 1.796 and subject = "+ss+";"
        cursor = connection.cursor()
        cursor.execute(query)
        result = list(cursor.fetchall())
        bully = ''
        for rr in list(result):
                bully += (str(rr[0])+" "+str(rr[1]))+"\n"

        file = open(outfile,"w" )
        file.write(bully)
        file.close()
        os.system("DriveSuma -com surf_cont -load_dset "+outfile+" -com surf_cont -1_only y -I_sb 1 -I_range 10 -switch_cmap afni_p11 -com recorder_cont -save_as "+outfile+".jpg" )

#---------------------------- kill suma below ----------------
os.system("DriveSuma -com kill_suma" )

Leave a Reply