[Swift-commit] r3054 - in SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs: . scripts

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Thu Aug 6 10:27:56 CDT 2009


Author: andric
Date: 2009-08-06 10:27:56 -0500 (Thu, 06 Aug 2009)
New Revision: 3054

Added:
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/catsort.py
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/copier.py
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/copystuff.py
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/find_missing.py
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/findmissingverts.R
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/findmissingverts.py
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/indiv_ccfinterp.R
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/indiv_ccfinterpSupp.R
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/medication.py
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/medicationTRES.py
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/printcount.py
   SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/untarthem.py
Log:
scripts dir for interp ccf on individual subjects

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/catsort.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/catsort.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/catsort.py	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import os
+import commands
+index = range(1,196001)
+
+hemis = ['lh','rh']
+#hemis = ['rh']
+subjs = [10]
+#subjs = [13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+#subjs = [3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+baseDir = os.getenv("cnari")+"/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/"
+
+for ss in subjs:
+    os.chdir(baseDir+"ss"+`ss`+"interp_results/")
+    print os.getcwd()
+    for h in hemis:
+        sortfile = "sorted_"+h+"_ccf.txt"
+        commands.getoutput("cat "+h+"_*_ccf.txt | sort -g -k 1 > "+sortfile)
+

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/copier.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/copier.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/copier.py	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+
+import shutil
+import os
+
+
+subjs = [3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+baseDir = os.getenv("cnari")+"/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/"
+
+
+for ss in subjs:
+    shutil.copy2(baseDir+"scripts/indiv_ccfinterpSupp.R", baseDir+"ss"+`ss`+"interp_results")
+

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/copystuff.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/copystuff.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/copystuff.py	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+
+import os
+import commands
+
+hemis = ['lh','rh']
+subjs = [3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+baseDir = os.getenv("cnari")+"/swift/projects/andric/ccf_emblem/individual_ss/"
+
+for ss in subjs:
+    oldStuff = baseDir+"IDEALseed/ss"+`ss`+"_results/ss_vec"+`ss`+".txt"
+    newStuff = baseDir+"interpolatedHRFs/ss"+`ss`+"interp_results/"
+    commands.getoutput("cp "+oldStuff+" "+newStuff)

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/find_missing.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/find_missing.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/find_missing.py	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,28 @@
+#!/usr/bin/python
+
+import os
+import commands
+
+
+starts = range(1,196000,1000)
+subjs = [5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+#subjs = [3]
+baseDir = os.getenv("cnari")+"/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/"
+hemis = ['lh','rh']
+
+
+for ss in subjs:
+    os.chdir(baseDir+"ss"+`ss`+"interp_results/")
+    print os.getcwd()
+    for h in hemis:
+        outfile = baseDir+"ss"+`ss`+"interp_results/missing_"+h+"_ss"+`ss`+"starts.txt"
+        missed = ""
+        for num in starts:
+            voxdata = h+"_"+`num`+"_"+`(num+999)`+"_ccf.txt"
+            if os.path.exists(voxdata): pass
+            else:
+                missed += `num`+"\n"
+        
+        file = open(outfile,'w')
+        file.write(missed)
+        file.close()

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/findmissingverts.R
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/findmissingverts.R	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/findmissingverts.R	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,6 @@
+prefix <- Sys.getenv("R_FILE")
+sorted <- read.table(prefix)
+verts <- c(1:196000)
+index <- sorted[,1]
+missing <- which(!verts %in% index)
+write.table(missing,paste(prefix,"missingverts",sep=""),row.names=F,col.names=F,quote=F)

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/findmissingverts.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/findmissingverts.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/findmissingverts.py	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,20 @@
+#!/usr/bin/python
+
+import os
+import commands
+index = range(1,196001)
+
+hemis = ['lh','rh']
+subjs = [3]
+#subjs = [3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+baseDir = os.getenv("cnari")+"/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/"
+
+for ss in subjs:
+    os.chdir(baseDir+"ss"+`ss`+"interp_results/")
+    print os.getcwd()
+    for h in hemis:
+        sortfile = baseDir+"ss"+`ss`+"interp_results/sorted_"+h+"_ccf"
+        commands.getoutput("cat "+h+"_*_ccf.txt | sort -g -k 1 > "+sortfile)
+        os.environ["R_FILE"] = sortfile
+        os.system("/usr/bin/R CMD BATCH --vanilla "+baseDir+"scripts/findmissingverts.R")
+

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/indiv_ccfinterp.R
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/indiv_ccfinterp.R	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/indiv_ccfinterp.R	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,136 @@
+#--- June 1, 2009
+## using interpolation to get better precision on the lag
+#---- This vrsion cuts off Beta vals abs(val) > 8 and uses lag.max=12
+library(akima)
+allinputs <- Sys.getenv("R_SWIFT_ARGS")
+print(allinputs)
+outname <- noquote(strsplit(allinputs," ")[[1]][1])
+hemi <- noquote(strsplit(allinputs," ")[[1]][2])
+
+inputfile <- Sys.getenv("R_INPUT")
+dd <- read.table(inputfile)
+Query_out <- data.frame(dd)
+
+
+NumSubjects <- 1;
+NumTimepoints <- 9;
+NumCols <- 36
+SubjectVec <- as.factor(rep(1:NumSubjects,NumCols))
+CondVect <- as.factor(rep(1:4, rep(NumTimepoints*NumSubjects, 4)))
+TimePointVec <- as.factor(rep(rep(1:9, rep(NumSubjects, 9)),4))
+OverallRows <- length(levels(as.factor(Query_out[,2])))
+ccf <- matrix(nrow=OverallRows, ncol=10)
+
+mat_row = 0
+
+attach(Query_out)
+vox_levels <- as.factor(Query_out[,2])
+
+for (vox in levels(vox_levels)){
+    mat_row = mat_row + 1
+    # brougt in many voxels, now go one by one
+    vox_matrix <- Query_out[which(Query_out[,2] == vox),]
+    # take colums 3-38of the results and make vector
+    zz <- (stack(vox_matrix[,3:38]))
+    VoxValues_vec <- zz[,1]
+    Voxel_df <- data.frame(S=SubjectVec, Cond=CondVect, Time=TimePointVec, Beta=VoxValues_vec)
+    attach(Voxel_df)
+    # grab those entries with extreme values to try to ammend with clean data
+    cutoff_obs <- Voxel_df[(Voxel_df$Beta <= -8) | (Voxel_df$Beta >= 8),]
+
+    if (length(unique(cutoff_obs$Beta)) > 0){
+       # get breakdown of the extreme values by subject and condition. if we wanted just by subject could have used
+       # cutoff_obs_breakdown <- aggregate(cutoff_obs$Beta, by=list(cutoff_obs$S), length)
+       cutoff_obs_breakdown <- aggregate(cutoff_obs$Beta, by=list(cutoff_obs$S, cutoff_obs$Time), length)
+       # now get just those conditions that had 1 or more extreme vals.
+       # ss that contributed more than 1 vals to any condition gets kicked out from this voxel's analysis
+       t1 <- subset(cutoff_obs_breakdown, cutoff_obs_breakdown$x >=1)
+       kicked_out_ss <-  as.factor(as.vector(unique(t1[,1])))
+       num_kicked_out_ss <- (length(kicked_out_ss))
+       cleaned_ss_df <- Voxel_df[!(Voxel_df$S %in% kicked_out_ss),]
+       remaining_ss <- length(as.factor(as.vector(unique(cleaned_ss_df$S))))
+       final_df <- cleaned_ss_df
+       rm(cleaned_ss_df)
+    }
+    else{
+       num_kicked_out_ss = 0
+       final_df <- Voxel_df
+    }
+
+    detach(Voxel_df)
+    rm(Voxel_df)
+    attach(final_df)
+    # control_vec is to track which voxels have shit data
+    # keeping the previous voxel's data if current voxel is crap
+    if (length(Beta) == 0){
+       agListMean <- agListMean
+       control_vec <- c(1)
+    }
+    else{
+       agListMean <- aggregate(Beta, by=list(Time, Cond), mean)
+       control_vec <- c(0)
+    }
+    
+    
+    waver.vector <- c(0,8.96394,89.8344,75.8427,23.2527,4.09246,0.507025,0.0493012,0)
+    vox_speech_vec <- subset(agListMean, Group.2==1)[,3]
+    vox_gesture_vec <- subset(agListMean, Group.2==2)[,3]
+    vox_gestspeech_vec <- subset(agListMean, Group.2==3)[,3]
+    vox_grasp_vec <- subset(agListMean, Group.2==4)[,3]
+    
+    
+    ##-- INTERPOLATION -------- ##
+    origX <- c(1:NumTimepoints)
+    ## 4 Hz resampling to get into 1/4 of a TR (1/2 second)
+    resample_length <- length(seq(1,NumTimepoints,1/4))
+    ## interpolate waver.vector and then each condition
+    asp_wvr <- aspline(origX,waver.vector,n=resample_length,method="improved")$y
+    asp_speech <- aspline(origX,vox_speech_vec,n=resample_length,method="improved")$y
+    asp_gesture <- aspline(origX,vox_gesture_vec,n=resample_length,method="improved")$y
+    asp_gestspeech <- aspline(origX,vox_gestspeech_vec,n=resample_length,method="improved")$y
+    asp_grasp <- aspline(origX,vox_grasp_vec,n=resample_length,method="improved")$y
+    
+    
+    #---- SPEECH
+    speech_ccf <- ccf(asp_speech, asp_wvr, lag.max = 12, type = c("correlation"), na.action=na.pass, plot=FALSE)
+    if (sum(as.numeric(is.na(speech_ccf$acf))) != 0){
+        speech_ccf$acf[1:25] = 0
+    }
+    speech_frame <- as.matrix(data.frame(speech_ccf$acf,speech_ccf$lag))
+    speech_cor <- speech_frame[which.max(speech_frame[,1]),]
+
+
+    #---- GESTURE
+    gesture_ccf <- ccf(asp_gesture, asp_wvr, lag.max = 12, type = c("correlation"), na.action=na.pass, plot=FALSE)
+    if (sum(as.numeric(is.na(gesture_ccf$acf))) != 0){
+        gesture_ccf$acf[1:25] = 0
+    }
+    gesture_frame <- as.matrix(data.frame(gesture_ccf$acf,gesture_ccf$lag))
+    gesture_cor <- gesture_frame[which.max(gesture_frame[,1]),]
+
+
+    #---- GESTURE & SPEECH
+    gestspeech_ccf <- ccf(asp_gestspeech, asp_wvr, lag.max = 12, type = c("correlation"), na.action=na.pass, plot=FALSE)
+    if (sum(as.numeric(is.na(gestspeech_ccf$acf))) != 0){
+        gestspeech_ccf$acf[1:25] = 0
+    }
+    gestspeech_frame <- as.matrix(data.frame(gestspeech_ccf$acf,gestspeech_ccf$lag))
+    gestspeech_cor <- gestspeech_frame[which.max(gestspeech_frame[,1]),]
+
+
+    #---- GRASP
+    grasp_ccf <- ccf(asp_grasp, asp_wvr, lag.max = 12, type = c("correlation"), na.action=na.pass, plot=FALSE)
+    if (sum(as.numeric(is.na(grasp_ccf$acf))) != 0){
+        grasp_ccf$acf[1:25] = 0
+    }
+    grasp_frame <- as.matrix(data.frame(grasp_ccf$acf,grasp_ccf$lag))
+    grasp_cor <- grasp_frame[which.max(grasp_frame[,1]),]
+    
+    
+    vox_id <- as.integer(vox)
+    ccf[mat_row, ] <- c(vox_id, speech_cor[[1]], speech_cor[[2]], gesture_cor[[1]], gesture_cor[[2]], gestspeech_cor[[1]], gestspeech_cor[[2]], grasp_cor[[1]], grasp_cor[[2]], control_vec)
+    detach(final_df)
+    rm(final_df)
+}
+
+write.table(round(ccf,5), file=paste(hemi,"_",outname,"_ccf.txt",sep=""), row.names=FALSE, col.names=FALSE)

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/indiv_ccfinterpSupp.R
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/indiv_ccfinterpSupp.R	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/indiv_ccfinterpSupp.R	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,133 @@
+#this is for adaptively filling in the missing vertices on the ccf analysis.
+## because the original .R script cleans bad vertices by using the previous vert's values, some batches were entirely missed if the first vertex in the batch was bad
+library(akima)
+outname <- ""
+dd <- read.table(paste(Sys.getenv("R_FILE"),".txt",sep=""))
+arg_length <- length(noquote(strsplit(Sys.getenv("R_FILE"),"/"))[[1]])
+outname <- noquote(strsplit(Sys.getenv("R_FILE"),"/"))[[1]][arg_length]
+Query_out <- data.frame(dd)
+
+
+NumSubjects <- 1;
+NumTimepoints <- 9;
+NumCols <- 36
+SubjectVec <- as.factor(rep(1:NumSubjects,NumCols))
+CondVect <- as.factor(rep(1:4, rep(NumTimepoints*NumSubjects, 4)))
+TimePointVec <- as.factor(rep(rep(1:9, rep(NumSubjects, 9)),4))
+OverallRows <- length(levels(as.factor(Query_out[,2])))
+ccf <- matrix(nrow=OverallRows, ncol=10)
+#control_vec <- matrix(nrow=OverallRows,ncol=1)
+
+mat_row = 0
+
+attach(Query_out)
+vox_levels <- as.factor(Query_out[,2])
+
+for (vox in levels(vox_levels)){
+    mat_row = mat_row + 1
+    # brougt in many voxels, now go one by one
+    vox_matrix <- Query_out[which(Query_out[,2] == vox),]
+    # take colums 3-38of the results and make vector
+    zz <- (stack(vox_matrix[,3:38]))
+    VoxValues_vec <- zz[,1]
+    Voxel_df <- data.frame(S=SubjectVec, Cond=CondVect, Time=TimePointVec, Beta=VoxValues_vec)
+    attach(Voxel_df)
+    # grab those entries with extreme values to try to ammend with clean data
+    cutoff_obs <- Voxel_df[(Voxel_df$Beta <= -8) | (Voxel_df$Beta >= 8),]
+
+    if (length(unique(cutoff_obs$Beta)) > 0){
+       # get breakdown of the extreme values by subject and condition. if we wanted just by subject could have used
+       # cutoff_obs_breakdown <- aggregate(cutoff_obs$Beta, by=list(cutoff_obs$S), length)
+       cutoff_obs_breakdown <- aggregate(cutoff_obs$Beta, by=list(cutoff_obs$S, cutoff_obs$Time), length)
+       # now get just those conditions that had 1 or more extreme vals.
+       # ss that contributed more than 1 vals to any condition gets kicked out from this voxel's analysis
+       t1 <- subset(cutoff_obs_breakdown, cutoff_obs_breakdown$x >=1)
+       kicked_out_ss <-  as.factor(as.vector(unique(t1[,1])))
+       num_kicked_out_ss <- (length(kicked_out_ss))
+       cleaned_ss_df <- Voxel_df[!(Voxel_df$S %in% kicked_out_ss),]
+       remaining_ss <- length(as.factor(as.vector(unique(cleaned_ss_df$S))))
+       final_df <- cleaned_ss_df
+       rm(cleaned_ss_df)
+    }
+    else{
+       num_kicked_out_ss = 0
+       final_df <- Voxel_df
+    }
+
+    detach(Voxel_df)
+    rm(Voxel_df)
+    attach(final_df)
+    # control_vec is to track which voxels have shit data
+    # keeping the previous voxel's data if current voxel is crap
+    if (length(Beta) == 0){
+       agListMean <- agListMean
+       control_vec <- c(1)
+    }
+    else{
+       agListMean <- aggregate(Beta, by=list(Time, Cond), mean)
+       control_vec <- c(0)
+    }
+    
+    
+    waver.vector <- c(0,8.96394,89.8344,75.8427,23.2527,4.09246,0.507025,0.0493012,0)
+    vox_speech_vec <- subset(agListMean, Group.2==1)[,3]
+    vox_gesture_vec <- subset(agListMean, Group.2==2)[,3]
+    vox_gestspeech_vec <- subset(agListMean, Group.2==3)[,3]
+    vox_grasp_vec <- subset(agListMean, Group.2==4)[,3]
+    
+    
+    ##-- INTERPOLATION -------- ##
+    origX <- c(1:NumTimepoints)
+    ## 4 Hz resampling to get into 1/4 of a TR (1/2 second)
+    resample_length <- length(seq(1,NumTimepoints,1/4))
+    ## interpolate waver.vector and then each condition
+    asp_wvr <- aspline(origX,waver.vector,n=resample_length,method="improved")$y
+    asp_speech <- aspline(origX,vox_speech_vec,n=resample_length,method="improved")$y
+    asp_gesture <- aspline(origX,vox_gesture_vec,n=resample_length,method="improved")$y
+    asp_gestspeech <- aspline(origX,vox_gestspeech_vec,n=resample_length,method="improved")$y
+    asp_grasp <- aspline(origX,vox_grasp_vec,n=resample_length,method="improved")$y
+    
+    
+    #---- SPEECH
+    speech_ccf <- ccf(asp_speech, asp_wvr, lag.max = 12, type = c("correlation"), na.action=na.pass, plot=FALSE)
+    if (sum(as.numeric(is.na(speech_ccf$acf))) != 0){
+        speech_ccf$acf[1:25] = 0
+    }
+    speech_frame <- as.matrix(data.frame(speech_ccf$acf,speech_ccf$lag))
+    speech_cor <- speech_frame[which.max(speech_frame[,1]),]
+
+
+    #---- GESTURE
+    gesture_ccf <- ccf(asp_gesture, asp_wvr, lag.max = 12, type = c("correlation"), na.action=na.pass, plot=FALSE)
+    if (sum(as.numeric(is.na(gesture_ccf$acf))) != 0){
+        gesture_ccf$acf[1:25] = 0
+    }
+    gesture_frame <- as.matrix(data.frame(gesture_ccf$acf,gesture_ccf$lag))
+    gesture_cor <- gesture_frame[which.max(gesture_frame[,1]),]
+
+
+    #---- GESTURE & SPEECH
+    gestspeech_ccf <- ccf(asp_gestspeech, asp_wvr, lag.max = 12, type = c("correlation"), na.action=na.pass, plot=FALSE)
+    if (sum(as.numeric(is.na(gestspeech_ccf$acf))) != 0){
+        gestspeech_ccf$acf[1:25] = 0
+    }
+    gestspeech_frame <- as.matrix(data.frame(gestspeech_ccf$acf,gestspeech_ccf$lag))
+    gestspeech_cor <- gestspeech_frame[which.max(gestspeech_frame[,1]),]
+
+
+    #---- GRASP
+    grasp_ccf <- ccf(asp_grasp, asp_wvr, lag.max = 12, type = c("correlation"), na.action=na.pass, plot=FALSE)
+    if (sum(as.numeric(is.na(grasp_ccf$acf))) != 0){
+        grasp_ccf$acf[1:25] = 0
+    }
+    grasp_frame <- as.matrix(data.frame(grasp_ccf$acf,grasp_ccf$lag))
+    grasp_cor <- grasp_frame[which.max(grasp_frame[,1]),]
+    
+    
+    vox_id <- as.integer(vox)
+    ccf[mat_row, ] <- c(vox_id, speech_cor[[1]], speech_cor[[2]], gesture_cor[[1]], gesture_cor[[2]], gestspeech_cor[[1]], gestspeech_cor[[2]], grasp_cor[[1]], grasp_cor[[2]], control_vec)
+    detach(final_df)
+    rm(final_df)
+}
+
+write.table(round(ccf,5), file=paste(outname,"_ccf.txt",sep=""), row.names=FALSE, col.names=FALSE)

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/medication.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/medication.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/medication.py	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,72 @@
+#!/usr/bin/python
+
+#---- this procedure is to go through each dir and find the missing text files then run R to fill in the gaps...
+# must first run 'find_missing_files.py'
+### this version is specific for the 'new' HNL machines (calero, guardado, manzur, pinto) because it sources a library for those distributions
+import commands
+import os
+import sys
+import MySQLdb
+
+
+#subjs = [5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+#subjs = [6]
+#subjs = [11,12]
+subjs = [10]
+#subjs = [13,14,15,17,18,19,20,21]
+#subjs = [22,23,24,25,26,27,28,30]
+hemis = ['rh']
+#hemis = ['lh','rh']
+baseDir = os.getenv("cnari")+"/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/"
+
+def the_supplement(ss,h):
+    ss_dir = baseDir+"ss"+`ss`+"interp_results/"
+    #missingfilename = ss_dir+"missing_"+`ss`+h+"_starts.txt"
+    missingfilename = ss_dir+"missing_"+h+"_ss"+`ss`+"starts.txt"
+    print "missing file is: "+missingfilename
+    missingfile = open(missingfilename,"r")
+    missingnums = missingfile.read().split()
+    print "missing numbers are: "+str(missingnums)
+
+    for num in missingnums:
+        begin_vox = int(num)
+        end_vox = int(num)+999
+        outprefix = ss_dir+"/"+h+"_"+num+"_"+`end_vox`
+        print "outprefix: "+outprefix+"\n"
+        checkfile = outprefix+"_ccf.txt"
+        outfile = outprefix+".txt"
+        print "begin vox: "+`begin_vox`+" and end vox: "+`end_vox`+"\n"
+        while os.path.exists(checkfile)==False:
+            try:
+                connection = MySQLdb.connect(db="EMBLEM1",read_default_file="~/.my.cnf")
+            except MySQLdb.Error, e:
+                print "Error %d: %s" % (e.args[0], e.args[1])
+                sys.exist (1)
+
+
+            query = "SELECT subject, voxel, speech0B, speech1B, speech2B, speech3B, speech4B, speech5B, speech6B, speech7B, speech8B, gesture0B, gesture1B, gesture2B, gesture3B, gesture4B, gesture5B, gesture6B, gesture7B, gesture8B, gestspeech0B, gestspeech1B, gestspeech2B, gestspeech3B, gestspeech4B, gestspeech5B, gestspeech6B, gestspeech7B, gestspeech8B, grasp0B, grasp1B, grasp2B, grasp3B, grasp4B, grasp5B, grasp6B, grasp7B, grasp8B FROM emblemfem"+h+" WHERE subject = "+`ss`+" and voxel between "+`begin_vox`+" and "+`end_vox`+";"
+
+            cursor = connection.cursor()
+            cursor.execute(query)
+            result = list(cursor.fetchall())
+            bully = ''
+            for rr in list(result):
+                bully += str(rr[0])+" "+str(rr[1])+" "+str(rr[2])+" "+str(rr[3])+" "+str(rr[4])+" "+str(rr[5])+" "+str(rr[6])+" "+str(rr[7])+" "+str(rr[8])+" "+str(rr[9])+" "+str(rr[10])+" "+str(rr[11])+" "+str(rr[12])+" "+str(rr[13])+" "+str(rr[14])+" "+str(rr[15])+" "+str(rr[16])+" "+str(rr[17])+" "+str(rr[18])+" "+str(rr[19])+" "+str(rr[20])+" "+str(rr[21])+" "+str(rr[22])+" "+str(rr[23])+" "+str(rr[24])+" "+str(rr[25])+" "+str(rr[26])+" "+str(rr[27])+" "+str(rr[28])+" "+str(rr[29])+" "+str(rr[30])+" "+str(rr[31])+" "+str(rr[32])+" "+str(rr[33])+" "+str(rr[34])+" "+str(rr[35])+" "+str(rr[36])+" "+str(rr[37])+"\n"
+
+
+            file = open(outfile,"w")
+            file.write(bully)
+            file.close()
+
+            os.environ["R_FILE"] = outprefix
+            os.chdir(ss_dir)
+            print "now working in: \n"+os.getcwd()
+            os.system("R CMD BATCH --vanilla ./indiv_ccfinterpSupp.R")
+            begin_vox = begin_vox + 1
+            print "next begin_vox is: "+`begin_vox`+"\n"
+
+
+
+for ss in subjs:
+    for h in hemis:
+        the_supplement(ss,h)

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/medicationTRES.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/medicationTRES.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/medicationTRES.py	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,71 @@
+#!/usr/bin/python
+
+#---- this procedure is to go through each dir and find the missing text files then run R to fill in the gaps...
+# must first run 'find_missing_files.py'
+### this version is specific for the 'new' HNL machines (calero, guardado, manzur, pinto) because it sources a library for those distributions
+import commands
+import os
+import sys
+import MySQLdb
+
+
+subjs = [5]
+#subjs = [5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+#subjs = [6]
+#subjs = [11,12]
+#subjs = [13,14,15,17,18,19,20,21]
+#subjs = [22,23,24,25,26,27,28,30]
+hemis = ['lh','rh']
+baseDir = os.getenv("cnari")+"/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/"
+
+def the_supplement(ss,h):
+    ss_dir = baseDir+"ss"+`ss`+"interp_results/"
+    #missingfilename = ss_dir+"missing_"+`ss`+h+"_starts.txt"
+    missingfilename = ss_dir+"missing_"+h+"_ss"+`ss`+"starts.txt"
+    print "missing file is: "+missingfilename
+    missingfile = open(missingfilename,"r")
+    missingnums = missingfile.read().split()
+    print "missing numbers are: "+str(missingnums)
+
+    for num in missingnums:
+        begin_vox = int(num)
+        end_vox = int(num)+999
+        outprefix = ss_dir+"/"+h+"_"+num+"_"+`end_vox`
+        print "outprefix: "+outprefix+"\n"
+        checkfile = outprefix+"_ccf.txt"
+        outfile = outprefix+".txt"
+        print "begin vox: "+`begin_vox`+" and end vox: "+`end_vox`+"\n"
+        while os.path.exists(checkfile)==False:
+            try:
+                connection = MySQLdb.connect(db="EMBLEM1",read_default_file="~/.my.cnf")
+            except MySQLdb.Error, e:
+                print "Error %d: %s" % (e.args[0], e.args[1])
+                sys.exist (1)
+
+
+            query = "SELECT subject, voxel, speech0B, speech1B, speech2B, speech3B, speech4B, speech5B, speech6B, speech7B, speech8B, gesture0B, gesture1B, gesture2B, gesture3B, gesture4B, gesture5B, gesture6B, gesture7B, gesture8B, gestspeech0B, gestspeech1B, gestspeech2B, gestspeech3B, gestspeech4B, gestspeech5B, gestspeech6B, gestspeech7B, gestspeech8B, grasp0B, grasp1B, grasp2B, grasp3B, grasp4B, grasp5B, grasp6B, grasp7B, grasp8B FROM emblemfem"+h+" WHERE subject = "+`ss`+" and voxel between "+`begin_vox`+" and "+`end_vox`+";"
+
+            cursor = connection.cursor()
+            cursor.execute(query)
+            result = list(cursor.fetchall())
+            bully = ''
+            for rr in list(result):
+                bully += str(rr[0])+" "+str(rr[1])+" "+str(rr[2])+" "+str(rr[3])+" "+str(rr[4])+" "+str(rr[5])+" "+str(rr[6])+" "+str(rr[7])+" "+str(rr[8])+" "+str(rr[9])+" "+str(rr[10])+" "+str(rr[11])+" "+str(rr[12])+" "+str(rr[13])+" "+str(rr[14])+" "+str(rr[15])+" "+str(rr[16])+" "+str(rr[17])+" "+str(rr[18])+" "+str(rr[19])+" "+str(rr[20])+" "+str(rr[21])+" "+str(rr[22])+" "+str(rr[23])+" "+str(rr[24])+" "+str(rr[25])+" "+str(rr[26])+" "+str(rr[27])+" "+str(rr[28])+" "+str(rr[29])+" "+str(rr[30])+" "+str(rr[31])+" "+str(rr[32])+" "+str(rr[33])+" "+str(rr[34])+" "+str(rr[35])+" "+str(rr[36])+" "+str(rr[37])+"\n"
+
+
+            file = open(outfile,"w")
+            file.write(bully)
+            file.close()
+
+            os.environ["R_FILE"] = outprefix
+            os.chdir(ss_dir)
+            print "now working in: \n"+os.getcwd()
+            os.system("R CMD BATCH --vanilla ./indiv_ccfinterpSupp.R")
+            begin_vox = begin_vox + 1
+            print "next begin_vox is: "+`begin_vox`+"\n"
+
+
+
+for ss in subjs:
+    for h in hemis:
+        the_supplement(ss,h)

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/printcount.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/printcount.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/printcount.py	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,15 @@
+#!/usr/bin/python
+
+import os
+import commands
+
+hemis = ['lh','rh']
+subjs = [3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+baseDir = os.getenv("cnari")+"/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/"
+
+for ss in subjs:
+    os.chdir(baseDir+"ss"+`ss`+"interp_results/")
+    print os.getcwd()
+    for h in hemis:
+        sortfile = "sorted_"+h+"_ccf.txt"
+        print h+" count: "+commands.getoutput("wc "+sortfile)

Added: SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/untarthem.py
===================================================================
--- SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/untarthem.py	                        (rev 0)
+++ SwiftApps/SIDGrid/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/scripts/untarthem.py	2009-08-06 15:27:56 UTC (rev 3054)
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+import commands
+import time
+import os
+import sys
+
+
+hemis = ['lh','rh']
+subjs = [3,5,6,7,8,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,30]
+baseDir = os.getenv("cnari")+"/swift/projects/andric/ccf_emblem/individual_ss/interpolatedHRFs/"
+
+for ss in subjs:
+    for h in hemis:
+        os.chdir(baseDir+"ss"+`ss`+"interp_results/")
+        print os.getcwd()
+        print time.ctime()+"\ndoing "+h
+        print commands.getoutput("ls interp_"+h+"*.tar | wc")
+        print commands.getoutput("find -name 'interp_"+h+"*.tar' -exec tar xf '{}' ';'")




More information about the Swift-commit mailing list