Skip to content

Commit

Permalink
Running black to correct the code and creating the first version with…
Browse files Browse the repository at this point in the history
… minor changes
  • Loading branch information
yasseraleman committed Mar 8, 2024
1 parent 9d256b0 commit 8214152
Show file tree
Hide file tree
Showing 13 changed files with 534 additions and 877 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ target/

# Jupyter Notebook
.ipynb_checkpoints
testing_notebook.ipynb

# pyenv
.python-version
Expand Down
4 changes: 2 additions & 2 deletions clabtoolkit/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Top-level package for Connectomics Lab Toolkit."""

__author__ = """Yasser Alemán-Gómez"""
__email__ = 'yasseraleman@protonmail.com'
__version__ = '0.0.1'
__email__ = "yasseraleman@protonmail.com"
__version__ = "0.1.0"
37 changes: 26 additions & 11 deletions clabtoolkit/bidstools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@

# This function copies the BIDs folder and its derivatives for e given subjects to a new location
def _copy_bids_folder(
bids_dir: str, out_dir: str, fold2copy: list = ["anat"], subjs2copy: str = None, deriv_dir: str = None,
include_derivatives: bool = False):
bids_dir: str,
out_dir: str,
fold2copy: list = ["anat"],
subjs2copy: str = None,
deriv_dir: str = None,
include_derivatives: bool = False,
):
"""
Copy full bids folders
@params:
bids_dir - Required : BIDs dataset directory:
out_dir - Required : Output directory:
fold2copy - Optional : List of folders to copy: default = ['anat']
subjs2copy - Optional : List of subjects to copy:
subjs2copy - Optional : List of subjects to copy:
deriv_dir - Optional : Derivatives directory: default = None
include_derivatives - Optional : Include derivatives folder: default = False
"""
Expand All @@ -28,12 +33,12 @@ def _copy_bids_folder(
subj_ids.sort()
else:
subj_ids = subjs2copy

# Selecting the derivatives folder
if include_derivatives:
if deriv_dir is None:
deriv_dir = os.path.join(bids_dir, "derivatives")

if not os.path.isdir(deriv_dir):
# Lunch a warning message if the derivatives folder does not exist
print("WARNING: The derivatives folder does not exist.")
Expand Down Expand Up @@ -83,7 +88,9 @@ def _copy_bids_folder(
directories = os.listdir(ses_dir)
fold2copy = []
for directory in directories:
if not directory.startswith(".") and os.path.isdir(os.path.join(ses_dir, directory)):
if not directory.startswith(".") and os.path.isdir(
os.path.join(ses_dir, directory)
):
print(directory)
fold2copy.append(directory)

Expand All @@ -108,22 +115,30 @@ def _copy_bids_folder(
for pipe_dir in der_pipe_folders:
if os.path.isdir(pipe_dir):

out_pipe_dir = os.path.join(out_dir, "derivatives", os.path.basename(pipe_dir))
out_pipe_dir = os.path.join(
out_dir, "derivatives", os.path.basename(pipe_dir)
)

pipe_indiv_subj_in = os.path.join(pipe_dir, subj_id, ses_id)
pipe_indiv_subj_out = os.path.join(out_pipe_dir, subj_id, ses_id)
pipe_indiv_subj_out = os.path.join(
out_pipe_dir, subj_id, ses_id
)

if os.path.isdir(pipe_indiv_subj_in):
try:
# Creating destination directory using make directory
os.makedirs(pipe_indiv_subj_out, exist_ok=True)

# Copying the folder
shutil.copytree(pipe_indiv_subj_in, pipe_indiv_subj_out, dirs_exist_ok=True)
shutil.copytree(
pipe_indiv_subj_in,
pipe_indiv_subj_out,
dirs_exist_ok=True,
)

except:
fail_deriv.append(pipe_indiv_subj_in)

# Print the failed sessions and derivatives
print(" ")
if fail_sess:
Expand All @@ -137,5 +152,5 @@ def _copy_bids_folder(
for i in fail_deriv:
print(i)
print(" ")

print("End of copying the files.")
6 changes: 3 additions & 3 deletions clabtoolkit/dicomtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from glob import glob
import subprocess


def sum(a, b):
return a + b


def _uncompress_dicom_session(dic_dir: str, subj_ids = None):
def _uncompress_dicom_session(dic_dir: str, subj_ids=None):
"""
Uncompress session folders
@params:
Expand All @@ -31,7 +32,6 @@ def _uncompress_dicom_session(dic_dir: str, subj_ids = None):
subj_ids = [x.strip() for x in subj_ids]
elif not isinstance(subj_ids, list):
raise ValueError("The subj_ids parameter must be a list or a string")


# Failed sessions
fail_sess = []
Expand Down Expand Up @@ -83,7 +83,7 @@ def _uncompress_dicom_session(dic_dir: str, subj_ids = None):
print("End of the uncompression process.")


def _compress_dicom_session(dic_dir: str, subj_ids = None):
def _compress_dicom_session(dic_dir: str, subj_ids=None):
"""
Compress session folders
@params:
Expand Down
2 changes: 1 addition & 1 deletion clabtoolkit/dwitools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


# This function removes the B0s volumes located at the end of the diffusion 4D volume.
def _remove_empty_dwi_Volume(dwifile):
def _remove_empty_dwi_Volume(dwifile: str):
"""
Remove the B0s volumes located at the end of the diffusion 4D volume.
@params:
Expand Down
4 changes: 0 additions & 4 deletions clabtoolkit/examples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



# _copy_bids_folder('/media/HPCdata/Mindfulness/', '/media/yaleman/HagmannHDD/Test/',["anat", "dwi"], ["sub-S001"], include_derivatives=True, deriv_dir='/media/HPCdata/Mindfulness/derivatives')
# _uncompress_dicom_session('/media/yaleman/Database/IMAGING-PROJECTS/Dicom')

Expand All @@ -24,4 +21,3 @@

# freelut = '/media/COSAS/Yasser/Work2Do/ReconVertDatabase/derivatives/chimera-atlases/sub-CHUVA001/ses-V2/anat/sub-CHUVA001_ses-V2_run-1_space-orig_atlas-chimeraLFMIIIFIF_desc-scale5growwm_dseg.lut'
# fsllut = '/home/yaleman/test.fsllut'

Loading

0 comments on commit 8214152

Please sign in to comment.