ADNI多模态神经影像整理笔记
目标:将ADNI下载的多模态格式影像转为BIDS存储格式的NIFTI文件
环境:Ubuntu 2020
工具包:
1. 下载影像
官网:https://ida.loni.usc.edu/login.jsp
注册账号,Proposal通过之后就可以下载了。
在IDA里面找到待下载的影像,打包下载。
推荐分数个压缩包下载,方便后续解压。
推荐使用advance research
2. 解压影像
用Ubuntu自带的解压工具即可解压。
由于传输故障可能出现无法解压的情况。下载完之后要及时查看,以便及时重下。
3. 汇总影像到一个目录下
以下步骤适用于dicom或者nifti格式
首先利用mv指令将所有包下的sub级别的目录移动到一起(如都移动到/adni/dicom/dti/
)。
mv alldti2/ADNI/* ~/adni/dicom/dti/
由于分批下载的特性,不同子包之间可能出现1️⃣重复下载 2️⃣同个被试的多次扫描出现在不同包里。
这两种情况均会导致mv失败。因此需要使用rsync进行一次同步。
rsync -av --ignore-existing alldti2/ADNI/* ~/adni/dicom/dti/
为节省空间,同步结束之后可以只保留/adni/dicom/dti/
,删除子包以及解压的子包。
4. 获得下载汇总表
汇总到一个文件夹后需要对下载情况进行评估。
目的主要是1️⃣找到异常影像(文件大小异常、volume数目异常等等)2️⃣ 统计跨模态的id
4.1汇总nifti格式的下载情况
*需要tidyverse包和glue包
# Returns a summary table of downloaded nifti files of a single modality
# Usage: summary_nifti(path). The path has "011_S_0003" "011_S_0005" "011_S_0005" "011_S_0005" ...
# "id_subject" "image_path" "image_size" "image_description" "image_date" "image_time" "image_ID"
summary_nifti <- function(path.download){
future::plan(future::multisession, workers = 8)
result <- furrr::future_map_dfr(list.files(path.download), function(id_subject) {
map_dfr(list.files(glue('{path.download}/{id_subject}')), function(image_description){
map_dfr(list.files(glue('{path.download}/{id_subject}/{image_description}')), function(image_time){
map_dfr(
list.files(glue('{path.download}/{id_subject}/{image_description}/{image_time}')),
function(image_ID){
filename <- list.files(glue('{path.download}/{id_subject}/{image_description}/{image_time}/{image_ID}'))
filepath <- glue('{path.download}/{id_subject}/{image_description}/{image_time}/{image_ID}/{filename}')
file_size = file.info(filepath)$size / 1000^2
return(
tibble(
id_subject = id_subject,
image_path = filepath,
image_size = file_size,
image_description = image_description,
image_time = image_time,
image_ID = image_ID
)
)
})
})
})
})
result.date <- result %>% separate(col = 'image_time', into = c('image_date', 'image_time'), sep = '_', extra = 'merge')
return(result.date)
}
4.2 汇总dicom格式下载情况
# Returns a summary table of downloaded nifti files of a single modality
# Usage: summary_nifti(path). The path has "011_S_0003" "011_S_0005" "011_S_0005" "011_S_0005" ...
# "id_subject" "image_path" "image_volume_size" "image_description" "image_date" "image_time" "image_ID"
summary_dicom <- function(path.download){
future::plan(future::multisession, workers = 3)
result <- furrr::future_map_dfr(list.files(path.download), function(id_subject) {
map_dfr(list.files(glue('{path.download}/{id_subject}')), function(image_description){
map_dfr(list.files(glue('{path.download}/{id_subject}/{image_description}')), function(image_time){
map_dfr(
list.files(glue('{path.download}/{id_subject}/{image_description}/{image_time}')),
function(image_ID){
dicom_path <- list.files(glue('{path.download}/{id_subject}/{image_description}/{image_time}/{image_ID}'))
return(
tibble(
id_subject = id_subject,
dicom_volume = length(list.files(dicom_path)),
dicom_path = dicom_path,
image_description = image_description,
image_time = image_time,
image_ID = image_ID
)
)
})
})
})
})
result.date <- result %>% separate(col = 'image_time', into = c('image_date', 'image_time'), sep = '_', extra = 'merge')
return(result.date)
}
共有 0 条评论