Skip to content

Commit

Permalink
add Shiny source code + minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardklap committed Dec 23, 2020
1 parent 1d77507 commit 0d71467
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 17 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/Qoala-T/QC/blob/master/LICENSE)

Version 1.2 > prediction model was updated January 14 2019; Github pages updated December 23 2020 <br />
Qoala-T is developed and created by [Lara Wierenga, PhD](https://brainanddevelopment.nl/people/lara-wierenga/) and modified by [Eduard Klapwijk, PhD](https://brainanddevelopment.nl/people/eduard-klapwijk/) in the [Brain and development research center](https://www.brainanddevelopment.nl).
Qoala-T is developed and created by [Lara Wierenga, PhD](https://brainanddevelopment.nl/people/lara-wierenga/) and modified by [Eduard Klapwijk, PhD](https://orcid.org/0000-0002-8936-0365) in the [Brain and development research center](https://www.brainanddevelopment.nl).
<br />

## About
Expand All @@ -25,12 +25,12 @@ We have also developed an app using R Shiny by which the Qoala-T model can be ru
- To be able to run the Qoala-T model, T1 MRI images should be processed in [FreeSurfer V6.0](https://surfer.nmr.mgh.harvard.edu/fswiki/DownloadAndInstall).
- Use the following script to extract the necessary information needed in order to perform Qoala-T: [Stats2Table.R](https://github.com/Qoala-T/QC/blob/master/Scripts/Stats2Table/Stats2Table.R)

*Note*: Stats2Table.R replaces extraction of necessary txt files using the [fswiki](https://surfer.nmr.mgh.harvard.edu/fswiki/freesurferstats2table) script or [stats2table_bash_qoala_t.sh](https://github.com/Qoala-T/QC/blob/master/Old/stats2table_bash_qoala_t.sh), which had to be merged using [this R script](https://github.com/Qoala-T/QC/blob/master/Old/Qoala_T_merge_example_script.R).
*Note*: the Stats2Table.R script replaces extraction of necessary txt files using the [fswiki](https://surfer.nmr.mgh.harvard.edu/fswiki/freesurferstats2table) script or [stats2table_bash_qoala_t.sh](https://github.com/Qoala-T/QC/blob/master/Old/stats2table_bash_qoala_t.sh), which had to be merged using [this R script](https://github.com/Qoala-T/QC/blob/master/Old/Qoala_T_merge_example_script.R).


### A. Predicting scan Qoala-T score by using Braintime model
- With this R script Qoala-T scores for a dataset are estimated using a supervised- learning model. This model is based on 784 T1-weighted imaging scans of subjects aged between 8 and 25 years old (53% females). The manual quality assessment is described in the Qoala-T manual [Manual quality control procedure for structural T1 scans](https://github.com/Qoala-T/QC/blob/master/Qoala-T_Manual.pdf), also available in the supplemental material of Klapwijk et al., (2019).
- To run the model-based Qoala-T option open [Qoala_T_A_model_based_github.R](https://github.com/Qoala-T/QC/blob/master/Scripts/Qoala-T_Scripts/Qoala_T_A_model_based_github.R) and follow the instructions. Alternatively you can run this option without having R installed, see the [Qoala-T app](https://qoala-t.shinyapps.io/qoala-t_app/).
- With this R script Qoala-T scores for a dataset are estimated using a supervised- learning model. This model is based on 784 T1-weighted imaging scans of subjects aged between 8 and 25 years old (53% females). The manual quality assessment is described in the Qoala-T manual [Manual quality control procedure for structural T1 scans](https://github.com/Qoala-T/QC/blob/master/Qoala-T_Manual.pdf), also available in the supplemental material of Klapwijk et al. (2019).
- To run the model-based Qoala-T option open [Qoala_T_A_model_based_github.R](https://github.com/Qoala-T/QC/blob/master/Scripts/Qoala-T_Scripts/Qoala_T_A_model_based_github.R) and follow the instructions. Alternatively you can run this option without having R installed, see the [Qoala-T app](https://qoala-t.shinyapps.io/qoala-t_app/) (source code [here](https://github.com/Qoala-T/QC/blob/master/Shiny/app.R)).

- An example output table (left) and output graph (right) showing the Qoala-T score of each scan are displayed below. The figure shows the number of included and excluded predictions. The grey area represents the scans that are recommended for manual quality assesment. <br /> <br />

Expand All @@ -49,17 +49,16 @@ We have also developed an app using R Shiny by which the Qoala-T model can be ru
- To run the subset-based Qoala-T option open [Qoala_T_B_subset_based_github.R](https://github.com/Qoala-T/QC/blob/master/Scripts/Qoala-T_Scripts/Qoala_T_B_subset_based_github.R) and follow the instructions.<br /> <br />
A flowchart of these processes can be observed in A and B below. <br />
![FlowChart](https://github.com/Qoala-T/QC/blob/master/Figures/Flowchart_github.jpg "FlowChart")

#### Run Qoala-T subset based in a Jupyter notebook:
- **NEW**: Using this [Qoala-T Jupyter Notebook](https://github.com/Qoala-T/QC/blob/master/Notebooks/Qoala-T_Notebook_subset.ipynb) is the easiest way to get from your directory with FreeSurfer-processed data to Qoala-T predictions onde you have manually rated a subset of your data. Only prerequisite is you can run Jupyter Notebooks in R, for example by installing [Anaconda](https://www.anaconda.com/distribution/) and then follow [these instructions](https://docs.anaconda.com/anaconda/navigator/tutorials/r-lang/).
- **NEW**: Using this [Qoala-T Jupyter Notebook - subset-based](https://github.com/Qoala-T/QC/blob/master/Notebooks/Qoala-T_Notebook_subset.ipynb) is the easiest way to get from your directory with FreeSurfer-processed data to Qoala-T predictions onde you have manually rated a subset of your data. Only prerequisite is you can run Jupyter Notebooks in R, for example by installing [Anaconda](https://www.anaconda.com/distribution/) and then follow [these instructions](https://docs.anaconda.com/anaconda/navigator/tutorials/r-lang/).

### Using Qoala-T with longitudinal data
- When using Qoala-T within the [longitudinal FreeSurfer stream](https://surfer.nmr.mgh.harvard.edu/fswiki/LongitudinalProcessing), the QC predictions should be run within the first step of the processing pipeline (Step 1. the cross-sectional processing of the timepoints). It will not work with the output from the longitudinal stream, since the longitudinal processing does not provide the number of surface holes, which is needed for prediction.
- When running Qoala-T right after cross-sectional processing, bad quality scans/segmentations can be removed before running step 2 where the template from all time points is created. In this way the template will not be affected by a poor quality timepoint.

## Predictive accuracies in new datasets

In order to continuously evaluate the performance of the Qoala-T tool, we will report predictive accuracies for different datasets on this page. We invite researchers who performed both manual QC and used Qoala-T to share their performance metrics and some basic information about their sample. This can be done by creating a pull request for this Github page or by e-mailing to [e.t.klapwijk@fsw.leidenuniv.nl](mailto:e.t.klapwijk@fsw.leidenuniv.nl).
In order to continuously evaluate the performance of the Qoala-T tool, we will report predictive accuracies for different datasets on this page. We invite researchers who performed both manual QC and used Qoala-T to share their performance metrics and some basic information about their sample. This can be done by creating a pull request for this Github page or by e-mailing to [e.klapwijk@essb.eur.nl](mailto:e.klapwijk@essb.eur.nl).
The table below reports predictive accuracies in new datasets when using the BrainTime model (i.e., option A that can be run using the Shiny app).

<table class="tg">
Expand Down
10 changes: 5 additions & 5 deletions Scripts/Qoala-T_Scripts/Qoala_T_A_model_based_github.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dataset_name <- "your_dataset_name"
# Or Load example with simulated data
# -----------------------------------------------------------------
# This is an example file
# githubURL <- "https://github.com/Qoala-T/QC/blob/master/simulated_data_A_model.Rdata?raw=true","Qoala_T_model"
# githubURL <- "https://github.com/Qoala-T/QC/blob/master/ExampleData/simulated_data_A_model.Rdata?raw=true","Qoala_T_model"
# test_data <- get(load(url(githubURL)))

# -----------------------------------------------------------------
Expand All @@ -60,7 +60,7 @@ githubURL <- "https://github.com/Qoala-T/QC/blob/master/Qoala_T_model.Rdata?raw=
rf.tune <- get(load(url(githubURL)))

# -----------------------------------------------------------------
#reorder colnames of dataset to match traningset
#reorder colnames of dataset to match trainingset
# -----------------------------------------------------------------
dataset_colnames <- names(rf.tune$trainingData)[-ncol(rf.tune$trainingData)]
testing <- test_data[,dataset_colnames]
Expand All @@ -78,14 +78,14 @@ head(rf.probs)
# ----------------------------------------------------------------
# create empty data frame
Qoala_T_predictions <- data.frame(matrix(ncol = 4, nrow = nrow(rf.probs)))
colnames(Qoala_T_predictions) = c('VisitID','Scan_QoalaT', 'Recommendation', 'manual_QC_adviced')
colnames(Qoala_T_predictions) = c('participant_id','Scan_QoalaT', 'Recommendation', 'manual_QC_adviced')

# fill data frame
Qoala_T_predictions$VisitID <- row.names(rf.probs)
Qoala_T_predictions$participant_id <- row.names(rf.probs)
Qoala_T_predictions$Scan_QoalaT <- rf.probs$Include*100
Qoala_T_predictions$Recommendation <- rf.pred
Qoala_T_predictions$manual_QC_adviced <- ifelse(Qoala_T_predictions$Scan_QoalaT<70&Qoala_T_predictions$Scan_QoalaT>30,"yes","no")
Qoala_T_predictions <- Qoala_T_predictions[order(Qoala_T_predictions$Scan_QoalaT, Qoala_T_predictions$VisitID),]
Qoala_T_predictions <- Qoala_T_predictions[order(Qoala_T_predictions$Scan_QoalaT, Qoala_T_predictions$participant_id),]


csv_Qoala_T_predictions = paste(outputFolder,'Qoala_T_predictions_model_based_',dataset_name,'.csv', sep = '')
Expand Down
10 changes: 5 additions & 5 deletions Scripts/Qoala-T_Scripts/Qoala_T_B_subset_based_github.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dataset_name <- "your_dataset_name"
# This is an example file
# dataset_name <- "simulated_data" # edit to your dataset name
# #
# githubURL <- "https://github.com/Qoala-T/QC/blob/master/simulated_data_B_subset.Rdata?raw=true"
# githubURL <- "https://github.com/Qoala-T/QC/blob/master/ExampleData/simulated_data_B_subset.Rdata?raw=true"
# dataset <- get(load(url(githubURL)))
# # -----------------------------------------------------------------

Expand All @@ -68,7 +68,7 @@ githubURL <- "https://github.com/Qoala-T/QC/blob/master/Qoala_T_model.Rdata?raw=
rf.tune <- get(load(url(githubURL)))

# -----------------------------------------------------------------
# reorder colnames of dataset to match traningset
# reorder colnames of dataset to match trainingset
# -----------------------------------------------------------------
dataset_names <- c("Rating",names(rf.tune$trainingData)[-ncol(rf.tune$trainingData)])
dataset <- dataset[,dataset_names]
Expand Down Expand Up @@ -121,14 +121,14 @@ head(rf.probs)
# ----------------------------------------------------------------
# create empty data frame
Qoala_T_predictions_subset_based <- data.frame(matrix(ncol = 4, nrow = nrow(rf.probs)))
colnames(Qoala_T_predictions_subset_based) = c('VisitID','Scan_QoalaT', 'Recommendation', 'manual_QC_adviced')
colnames(Qoala_T_predictions_subset_based) = c('participant_id','Scan_QoalaT', 'Recommendation', 'manual_QC_adviced')

# fill data frame
Qoala_T_predictions_subset_based$VisitID <- row.names(rf.probs)
Qoala_T_predictions_subset_based$participant_id <- row.names(rf.probs)
Qoala_T_predictions_subset_based$Scan_QoalaT <- rf.probs$Include*100
Qoala_T_predictions_subset_based$Recommendation <- rf.pred
Qoala_T_predictions_subset_based$manual_QC_adviced <- ifelse(Qoala_T_predictions_subset_based$Scan_QoalaT<60&Qoala_T_predictions_subset_based$Scan_QoalaT>40,"yes","no")
Qoala_T_predictions_subset_based <- Qoala_T_predictions_subset_based[order(Qoala_T_predictions_subset_based$Scan_QoalaT, Qoala_T_predictions_subset_based$VisitID),]
Qoala_T_predictions_subset_based <- Qoala_T_predictions_subset_based[order(Qoala_T_predictions_subset_based$Scan_QoalaT, Qoala_T_predictions_subset_based$participant_id),]


csv_Qoala_T_predictions_subset_based = paste(outputFolder,'Qoala_T_predictions_subset_based',dataset_name,'.csv', sep = '')
Expand Down
Loading

0 comments on commit 0d71467

Please sign in to comment.