Last active
February 27, 2018 08:28
-
-
Save lauracodecreations/c9af05b15979f3bae14bbe61ebf5efc4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/Rscript | |
#dti_FA image is in dti.dti directory | |
#Note: in flsview the slice number is one less than R. If x = 45, then in fslview x = 44 | |
#Note: masks and FA images must be saved in the directory where R started. Use bash script "~/selectracts" | |
#subject 775353 IFL_R z 26, best(continous), x (non of them are continous) | |
#y slice sometimes looks a little zquich - size/location of each plot | |
#the dark color makes it a little slow | |
library(Rniftilib) | |
library(tcltk) | |
library(base) | |
library(Matrix) | |
library(lattice) | |
library(base) | |
#require(grDevices) | |
#prints the header for comments text file | |
write(sprintf("IDNUM POSITION SIDE COMMENTS"), file="comments.txt", append = TRUE) | |
#array of all the subject | |
IDNUMS<-c(775511, 775353) | |
#loop into one subject at a time | |
for (id in 1:2) { | |
ID<-print(IDNUMS[id]) | |
FA_Map <- nifti.image.read(file=sprintf("%s_dti_FA.nii.gz", ID), read_data=1) | |
iLF_l <- nifti.image.read(file=sprintf("%s_ILF_L_fdt_thr.nii.gz", ID), read_data=1) | |
iLF_r <- nifti.image.read(file=sprintf("%s_ILF_R_fdt_thr.nii.gz", ID), read_data=1) | |
sLF_l <- nifti.image.read(file=sprintf("%s_SLF_L_fdt_thr.nii.gz", ID), read_data=1) | |
sLF_r <- nifti.image.read(file=sprintf("%s_SLF_R_fdt_thr.nii.gz", ID), read_data=1) | |
#prints track position: 19 is for s(superior), 9 is for i(inferior) | |
for (p in c(9, 19)) { | |
#print track side: 18 is for r (right side), 12 is for l (left side) | |
for (s in c(12, 18)) { | |
#prints superior first then inferior | |
zhighest=0 | |
xhighest=0 | |
yhighest=0 | |
zv=0 | |
x=0 | |
y=0 | |
#the width and height of a single image | |
x11(12,20) | |
par(mfrow=c(1,3), ps = 30 ) | |
for (i in 1:64) { | |
#prints z slice | |
output<-nnzero(eval(parse(text = sprintf("%sLF_%s[,,i,1]", paste(letters[p]), paste(letters[s]) )))) | |
if(output > zhighest) { | |
zhighest=output | |
zv=i | |
} | |
} | |
image(z=FA_Map[,,zv,1], col=grey((0:32)/32), axes=FALSE, xlab = sprintf("z = %s", zv) ) | |
par(new=TRUE) | |
image(eval(parse(text = sprintf("z=%sLF_%s[,,zv,1]", paste(letters[p]), paste(letters[s]) ))), col=topo.colors(7, alpha = 0.2), axes=FALSE) | |
#prints the x slice | |
for (i in 1:127) { | |
output<-nnzero(eval(parse(text = sprintf("%sLF_%s[i,,,1]", paste(letters[p]), paste(letters[s]) )))) | |
if(output > xhighest) { | |
xhighest=output | |
x=i | |
} | |
} | |
image(z=FA_Map[x,,,1], col=grey((0:32)/32), axes=FALSE, xlab = sprintf("x = %s", x) ) | |
par(new=TRUE) | |
image(eval(parse(text = sprintf("z=%sLF_%s[x,,,1]", paste(letters[p]), paste(letters[s]) ))), col=topo.colors(7, alpha = 0.2), axes=FALSE) | |
par(new=FALSE) | |
title(main = sprintf("%s %sLF_%s",ID, toupper(paste(letters[p])), toupper(paste(letters[s]))), font.main = 2) | |
#prints y slice | |
for (i in 1:127) { | |
output<-nnzero(eval(parse(text = sprintf("%sLF_%s[,i,,1]", paste(letters[p]), paste(letters[s]) )))) | |
if(output > yhighest) { | |
yhighest=output | |
y=i | |
} | |
} | |
image(z=FA_Map[,y,,1], col=grey((0:32)/32), axes=FALSE, xlab = sprintf("y = %s", y) ) | |
par(new=TRUE) | |
image(eval(parse(text = sprintf("z=%sLF_%s[,y,,1]", paste(letters[p]), paste(letters[s]) ))), col=topo.colors(7, alpha = 0.2), axes=FALSE) | |
par(new=FALSE) | |
#gets user's input (Note: removing the question saves time, and lets the user see which slice they are viewing) | |
#ans <- readline("Are these images acceptable? (y/n)") | |
#if (ans=="n") { | |
#com<-readline(sprintf("%s, %s position, %s side:", ID, toupper(paste(letters[p])), toupper(paste(letters[s])) )) | |
#add brake to allow the user to answer the question before showing the next image | |
# adds to a file located where R was started | |
#maybe adding all SL, SR, IL, IR in one line ... | |
#write(sprintf("%s %s %s %s", ID, toupper(paste(letters[p])), toupper(paste(letters[s])), com), file="comments.txt", append = TRUE) | |
#} | |
} | |
} | |
} | |
#notes: | |
#maybe if n is set to something, then close images - command | |
#n <- ifelse(grepl("\\D",n),-1,as.integer(n)) | |
#if(is.na(n)){break} # breaks when hit enter | |
#par new true is the opposite due to the lattice library requested |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment