Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #128

Merged
merged 53 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
17a1397
experi9000
drcandacemakedamoore Apr 7, 2024
39b28b7
experi9000
drcandacemakedamoore Apr 7, 2024
5834805
update castor1
Jun 21, 2024
1b87637
labs update1
Jun 22, 2024
6c4d17e
recoding notebook
Jul 6, 2024
4d99681
labs for castor
Jul 12, 2024
3a343ac
pushy
Jul 12, 2024
c05e76f
two twleves as request
Jul 12, 2024
79cf301
non-baseline labs
Jul 13, 2024
f789dc7
question start corr
Jul 13, 2024
46f47e9
update tbe
Jul 17, 2024
30f0a3b
update with K00
Jul 17, 2024
b5e10d2
add neuropsy to volu
Jul 18, 2024
7979352
first moment labs sf
Jul 19, 2024
9bb89d9
updatedreadmespelling
AidaasinAyda Jul 19, 2024
a36d9ee
pray
Jul 20, 2024
8896dab
pray2
Jul 20, 2024
d9f2120
delete extra notebook
Jul 20, 2024
f7fbd46
add function to check dicom dimensions
Jul 20, 2024
3c5130f
fix fails
Jul 26, 2024
0eb2045
concatenate demographic_volumetrics_t0_first_try
AidaasinAyda Jul 26, 2024
a11673b
cleanup
Jul 26, 2024
05d9de8
checked aida's code
Jul 26, 2024
9363166
try to unbug sphinx
drcandacemakedamoore Jul 26, 2024
15c95a8
functions to examine commas
drcandacemakedamoore Aug 2, 2024
319daa8
near burnout
Aug 2, 2024
1b8a83d
finalize first labs
Aug 2, 2024
ce4020d
put together numeric score
Aug 9, 2024
3318e79
aslnitebook
drcandacemakedamoore Aug 17, 2024
799294e
bash scripts
drcandacemakedamoore Aug 18, 2024
754529b
good asl
drcandacemakedamoore Aug 18, 2024
c8785bb
rremove bad asl
drcandacemakedamoore Aug 18, 2024
aa1dc04
mel branch
Aug 23, 2024
76d24d2
further perfect labs
Aug 23, 2024
b1e4768
add more matched pipeline
drcandacemakedamoore Aug 23, 2024
835057b
switching paths for windows
Aug 30, 2024
3f49575
tabling asl outpus
drcandacemakedamoore Aug 30, 2024
ecbcbd7
verzamelen
drcandacemakedamoore Aug 31, 2024
35edfd1
missing asl
drcandacemakedamoore Sep 4, 2024
66f4f3d
fixing neuropsych data
Sep 6, 2024
9f1a9f1
mybe
drcandacemakedamoore Sep 6, 2024
ae5b28c
upload wisc wais
Sep 13, 2024
d24e730
wais changes
Sep 13, 2024
d90c705
pyd over dicoms
Sep 19, 2024
d7993cb
make csv file
Sep 13, 2024
52cd262
final wisc_wais
Sep 19, 2024
5694c38
cleanup minor 1 notebook
drcandacemakedamoore Oct 6, 2024
f2a5691
update freesurfer verzamel
drcandacemakedamoore Oct 11, 2024
1ed8666
interim analysis volbrain
AidaasinAyda Sep 27, 2024
925e251
Made it more castor-friendly for upload
AidaasinAyda Oct 15, 2024
b427696
kernel clear and add optional linux vs/ win paths
drcandacemakedamoore Oct 19, 2024
1c85e9a
obvious
drcandacemakedamoore Nov 8, 2024
befad1d
change name
drcandacemakedamoore Nov 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,5 @@ conda-pkg/meta.yaml
!tests/sample_synthetic_data/*.csv
secret_data/*
secret_data/
tmp_dcm2bids/*
tmp_dcm2bids/*
.Rproj.user
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<img style="width: 35%; height: 35%" src="image011.png">
</p>

brickstudy is an open source collaborative python library for analysis of data related to pediatric hematology patients, including and especially the neuroradiology data.
brickstudy is an open source collaborative python library for analysis of data related to sickle cell disease patients, including and especially the neuroradiology data.

brickstudy will include a main code library where the user can access the code.

The library is under construction.

Program files
The core functions of brickstudy are in the folder brickstudy.
Program Files
The core functions of brickstudy are in the folder "brickstudy".

Our guide to notebooks is under construction. To look around keep in mind the following distinction on folders:

Expand All @@ -21,13 +21,13 @@ These are a growing series of interactive notebooks that allow researchers to in

notebooks/experi:

This folder contains experimental work by core members of the BRICK team (Drs Candace Makeda Moore, Melanie Bruinooge and Aida Gebremeksel)
This folder contains experimental work by core members of the BRICK team Candace Makeda Moore,MD, Melanie Bruinooge, MD and Aida Gebremeksel, MD)
Data sets:
The notebooks are configured to run on various datasets. Contact Dr. Melanie Bruinooge( 📫 m.bruinooge@erasmusmc.nl) to discuss any questions on data configuration for your datasets.
The notebooks are configured to run on various datasets. Contact Melanie Bruinooge, MD (📫 m.bruinooge@erasmusmc.nl) to discuss any questions on data configuration for your datasets.

notebooks/teaching:

This folder contains teaching materials for learning the most basic basics of handeling data.
This folder contains teaching materials for learning the most basic basics of handling data.

A standardized dataset is under development.

Expand Down
13 changes: 13 additions & 0 deletions brickstudy.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
76 changes: 75 additions & 1 deletion brickstudy/foundation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from functools import reduce
import numpy as np
from datetime import datetime, date
# import pydicom as dicom
import pydicom as pydicom
import pandas as pd
import openpyxl
import skimage.io as io
Expand Down Expand Up @@ -181,6 +181,80 @@ def plot_slice(self, z):
vmin=0,
vmax=self.v[1],
)


def check_dimensions_of_voxel(image_string):
"""
This function if given a dicom string will return the dimensions as
a tuple, and print a message about them

"""
dcm_read = pydicom.dcmread(image_string)
voxel_width = dcm_read.PixelSpacing[0]
voxel_height = dcm_read.PixelSpacing[1]
slice_thickness = dcm_read.SliceThickness
print("Voxel dimensions are:", voxel_width, voxel_height, slice_thickness)
return (voxel_width, voxel_height, slice_thickness)


def map_for_commas(df):
"""
checks if there are any string values with commas in a pandas DataFrame,
and return a datadrame with booleans, then a dataframe to show the values

:param df: The DataFrame to check.
:type df: :class:`~pd.dateframe`
:return: tuple of two dataframes one with bools for check, one with values
:rtype: :class: tuple
"""
# apply a function to each element in the DataFrame to check for commas
bool_frame = df.applymap(lambda x: isinstance(x, str) and ',' in x)
bool_frame_applied = df[bool_frame]
return bool_frame, bool_frame_applied


def map_for_commas_if_all_strings(df):
"""
checks if there are any values with commas in a pandas DataFrame,
and returns a datadrame with bools, then a dataframe which shows values

:param df: The DataFrame to check.
:type df: :class:`~pd.dateframe`
:return: tuple of two dataframes based on with bools for check
:rtype: :class: tuple

"""
df = df.applymap(str)
# Apply a function to each element in the DataFrame to check for commas
bool_frame = df.applymap(lambda x: isinstance(x, str) and ',' in x)
bool_frame_applied = df[bool_frame]
return bool_frame, bool_frame_applied


def check_and_print_commas(df):
"""
converts all values in a DataFrame to strings,
then check if any values have commas.
If a value has a comma, print the location of the value.
Returns number of comma values

"""
# convert all values to strings
df = df.applymap(str)

counter = 0
# check for commas and print the location
for row_index, row in df.iterrows():
for col_index, value in row.items():
if ',' in value:
print(
f"Alert:comma row{row_index}, column{col_index}: {value}"
)
counter += 1

return counter


# class PydicomDicomReader:
# """Class for reading DICOM metadata with pydicom."""

Expand Down
15 changes: 15 additions & 0 deletions match_gen_r.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
for f in $(find /home/fsluser/pcasl_festival/json_holder_1/ -type f -name '*.nii.gz') ; do
out=pcasl_anat_output/$(basename $f)good2
stripped_basename=$(basename $f)
stripped_basename=${stripped_basename%.nii.gz}
anat=/home/fsluser/home_holder/$stripped_basename.anat
mkdir $out
# bolus duration not as in dicom data but as given by medical physics team
bolusDuration='0.22170496193,0.3720622289,1.18342832912'
# tistimes is a list of inflow times as specified by medical physics team (not DICOM)
tistimes='1.22170496193,2.15336425781,4.5'
# pvccorr adds partial volume correction
oxford_asl -i $f -o $out --fslanat $anat --tis=${tistimes} --bolus=${bolusDuration} --casl --pvcorr &
break
done
wait
195 changes: 195 additions & 0 deletions notebooks/Concatenate_volbrain_csvs_deeplesion.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## Volbrain deeplesion verzamelen"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This code is for organizing the Volbrain.net output of the DeepLesion Algorythm. It runs over the zip files in a specific folder, and extracts necessary information from the enclosed CSVs and puts themm all together in a table"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#load necessary libraries\n",
"import pandas as pd\n",
"import numpy as np \n",
"import zipfile\n",
"import os\n",
"from zipfile import ZipFile\n",
"import glob\n",
"from io import BytesIO"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#navigate to zipfolders and intended folder for output (change to commented out if on Windows)\n",
"# path_volbrain = 'Z:/processed_data/VolBrain'\n",
"# output_folder = \"Z:/processed_data/VolBrain/Separate_CSV_Deeplesion\"\n",
"path_volbrain = '/mnt/data/processed_data/VolBrain'\n",
"output_folder = \"/mnt/data/processed_data/VolBrain/Separate_CSV_Deeplesion\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#create a list to store the CSV headers in\n",
"all_data = []"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"dataframes = []\n",
"\n",
"for zip_file in glob.glob(os.path.join(path_volbrain, '*.zip')):\n",
" # split by underscores\n",
" participant_id = zip_file.split(\"_\")\n",
" # concatenate BRICK with 00X\n",
" participant_id = participant_id[1] + \"_\" + participant_id[2]\n",
" with ZipFile(zip_file, \"r\") as zf:\n",
" #get the list of files inside the zip (assumes 1 csv per zip folder)\n",
" for entry_name in zf.namelist():\n",
" if entry_name.endswith(\".csv\"):\n",
" entry = zf.read(entry_name)\n",
" df = pd.read_csv(BytesIO(entry), sep=';')\n",
" df['Participant Id'] = participant_id\n",
" dataframes.append(df)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"concat_df = pd.concat(dataframes)\n",
"concat_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#move the participant id row to the front. Now it's last. This is important for upload in castor.\n",
"concat_df = concat_df.loc[:, [concat_df.columns[-1]] + list(concat_df.columns[:-1])]\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"concat_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"#Now make the column names castor appropriate. Do not change the \"Participant Id\" column of course. dl stands for DeepLesion algorithm\n",
"concat_df.columns = [\n",
" col if col == \"Participant Id\" else \"dl_\" + col.replace(\" \", \"_\") + \"_T0\"\n",
" for col in concat_df.columns\n",
"]\n",
"\n",
"#For castor, male is 1 and female is 2. Replace these values\n",
"concat_df[\"dl_Sex_T0\"] = concat_df[\"dl_Sex_T0\"].replace({\"Female\": 2, \"Male\": 1})\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"concat_df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"# concat_df.to_csv('Z:/castor_proof_files/volbrains_castor.csv')\n",
"#(change to commented out if on Windows)\n",
"concat_df.to_csv('/mnt/data/castor_proof_files/volbrains_castor.csv')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading
Loading