コード例 #1
0
def get_subjects(study, subjType, listPrefix):
    path = os.path.join('/cluster/kuperberg/SemPrMM/', 'MEG/')
    subject_filename = path + 'scripts/function_inputs/' + listPrefix + '.txt'

    subject_list = readInput.readList(subject_filename)
    all_subs = []
    for row in subject_list:
        row = subjType + row
        all_subs.append(row)

    return [sub for sub in all_subs if len(find_eves(study, sub)) > 0]
コード例 #2
0
def main(subjType, listPrefix, study):
        rt_ax_avg= []
        rt_ay_avg= []
        rt_bx_avg = []
        rt_by_avg = []
        for mod in modalities:
		##for study in studies:
			##subjects = get_subjects(mod,study,subjType)
                        subjects = readInput.readList('/cluster/kuperberg/SemPrMM/MRI/scripts/input/' +listPrefix)
			print(subjects)
			print(study)
			study_results, rt_ax_avg, rt_ay_avg, rt_bx_avg, rt_by_avg = parse_study(mod,study,subjects,listPrefix)
                        with open('/cluster/kuperberg/SemPrMM/MRI/results/behavioral_accuracy/'+mod+'_'+listPrefix+'_'+study+'_accuracy-short.log','w') as f:
				f.write('sub:\t')#write out header
				for code in code_names[study]:
					f.write(code+'\t')
				if study == 'AXCPT':
                                        f.write('AllTasks\tAX_RT\tAY_RT\tBX_RT\tBY_RT\n')
                                else:
                                        f.write('AllTasks\n')                                      
				for i, sub in enumerate(subjects):
                                #for i, sub in enumerate(sorted(study_results.keys(), reverse=True)):
					num = den = 0
					f.write(sub+':\t')
					results = study_results[sub]
					#sort codes numerically
					codes = sorted([int(key) for key in results.keys()])
					num = sum([item[0] for code,item in results.items() if int(code) in studies_tasks[study]])
					den = sum([item[1] for code,item in results.items() if int(code) in studies_tasks[study]])
					sorted_results = [float(results[str(code)][0])/float(results[str(code)][1]) for code in codes]
					for result in sorted_results:
				            f.write(str(round(result,3))+'\t')
					f.write(str(round(float(num)/den,3))+'\t')
					if study == 'AXCPT':
                                                f.write(str(rt_ay_avg[i])+'\t')
                                                f.write(str(rt_by_avg[i])+'\t')
                                                f.write(str(rt_bx_avg[i])+'\t')
                                                f.write(str(rt_ax_avg[i])+'\n')
                        mriaccuracy2R(mod,study,subjType, listPrefix)
        print("Completed. See results in /MRI/results/behavioral_accuracy/R/ folder")
コード例 #3
0
def maxFilter(subjID):

    ##constants
    corrThresh = .96
    sampleTime = 30

    expList = ['BaleenHP']

    runDict = {'BaleenHP': ['Run1', 'Run2', 'Run3', 'Run4']}

    dataPath = "/cluster/kuperberg/SemPrMM/MEG/data/" + subjID + "/"
    badChanFileName = dataPath + subjID + "_bad_chan.txt"
    badChanList = readInput.readList(badChanFileName)
    print badChanList

    badMEG = ''
    for chan in badChanList:
        if chan[0:3] == 'MEG':
            print chan[-4:]
            badMEG = badMEG + (chan[-4:]) + ' '

    for exp in expList:
        for run in runDict[exp]:
            in_fif_fname = dataPath + subjID + '_' + exp + run + '_raw.fif'
            out_fif_fname = dataPath + subjID + '_' + exp + run + '_MF_raw.fif'

            command = (
                'maxfilter -f %s -v -frame head -st %s -corr %s -origin 0 0 40 -bad %s -o %s -force'
                %
                (in_fif_fname, sampleTime, corrThresh, badMEG, out_fif_fname))

            print command
            st = os.system(command)
            print 'Command executed: %s' % command
            if st != 0:
                raise ValueError('Pb while running : %s' % command)
            else:
                print(
                    'Done computing maxFilter. IMPORTANT : Please eye-ball the data !!'
                )
コード例 #4
0
ファイル: maxFilter.py プロジェクト: KuperbergLab/MEG_scripts
def maxFilter(subjID):

	##constants
	corrThresh = .96
	sampleTime = 30
	
	expList = ['BaleenHP']
	
	runDict = {'BaleenHP':['Run1','Run2','Run3','Run4']}
	
	dataPath = "/cluster/kuperberg/SemPrMM/MEG/data/" + subjID + "/"
	badChanFileName = dataPath + subjID + "_bad_chan.txt"
	badChanList = readInput.readList(badChanFileName)
	print badChanList
	
	badMEG = ''
	for chan in badChanList:
		if chan[0:3] == 'MEG':
			print chan[-4:]
			badMEG = badMEG + (chan[-4:]) + ' '
	
	for exp in expList:
		for run in runDict[exp]:
			in_fif_fname = dataPath + subjID + '_' + exp + run + '_raw.fif'
			out_fif_fname = dataPath + subjID + '_' + exp + run + '_MF_raw.fif'
	
			command = ('maxfilter -f %s -v -frame head -st %s -corr %s -origin 0 0 40 -bad %s -o %s -force'
                   % (in_fif_fname, sampleTime, corrThresh, badMEG, out_fif_fname))
	
			print command
			st = os.system(command)
			print 'Command executed: %s' % command
			if st != 0:
				raise ValueError('Pb while running : %s' % command)
			else: 
				print ('Done computing maxFilter. IMPORTANT : Please eye-ball the data !!')
コード例 #5
0
colorList = ['k', 'r']
lWidth = 4

ymin, ymax = [-.5, 24]
xmin, xmax = [-100, 600]

data_path = '/cluster/kuperberg/SemPrMM/MEG/data/'
results_path = '/cluster/kuperberg/SemPrMM/MEG/results/sensor_level/MEG_rms/'
channel_path = '/cluster/kuperberg/SemPrMM/MEG/scripts/function_inputs/MEG_Chan_Names/grad_'
channelGroups = ['frontal', 'temporal', 'parietal', 'occipital']

hemList = ['L', 'R']

###Get subject list
subjFile = '/cluster/kuperberg/SemPrMM/MEG/scripts/function_inputs/' + args.prefix + '.txt'
subjects = readInput.readList(subjFile)
print subjects
#subjects = ['1', '2','3']

for group in channelGroups:
    pl.clf()
    font = {'size': 30}
    pl.rc('font', **font)

    for hem in hemList:

        channelFile = channel_path + hem + group + '.txt'
        channelNames = readInput.readList(channelFile)
        channelList = []
        for item in channelNames:
            channelList.append('MEG ' + item)
コード例 #6
0
def spanData2R(subjType, listPrefix):
        data_path = '/cluster/kuperberg/SemPrMM/assessment/'
        inFile1 = data_path + 'scripts/function_input/' + str(listPrefix) + '.txt'  
        inFile2 = data_path + 'span/Input/' + 'WM-SpanLog_' + str(subjType)  
        outFile1 = data_path + 'results/span/R/' + str(listPrefix) + '_WM-Span_Long.txt'  

        
##     if (subjType == 'ac'):
##         subject_filename = data_path + 'scripts/function_inputs/ac.meg.all.txt'
##     if (subjType == 'sc'):
##         subject_filename = data_path + 'scripts/function_inputs/sc.meg.all.txt'
##     if (subjType == 'ya'):
##         subject_filename = data_path + 'scripts/function_inputs/ya.meg.all.txt'
        subject_list = readInput.readList(inFile1)
        ##print subject_list
##
        for subject in subject_list:
            print subject
  
#To Find the total number of rejected trials, and percentage inclusion
        #subjID = str(subjType)+ str(subject)
        totalTrials = 0 # Must be initialised within the loop to refresh for each subject :) 
        dataTable1=[]
        dataTable2=[]
        lineTemp = []
        lineTemp1 = []
        temp = 1
        header = []

         
        if os.path.exists(inFile1):
            print("File exists")
        else:
            print("Check the input file name")
    
        myFile1 = open(inFile2, "r") 
        while temp:
             temp = myFile1.readline()
             temp1 = temp.strip() # not ('')
             if temp1:
                  temp2 = temp1.split()
                  dataTable1.append(temp2) # Save information as a list of items in a DataTable
                  runCount=len(dataTable1)   
        myFile1.close()

        header = dataTable1[0]
        span_len = len(header)
        #print(runCount)
        #print(span_len)

        myFile2 = open(outFile1, "w")
        myFile2.write("Sub:\t\tSpan\t\tNumCorrect\n")	
        for i in range(1, runCount):
               lineTemp = (dataTable1[i])
               ##print(lineTemp)
               #print(lineTemp[0])
               for j in range(1,span_len):
                     if str(lineTemp[0]) in subject_list: # Compares the subject name to check if it exists in the listPrefix file. 
                                               
                          myFile2.write(lineTemp[0] + '\t\t')
                          myFile2.write(header[j] + '\t\t')
                          myFile2.write(lineTemp[j])
                          myFile2.write('\n')
        print("Completed. See result in /assessment/results/span/R/ folder")
コード例 #7
0
##Define data file names
data_path = '/Volumes/CUTTLEFISH/MEG_Experiments/'+args.exp+'/data/'+args.subjID + '/' 
raw_fname = data_path + args.subjID + '_' + args.par + '-Filtered_raw.fif'
outfile_fname = data_path + 'rej/' + args.subjID + '_' + args.par + '-Filtered_raw_blink.txt'
badChan_fname = data_path + args.subjID + '_bad_chan.txt'


##Define default parameters
thresh = 3e-13
blinkChanList = [0, 1, 2, 21, 22, 23, 24, 41, 42, 43, 44, 59, 60, 61, 62, 63, 82, 83, 84, 100] # starts at 0 for python
winSize = 100  #ms on each side of test sample


##Read in a subject-specific threshold, if it exists
if os.path.isfile(data_path + 'rej/rej_thr.txt'):
	thrString = readInput.readList(data_path + 'rej/rej_thr.txt')
	thrList = thrString[0].split()
	thresh = float(thrList[1])

print
print 'Threshold used is:',thresh
print


##Read in raw data (158 channels x time samples)
raw = fiff.Raw(raw_fname)
ch_names = raw.info['ch_names']


##Read in a subject-specific blink-channel list, if it exists
if os.path.isfile(data_path + 'rej/' + args.subjID + '_rej_chan.txt'):
コード例 #8
0
ymin = -1e-13
ymax = 1e-13




##Filenames

filename = '/Volumes/CUTTLEFISH/MEG_Experiments/'+args.exp+'/results/Quadrants/'+args.par+'_'+args.subjList+'_'+'quadTest.txt'
myFile = open(filename, "w")
myFile.close()	

quadList = ['LA','LP','RA','RP']


subjList = readInput.readList('/Volumes/CUTTLEFISH/MEG_Experiments/'+args.exp + '/subjLists/'+ args.subjList + '.txt')
print subjList[0]

for subj in subjList:
	#initialize structure to hold data for each condition
	quadData = {}
	for cond in args.condList:
		quadData[cond] = []

	data_path = '/Volumes/CUTTLEFISH/MEG_Experiments/'+args.exp+'/data/'+subj + '/'
	data_file = data_path + subj + '_' + args.par 
	print data_file

	quadCount = 0
	for quad in quadList:
	
コード例 #9
0
##Set the factors to examine
protocolList = ['MaskedMM_All', 'MaskedMM_All', 'MaskedMM_All']
condList = ['1', '2', '3']
hemList = ['lh','rh']
#labelList = ['G_front_inf-Opercular', 'G_front_inf-Triangul','G_front_inf-Orbital', 'Pole_temporal', 'G_temp_ant-sup-Lateral','G_temp_post-sup-Lateral','S_temporal_ant-sup','S_temporal_post-sup','G_temporal_ant-middle','G_temporal_post-middle','G_temporal_inf','S_temporal_inf','G_pariet_inf-Angular','G_temp_sup-Plan_polar','aparc2009-aMTGSTS','aparc2009-pMTGSTS','aparc2009-IFG','aparc2009-aMTGSTSTP','ya.n24.bal.BaleenHP_300-500_cluster']
labelList = ['aparc-IFG','aparc-pMTGSTS']

##Convert input times from ms to samples
baseline=100 #ms
sample1 = int( round( (args.t1+baseline)/1.6667 ) )
sample2 = int( round( (args.t2+baseline)/1.6667 ) )

###Get subject list
subjFile = '/cluster/kuperberg/SemPrMM/MEG/scripts/function_inputs/' + args.prefix + '.txt'
subjects = readInput.readList(subjFile)
print subjects



###################################
########MAKE DATA TABLE############
###################################


dataTable = []

for x in range(3):
	print protocolList[x]
	
	for label in labelList:
コード例 #10
0
channelGroups = ['ant','post']
hemList = ['left','right']

pl.clf()
for group in channelGroups:
	
	font = {
         'weight' : 'bold',
         'size'   : 16}
	pl.rc('font', **font)
	#figure(num=None, figsize=(16, 6), dpi=80, facecolor='w', edgecolor='k') # you could use this to change the size of the figure

	for hem in hemList:
	
		channelFile = channel_path + hem + '_' + group+ '.txt'
		channelList = readInput.readList(channelFile)
	    
		if hem == 'left':
		    if group == 'ant':
		       pl.subplot(2,2,1)
		       pl.title("Left Anterior")
		    else:
		       pl.subplot(2,2,3)
		       pl.title("Left Posterior")
		else:
		    if group == 'ant':
		       pl.subplot(2,2,2)
		       pl.title("Right Anterior")
		    else:
		       pl.subplot(2,2,4)
		       pl.title("Right Posterior")
コード例 #11
0
args = parser.parse_args()


if args.baseline:
    if args.baseline not in args.condList:
        sys.exit("Error: Baseline condition does not exist. It must be from condList")


##Filenames
data_path = "/Volumes/CUTTLEFISH/MEG_Experiments/" + args.exp + "/data/" + args.subjID + "/"
data_file = data_path + args.subjID + "_" + args.par

print data_path
print data_file

chans = readInput.readList(data_path + "/sensor_list/" + args.chan_filename + ".txt")
chans = [int(chan) for chan in chans]
print "actual chans as shown in MNE: {}".format(chans)

chans = [chan - 1 for chan in chans]  # this accounts for python indexing at 0
print "chans as interpreted by iPython: {}".format(chans)


##Plot condition(s)
cm = plt.get_cmap("cool")  # this chooses the colors to use for data lines
fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_color_cycle([cm(1.0 * i / len(args.condList)) for i in range(len(args.condList))])
for cond in args.condList:

    condName = cond
コード例 #12
0
                all_data[k][sub] = v
        except IOError:
            pass
    return all_data


if __name__ == '__main__':
    data_path = '/cluster/kuperberg/SemPrMM/MEG/'
    subjType = sys.argv[1]
    if (subjType == 'ac'):
        subject_filename = data_path + 'scripts/function_inputs/ac.meg.all.txt'
    if (subjType == 'sc'):
        subject_filename = data_path + 'scripts/function_inputs/sc.n16.meeg.b.txt'
    if (subjType == 'ya'):
        subject_filename = data_path + 'scripts/function_inputs/ya.meg.all.possible.txt'
    subject_list = readInput.readList(subject_filename)
    subjects = []
    for row in subject_list:
        row = subjType + row
        subjects.append(row)
    print subjects

    all_data = get_data(subjects)
    for k, v in all_data.items():
        #print k, v
        ##Note:
        fname = '/%s/kuperberg/SemPrMM/MEG/results/artifact_rejection/heogveog_rejection/%s_%s_rejTable.txt' % (
            pre, subjType, k)
        codes = sorted(v[subjType + '12'].keys(),
                       cmp=lambda x, y: cmp(int(x), int(y))
                       )  ##using subject ID 12 to retrieve item codes
コード例 #13
0
args=parser.parse_args()

##Get the condCode information
sys.path.insert(0,'/Volumes/CUTTLEFISH/MEG_Experiments/'+args.exp + '/')
fileName =args.exp+'_condCodes'
print fileName
cc = __import__(fileName) ##importing condCodes


##Initialize path variables and read subject list
expPath = '/Volumes/CUTTLEFISH/MEG_Experiments/'+args.exp+'/'
data_path = expPath + 'data/'
results_path = expPath +'results/'

subjList = readInput.readList(expPath + 'subjLists/' + args.subjList+'.txt')	


##create structure for mne python to call all the conditions up
labelList = cc.condLabels[args.par]
# dictionary from trigger to condition sorted by trigger number
event_id = collections.OrderedDict(sorted(labelList, key=lambda item : item[0]))
print event_id

numCond = len(event_id)
#initialize structures needed to create grand average
allData = [ [] for item in range(numCond) ]  ##channel x time MEG data
allNave = [ [] for item in range(numCond) ]  ##number of trials per condition in ave


###################################################################################
コード例 #14
0
def computeEvents(subjType, par):
    data_path = '/cluster/kuperberg/SemPrMM/MEG/'
    outFile = data_path + 'results/artifact_rejection/megeeg_rejection/' + str(
        subjType) + '_MEEGArtRejSummary_' + str(par)
    myFile2 = open(outFile, "w")

    if (subjType == 'ac'):
        subject_filename = data_path + 'scripts/function_inputs/ac.meg.all.txt'
    if (subjType == 'sc'):
        subject_filename = data_path + 'scripts/function_inputs/sc.meg.all.txt'
    if (subjType == 'ya'):
        subject_filename = data_path + 'scripts/function_inputs/ya.meg.all.txt'
    subject_list = readInput.readList(subject_filename)
    #    subject_list = ['9', '14', '12', '3', '1', '6']
    print subject_list

    for subject in subject_list:

        #To Find the total number of rejected trials, and percentage inclusion
        subjID = str(subjType) + str(subject)
        #       subjID = 'sc14'
        totalTrials = 0  # Must be initialised within the loop to refresh for each subject :)
        totalRejects = 0
        trialCount = 0
        rtrialCount = 0
        pReject = 0
        dataTable1 = []
        dataTable2 = []
        lineTemp = []
        lineTemp1 = []
        temp = 1

        inFile1 = data_path + 'data/' + str(
            subjID) + '/ave_projon/logs/' + str(
                subjID) + '_MEEGArtReject_' + str(par)
        if os.path.exists(inFile1):

            myFile1 = open(inFile1, "r")
            while temp:
                temp = myFile1.readline()
                temp1 = temp.strip(
                )  # when I included (' ') it did not return the items as a list, but when I just wrote () it did the trick!
                if temp1:
                    temp2 = temp1.split()
                    dataTable1.append(
                        temp2
                    )  # Save information as a list of items in a DataTable
                    runCount = len(dataTable1)
            myFile1.close()

            for i in range(0, len(dataTable1)):
                lineTemp = (dataTable1[i])
                trialCount = float(lineTemp[0])
                rtrialCount = float(lineTemp[1])
                totalTrials = totalTrials + trialCount
                totalRejects = totalRejects + rtrialCount

            pReject = (1 - round(((totalRejects) / float(totalTrials)), 4))
            #print(pReject)

            # To Display the total number of rejected trials, and percentage
            myFile2 = open(outFile, "a")
            myFile2.write("\n")
            myFile2.write(subjID)
            myFile2.write("\n")
            myFile2.write("Number of events found:\t")
            myFile2.write(str(totalTrials))
            myFile2.write("\n")
            myFile2.write("Number of events rejected:\t")
            myFile2.write(str(totalRejects))
            myFile2.write("\n")
            myFile2.write("MEG/EEG Inclusion Rate:\t")
            myFile2.write(str(pReject))
            myFile2.write("\n")

            # To Find the name of the bad channels rejected
            items = []
            chans = []
            chantot = []
            temp3 = 1
            dataTable3 = []
            dataTable4 = []
            linetemp1 = []
            inFile2 = data_path + 'data/' + str(
                subjID) + '/ave_projon/logs/' + str(
                    subjID) + '_MEEGArtReject-BadChan_' + str(par)
            myFile3 = open(inFile2, "r")
            while temp3:
                temp3 = myFile3.readline()
                temp4 = temp3.strip()
                if temp4:
                    temp5 = temp4.split()
                    dataTable3.append(
                        temp5
                    )  # Save information as a list of items in a DataTable
            for i in range(0, len(dataTable3)):
                lineTemp1 = dataTable3[i]
                #print(lineTemp1[0])
                chans.append(lineTemp1[0])
                chantot.append(lineTemp1[1])
            items = list(set(chans))
            #print(items)
            items = sorted(
                items, key=itemgetter(0)
            )  # To print Gradiometer, magnetometers and the the EEG channels in oreder.

            # To Display the name of the bad channels rejected
            myFile2.write("Number of Times MEG/EEG Channels Rejected")
            myFile2.write("\n")
            for i in range(0, len(items)):
                x = 0
                myFile2.write(str(items[i]))
                for j in range(0, len(chans)):
                    if items[i] == chans[j]:
                        x = x + int(chantot[j])
                #print(items[i])
                #print(x)
                myFile2.write("\t")
                myFile2.write(str(x))
                myFile2.write("\n")
            myFile2.close()
            myFile3.close()
コード例 #15
0
data_file = data_path + args.filename + '_' + 'ga' 



print data_path
print data_file

quadList = ['LA','LP','RA','RP']

for quad in quadList: ########## 

	args.chan_filename = '/Volumes/CUTTLEFISH/MNE_scripts/function_inputs/quad-'+quad+'.txt'
	plot_out= data_path+'Quadrants/'+args.filename+'_'+quad+'.png' #individual plots
	

	chans = readInput.readList(args.chan_filename)
	chans = [int(chan) for chan in chans]
	#print "actual chans as shown in MNE: {}".format(chans)
	
	#chans = [chan-1 for chan in chans] # this accounts for python indexing at 0
	print "chans as interpreted by iPython: {}".format(chans)
	
	
	##Plot condition(s)
	cm = plt.get_cmap('cool') # this chooses the colors to use for data lines
	fig = plt.figure()
	ax = fig.add_subplot(111)
	ax.set_color_cycle([cm(1.*i/len(args.condList)) for i in range(len(args.condList))])
	for cond in args.condList:
		
		condName = cond
コード例 #16
0
results_path = '/cluster/kuperberg/SemPrMM/MEG/results/sensor_level/MEG_rms/rms_ga/'
channel_path = '/cluster/kuperberg/SemPrMM/MEG/scripts/function_inputs/MEG_Chan_Names/grad_'
channelGroups = ['frontal','temporal','parietal','occipital']

hemList = ['L', 'R']

for group in channelGroups:
	pl.clf()
	font = {
         'size'   : 30}
	pl.rc('font', **font)
	
	for hem in hemList:
	
		channelFile = channel_path + hem + group+ '.txt'
		channelNames = readInput.readList(channelFile)
		channelList = []
		for item in channelNames:
			channelList.append('MEG ' + item)
		print group
		print channelList
	
		
		if hem == 'L':
			pl.subplot(121)
		else:
			pl.subplot(122)
		for c in range(2):
			file = data_path + args.prefix +'-ave.fif'
			print file
			print 'set ',condList[c]
コード例 #17
0
ymin,ymax = [-.5,26]
xmin,xmax = [-100,660]


data_path = '/cluster/kuperberg/SemPrMM/MEG/data/'
results_path = '/cluster/kuperberg/SemPrMM/MEG/results/sensor_level/MEG_rms/'
channel_path = '/cluster/kuperberg/SemPrMM/MEG/scripts/function_inputs/MEG_Chan_Names/grad_'
channelGroups = ['frontal','temporal','parietal','occipital']
##channelGroups = ['occipital']

hemList = ['L', 'R']

###Get subject list
subjFile = '/cluster/kuperberg/SemPrMM/MEG/scripts/function_inputs/' + args.prefix + '.txt'
subjects = readInput.readList(subjFile)
print subjects
#subjects = ['1', '2','3']

for group in channelGroups:
	pl.clf()
	font = {
         'size'   : 16}
	pl.rc('font', **font)
	
	for hem in hemList:
		
		channelFile = channel_path + hem + group+ '.txt'
		channelNames = readInput.readList(channelFile)
		channelList = []
		for item in channelNames:
コード例 #18
0
data_path = '/cluster/kuperberg/SemPrMM/MEG/results/sensor_level/ga_fif/'
results_path = '/cluster/kuperberg/SemPrMM/MEG/results/sensor_level/MEG_rms/rms_ga/'
channel_path = '/cluster/kuperberg/SemPrMM/MEG/scripts/function_inputs/MEG_Chan_Names/grad_'
channelGroups = ['frontal', 'temporal', 'parietal', 'occipital']

hemList = ['L', 'R']

for group in channelGroups:
    pl.clf()
    font = {'size': 30}
    pl.rc('font', **font)

    for hem in hemList:

        channelFile = channel_path + hem + group + '.txt'
        channelNames = readInput.readList(channelFile)
        channelList = []
        for item in channelNames:
            channelList.append('MEG ' + item)
        print group
        print channelList

        if hem == 'L':
            pl.subplot(121)
        else:
            pl.subplot(122)
        for c in range(2):
            file = data_path + args.prefix + '-ave.fif'
            print file
            print 'set ', condList[c]
            evoked = mne.fiff.read_evoked(file,
コード例 #19
0
                        myFile2.write(lineTemp[j] + '\n')
                        myFile2.write('\n')
        

						
if __name__ == "__main__":


        
        modalities = ['MRI']
        studies = ['MaskedMM']
        #subjType = ['ac', 'sc', 'ya']
 
        all_lines = 0
        for mod in modalities:
          subjects = readInput.readList('/cluster/kuperberg/SemPrMM/MRI/scripts/input/' +listPrefix)
          print(subjects)
          with open('/cluster/kuperberg/SemPrMM/MRI/results/behavioral_accuracy/'+mod+'_'+listPrefix+'_'+study+'_accuracy-short_new.log','w') as d:
            #print(study)
             d.write('sub' + '\t' + 'Acc_AniPrime' + 'Acc_AniTarg' +'\n')

             for sub in subjects:
                acc_anipri_avg = 0.0
                acc_anitar_avg = 0.0
                acc_ani_avg = 0.0
		rt_anipri_avg = 0.0
		rt_anitar_avg = 0.0
		rt_ani_avg = 0.0
                acc_AniPrime = 0.0
                acc_AniTar = 0.0
                acc_Ani = 0.0
コード例 #20
0
channelGroups = ['ant','post']
hemList = ['left','right']


for group in channelGroups:
	pl.clf()
	font = {
         'weight' : 'bold',
         'size'   : 16}
	pl.rc('font', **font)
	#figure(num=None, figsize=(16, 6), dpi=80, facecolor='w', edgecolor='k') # you could use this to change the size of the figure

	for hem in hemList:
	
		channelFile = channel_path + hem + '_' + group+ '.txt'
		channelList = readInput.readList(channelFile)
	
		if hem == 'left':
			pl.subplot(121)
		else:
			pl.subplot(122)
		for c in range(2):
		
			##get the data
			file = data_path + prefixList[c] +'-ave.fif'
                        ##file = data_path + args.prefix1 +'-ave.fif'
			print file
			print 'set ',condList[c]
			evoked = fiff.Evoked(file,setno=condList[c],baseline=(-100,0),proj=False)
			times=evoked.times*1000
			sel = fiff.pick_types(evoked.info,meg=False,eeg=False,include=channelList)
コード例 #21
0
args = parser.parse_args()
exp = args.exp ## msabri
subjID = args.subjID
par = args.par ##Left Right etc.,
set1 = args.set1
condName = [args.set1] ##If set1 and set2 are condition names

####Setup Subject Speciifc Information
data_path = '/home/custine/MEG/data/' +exp+'/'+subjID + '/ave_projon/'
results_path = data_path +'plots/' 
fname = data_path + subjID +'_' +par+'-ave.fif'
out_fname = results_path + subjID + '_' + par +'_'+set1+'_meg_evoked_color.png'
print out_fname
#chan_path = '/home/custine/MEG/scripts/function_inputs/MEG_Chan_Names/'
chan_fname = '/home/custine/MEG/scripts/function_inputs/MEG_Chan_Number/MEG_chan_number_list-m.txt'
chan_names = readInput.readList(chan_fname)
#chan_list = []
#for item in chan_names:
#    chan_list.append('MEG'+item)
chan_names = [int(chan) for chan in chan_names]

####Reading the Evoked data structure
for c in condName:
    print c
    evoked = mne.fiff.Evoked(fname, setno='epochs_'+c , baseline = (None, 0))
    #evoked = mne.fiff.Evoked(fname, setno = c , baseline = (None, 0)) ##Use this if you are using condition numbers
    #badChanSet = set(evoked.info['bads'])
    sel = chan_names
    #sel = list(set(chan_names) - set(badChanSet))
    print sel
    data = evoked.data[sel]
コード例 #22
0
                    all_data[k] = {}
                all_data[k][sub] = v
        except IOError:
            pass
    return all_data

if __name__ == '__main__':
    data_path = '/cluster/kuperberg/SemPrMM/MEG/'
    subjType = sys.argv[1]
    if (subjType == 'ac'):
		subject_filename = data_path + 'scripts/function_inputs/ac.meg.all.txt'
    if (subjType == 'sc'):
		subject_filename = data_path + 'scripts/function_inputs/sc.n16.meeg.b.txt'
    if (subjType == 'ya'):
		subject_filename = data_path + 'scripts/function_inputs/ya.meg.all.possible.txt'
    subject_list = readInput.readList(subject_filename)
    subjects = []
    for row in subject_list:
    	row = subjType+row
    	subjects.append(row)
    print subjects
    
    all_data = get_data(subjects)
    for k,v in all_data.items():
        #print k, v
        ##Note: 
        fname = '/%s/kuperberg/SemPrMM/MEG/results/artifact_rejection/heogveog_rejection/%s_%s_rejTable.txt' % (pre, subjType, k)
        codes = sorted(v[subjType+'12'].keys(), cmp=lambda x,y: cmp(int(x), int(y)))   ##using subject ID 12 to retrieve item codes
        print codes 
        code_line = '\t\t%s' % '\t\t\t'.join(codes)
        #print code_line
コード例 #23
0
###############################################################
### Get User Input 

parser = argparse.ArgumentParser(description = 'Get user input..')
parser.add_argument('exp', type = str)
parser.add_argument('par', type = str)

args = parser.parse_args()
exp = args.exp ## msabri
par = args.par ##Left Right etc., 


####Setup Subject Speciifc Information
data_path = '/home/custine/MEG/data/' + exp
subjList = readInput.readList('/home/custine/MEG/scripts/function_inputs/'+exp+'_subjList.txt')
result_path = '/home/custine/MEG/results/sensor_level/ga_fif/' 
print subjList

event_id ={}
condName = {}
labels = cc.condLabels[par]
for row in labels: 
    event_id[row[1]] = int(row[0])   
    
print event_id
print 'Number of Conditions...'
lenCond = len(event_id)
print lenCond

allData = [ [] for item in range(lenCond)]
コード例 #24
0
def spanData2R(subjType, listPrefix):
    data_path = '/cluster/kuperberg/SemPrMM/assessment/'
    inFile1 = data_path + 'scripts/function_input/' + str(listPrefix) + '.txt'
    inFile2 = data_path + 'span/Input/' + 'WM-SpanLog_' + str(subjType)
    outFile1 = data_path + 'results/span/R/' + str(
        listPrefix) + '_WM-Span_Long.txt'

    ##     if (subjType == 'ac'):
    ##         subject_filename = data_path + 'scripts/function_inputs/ac.meg.all.txt'
    ##     if (subjType == 'sc'):
    ##         subject_filename = data_path + 'scripts/function_inputs/sc.meg.all.txt'
    ##     if (subjType == 'ya'):
    ##         subject_filename = data_path + 'scripts/function_inputs/ya.meg.all.txt'
    subject_list = readInput.readList(inFile1)
    ##print subject_list
    ##
    for subject in subject_list:
        print subject


#To Find the total number of rejected trials, and percentage inclusion
#subjID = str(subjType)+ str(subject)
    totalTrials = 0  # Must be initialised within the loop to refresh for each subject :)
    dataTable1 = []
    dataTable2 = []
    lineTemp = []
    lineTemp1 = []
    temp = 1
    header = []

    if os.path.exists(inFile1):
        print("File exists")
    else:
        print("Check the input file name")

    myFile1 = open(inFile2, "r")
    while temp:
        temp = myFile1.readline()
        temp1 = temp.strip()  # not ('')
        if temp1:
            temp2 = temp1.split()
            dataTable1.append(
                temp2)  # Save information as a list of items in a DataTable
            runCount = len(dataTable1)
    myFile1.close()

    header = dataTable1[0]
    span_len = len(header)
    #print(runCount)
    #print(span_len)

    myFile2 = open(outFile1, "w")
    myFile2.write("Sub:\t\tSpan\t\tNumCorrect\n")
    for i in range(1, runCount):
        lineTemp = (dataTable1[i])
        ##print(lineTemp)
        #print(lineTemp[0])
        for j in range(1, span_len):
            if str(
                    lineTemp[0]
            ) in subject_list:  # Compares the subject name to check if it exists in the listPrefix file.

                myFile2.write(lineTemp[0] + '\t\t')
                myFile2.write(header[j] + '\t\t')
                myFile2.write(lineTemp[j])
                myFile2.write('\n')
    print("Completed. See result in /assessment/results/span/R/ folder")
コード例 #25
0
###############################################################################
# Parameters

parser = argparse.ArgumentParser(description='Get input')
parser.add_argument('prefix', type=str)
parser.add_argument('protocol', type=str)
parser.add_argument('cond1', type=int)
parser.add_argument('cond2', type=int)
parser.add_argument('t1', type=float)
parser.add_argument('t2', type=float)
parser.add_argument('model', type=str)
parser.add_argument('threshold', type=float)
args = parser.parse_args()

subjFile = '/cluster/kuperberg/SemPrMM/MEG/scripts/function_inputs/' + args.prefix + '.txt'
subjects = readInput.readList(subjFile)
print subjects

time_interval = (
    args.t1, args.t2
)  #If you set a real time_interval, you will average across this and do spatial clusters
dec = None

#time_interval = None  #If you set time_interval to None, it will do spatiotemporal clusters
#dec = 10  # this sets the temporal decimation factor. e.g. if you sampled 600Hz and set this to 3, you will downsample the test to every 5 ms

thresholds = [
    args.threshold
]  #This sets the threshold for the first stage of the test. You have the option of including more than one threshold to see what happens when it changes

#def stat_fun(X):
コード例 #26
0
def computeEvents(subjType, par):
     data_path = '/cluster/kuperberg/SemPrMM/MEG/'
     outFile = data_path + 'results/artifact_rejection/megeeg_rejection/' + str(subjType) + '_MEEGArtRejSummary_' + str(par)
     myFile2 = open(outFile, "w") 

        
     if (subjType == 'ac'):
         subject_filename = data_path + 'scripts/function_inputs/ac.meg.all.txt'
     if (subjType == 'sc'):
         subject_filename = data_path + 'scripts/function_inputs/sc.meg.all.txt'
     if (subjType == 'ya'):
         subject_filename = data_path + 'scripts/function_inputs/ya.meg.all.txt'
     subject_list = readInput.readList(subject_filename)
 #    subject_list = ['9', '14', '12', '3', '1', '6']
     print subject_list

     for subject in subject_list:
        
#To Find the total number of rejected trials, and percentage inclusion
        subjID = str(subjType)+ str(subject)
 #       subjID = 'sc14'
        totalTrials = 0 # Must be initialised within the loop to refresh for each subject :) 
        totalRejects = 0
        trialCount=0
        rtrialCount=0
        pReject=0
        dataTable1=[]
        dataTable2=[]
        lineTemp = []
        lineTemp1 = []
        temp = 1
        
        inFile1 = data_path + 'data/' + str(subjID) + '/ave_projon/logs/' + str(subjID) + '_MEEGArtReject_' + str(par)
        if os.path.exists(inFile1):
             
          myFile1 = open(inFile1, "r") 
          while temp:
             temp = myFile1.readline()
             temp1 = temp.strip() # when I included (' ') it did not return the items as a list, but when I just wrote () it did the trick!
             if temp1:
                temp2 = temp1.split()
                dataTable1.append(temp2) # Save information as a list of items in a DataTable
                runCount=len(dataTable1)   
          myFile1.close()
          
          for i in range(0, len(dataTable1)):
            lineTemp = (dataTable1[i])
            trialCount=float(lineTemp[0])
            rtrialCount=float(lineTemp[1])
            totalTrials = totalTrials + trialCount
            totalRejects = totalRejects + rtrialCount
            
          pReject=(1-round(((totalRejects)/float(totalTrials)),4))
          #print(pReject)


# To Display the total number of rejected trials, and percentage         
          myFile2 = open(outFile, "a") 
          myFile2.write("\n")
          myFile2.write(subjID)
          myFile2.write("\n")
          myFile2.write("Number of events found:\t")
          myFile2.write(str(totalTrials))
          myFile2.write("\n")
          myFile2.write("Number of events rejected:\t")
          myFile2.write(str(totalRejects))
          myFile2.write("\n")
          myFile2.write("MEG/EEG Inclusion Rate:\t")
          myFile2.write(str(pReject))
          myFile2.write("\n")

# To Find the name of the bad channels rejected
          items=[]
          chans=[]
          chantot=[]
          temp3 = 1
          dataTable3=[]
          dataTable4=[]
          linetemp1=[]
          inFile2 = data_path + 'data/' + str(subjID) + '/ave_projon/logs/' + str(subjID) + '_MEEGArtReject-BadChan_' + str(par)
          myFile3 = open(inFile2, "r")
          while temp3:
             temp3 = myFile3.readline()
             temp4 = temp3.strip() 
             if temp4:
               temp5 = temp4.split()
               dataTable3.append(temp5) # Save information as a list of items in a DataTable
          for i in range(0, len(dataTable3)):
              lineTemp1 = dataTable3[i]
              #print(lineTemp1[0])
              chans.append(lineTemp1[0])
              chantot.append(lineTemp1[1])          
          items=list(set(chans))
          #print(items)
          items = sorted(items, key=itemgetter(0)) # To print Gradiometer, magnetometers and the the EEG channels in oreder. 
          

# To Display the name of the bad channels rejected
          myFile2.write("Number of Times MEG/EEG Channels Rejected")
          myFile2.write("\n")
          for i in range(0, len(items)):
                x=0
                myFile2.write(str(items[i]))
                for j in range(0, len(chans)):
                        if items[i] == chans[j]:
                              x = x + int(chantot[j])
                #print(items[i])
                #print(x)              
                myFile2.write("\t")
                myFile2.write(str(x))
                myFile2.write("\n")
          myFile2.close()
          myFile3.close()