-
Notifications
You must be signed in to change notification settings - Fork 15
/
Qoala_T_merge_example_script.R
51 lines (43 loc) · 2.61 KB
/
Qoala_T_merge_example_script.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Code to reproduce merging Freesurfer output files for Qoala-T Tool
# title: Qoala-T: A supervised-learning tool for quality control of FreeSurfer segmented MRI data
# author:
# - name: Klapwijk, E.T., van de Kamp, F., Meulen, M., Peters, S. and Wierenga, L.M.
# https://doi.org/10.1016/j.neuroimage.2019.01.014
#
# If you have any question or suggestion, dont hesitate to get in touch:
# https://github.com/Qoala-T/QC/issues
# -----------------------------------------------------------------
# Construct your dataset
# -----------------------------------------------------------------
#Instruction:
# row.names = MRI_ID
# col.names = colnames(simulated_data_A_model.RData)
# -----------------------------------------------------------------
# Construct your dataset for model-based and subset-based Qoala-T options
# -----------------------------------------------------------------
# Input directory to your data files including: aseg_stats.txt, aparc_area_lh.txt, aparc_area_rh.txt, aparc_thickness_lh.txt, aparc_thickness_rh.txt
inputFolder <- "~/Desktop/input_datafiles/"
setwd(inputFolder)
yourdatafile <- data.frame(read.table("aseg_stats.txt",sep="\t",header=TRUE))
row.names(yourdatafile) <- yourdatafile[,1]
yourdatafile <- yourdatafile[,-1]
for (j in c("aparc_area_lh.txt","aparc_area_rh.txt","aparc_thickness_lh.txt","aparc_thickness_rh.txt")) {
data = data.frame(read.table(paste(j,sep=""),sep="\t",header=TRUE))
row.names(data) <- data[,1]
data <- data[,-1]
yourdatafile <- merge(yourdatafile,data,by="row.names",all.x=T)
ifelse(grep("\\.y$", colnames(yourdatafile)),(yourdatafile <- yourdatafile[, -grep("\\.y$", colnames(yourdatafile))]) , yourdatafile)
names(yourdatafile) <- gsub("\\.x$", "", names(yourdatafile))
row.names(yourdatafile) <- yourdatafile[,1]
yourdatafile <- yourdatafile[,-1]
}
save(yourdatafile,file="yourdatafile.Rdata")
# -----------------------------------------------------------------
# Add rating for subset-based Qoala-T option (Qoala_T_B_subset_based_github.R; not necessary using when only using model-based Qoala-T option A)
# -----------------------------------------------------------------
# column one = Rating with two factor levels 'Include' and 'Exclude', here we simulated that 10% of data is rated, and for 90% of data there is no rating, indicated by NA's
# Make sure to create a text file named rating.txt that includes a column named MRI_ID and Rating
rating_yourdatafile <- data.frame(read.table("rating.txt",sep="\t",header=TRUE))
dataset <- merge(rating_yourdatafile,yourdatafile,by.x="MRI_ID",by.y="row.names",all.y=T)
row.names(dataset) <- dataset[,1]
dataset <- dataset[,-1]