Skip to content

Commit

Permalink
Merge pull request #1 from jomasator2/MIDS36
Browse files Browse the repository at this point in the history
Mids36
  • Loading branch information
jomasator2 authored Jun 15, 2023
2 parents 3e6e79d + 0bf4bfc commit 56b38da
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 172 deletions.
62 changes: 3 additions & 59 deletions xnat2mids/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,7 @@
This application allow the user to download one project on XNAT and
transform this project in MIDS format
There are 2 functions in this code:
download one project from xnat application:
arguments:
Prefix -w --web PAGE_WEB 1) The URL page where XNAT is.
Prefix -p --project [PROJECTS] 2) The project name to download
Prefix -i --input PATH 3) the directory where the files
will be downloaded
Prefix -u --user [USER] 4) The username to login in XNAT
If not write a username, It
loggin as guest.
Convert the xnat directories of the project in MIDS format:
arguments:
Prefix -i --input PATH 1) the directory where the files will
be downloaded
Prefix -o --output PATH 2) Directory where the MIDS model
is applied.
"""
###############################################################################
# Imports
Expand Down Expand Up @@ -93,49 +77,9 @@ def main():
This sorfware allows the user to Download one project into XNAT platform
and convert the XNAT images directory in MIDS directory.
The aplication execution needs Python --version >= 3.5.
there are 2 functions in this code:
Download temporary projects from xnat application:
arguments:
+ Prefix -w --web PAGE_WEB 1) The URL page where XNAT is.
+ Prefix -u --user [USER] 2) The username to login in XNAT
If not write a username, It logins
as guest.
+ Prefix -i --input INPUT 4) The directory where the
files will be downloaded.
+ Prefix -t --types [sdnbr] 5) Download types of MRI images
included in xnat
- d = dicom + dicom metadata in
folder NIFTI
- n = nifti or png if image is
one slide (2D) + roi
- b = BIDS (only in CENTRAL XNAT)
- r = Structural report
default = nr
The aplication execution needs Python --version >= 3.6.7
+ Prefix --overwrite 5) Overwrite download files
Convert the xnat directories of the project in MIDS format:
arguments:
+ Prefix -i --input INPUT 1) The directory where the files
will be downloaded.
+ Prefix -o --output OUTPUT 2) Directory where the MIDS model
is applied.
+ Prefix -bp --body-part 3) Specify which part of the body are
in the dataset(A clear dataset with
only one part are needed)
"""
"""
)
parser.add_argument('-w', '--web', type=str, default=None,
help='The URL page where XNAT is.')
Expand Down
10 changes: 3 additions & 7 deletions xnat2mids/conversion/io_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
"""


def add_tag_dicom(tag, description, value, json_file_path):
def add_tags_dicom(tag_dict, json_file_path):
json_file = load_json(json_file_path)
for i in range(len(json_file["ResultSet"]["Result"])):
if json_file["ResultSet"]["Result"][i]["tag1"] == tag:
json_file["ResultSet"]["Result"][i]["value"] = value
break
else:
json_file["ResultSet"]["Result"].append({"tag1":tag, "tag2":"", "desc":description, "value":value})
for tag, value in tag_dict.items():
json_file[tag] = value
save_json(json_file, json_file_path)


Expand Down
10 changes: 5 additions & 5 deletions xnat2mids/mids_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import pandas

from xnat2mids.conversion.io_json import load_json
from xnat2mids.conversion.io_json import add_tags_dicom
from xnat2mids.procedures.magnetic_resonance_procedures import ProceduresMR
from xnat2mids.procedures.light_procedures import LightProcedure
from xnat2mids.protocols.scans_tagger import Tagger
Expand Down Expand Up @@ -115,7 +116,7 @@ def create_directory_mids_v1(xnat_data_path, mids_data_path, body_part):

mids_session_path = mids_data_path.joinpath(subject_name, session_name)
xml_session_rois = list(sessions_xnat_path.rglob('*.xml'))
#print(f"1: {mids_session_path=}")
#print(f"1: {mids_session_path}")
tagger = Tagger()
tagger.load_table_protocol(
'./xnat2mids/protocols/protocol_RM_prostate.tsv'
Expand All @@ -133,7 +134,6 @@ def create_directory_mids_v1(xnat_data_path, mids_data_path, body_part):
path_dicoms= list(scans_path.joinpath("resources").rglob("*.dcm"))[0].parent
folder_conversion = dicom2niix(path_dicoms, options_dcm2niix) #.joinpath("resources")
else:

path_dicoms= list(scans_path.joinpath("resources").rglob("*.dcm"))[0].parent
folder_conversion = dicom2png(path_dicoms, options_dcm2niix) #.joinpath("resources")

Expand Down Expand Up @@ -165,8 +165,8 @@ def create_directory_mids_v1(xnat_data_path, mids_data_path, body_part):
"
# print()
# print(modality, study_description, ProtocolName, image_type)
print(f"{study_description=}")
print(f"{Protocol_name=}")
print(f"{study_description}")
print(f"{Protocol_name}")
if modality == "MR":
# via BIDS protocols
searched_prost = prostate_pattern_comp.search(study_description)
Expand All @@ -184,7 +184,7 @@ def create_directory_mids_v1(xnat_data_path, mids_data_path, body_part):
folder_conversion, mids_session_path, session_name, protocol, acq, dir_, folder_BIDS, body_part
)

if modality == "OP":
if modality in ["OP", "SC", "XC", "OT"]:
laterality = dict_json.get("Laterality")
acq = "" if "ORIGINAL" in image_type else "opacitysubstract"
# print(laterality, acq)
Expand Down
4 changes: 2 additions & 2 deletions xnat2mids/procedures/light_procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def copy_sessions(self, subject_name):
df_aux.index = numpy.arange(1, len(df_aux) + 1)
print(len(df_aux))
activate_run = True if len(df_aux) > 1 else False
print(f"{activate_run=}")
print(f"{activate_run}")
for index, row in df_aux.iterrows():
activate_acq_partioned = True if len(row['run']) > 1 else False
for acq, file_ in enumerate(sorted(row['run'])):
Expand Down Expand Up @@ -64,7 +64,7 @@ def calculate_name(self, subject_name, key, num_run, num_part, activate_run, act
rec = f"{key_list[1] if key_list[1] else ''}"
chunk = f"{num_part+1 if activate_acq_partioned else ''}"
run = f"{num_run if activate_run else ''}"
print(f"{run=}")
print(f"{run}")
# print(f"{key=}")
return "_".join([
part for part in [
Expand Down
2 changes: 1 addition & 1 deletion xnat2mids/procedures/magnetic_resonance_procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def calculate_name(self, subject_name, keys, num_run, num_part, activate_run, ac
print(num_part, activate_acq_partioned)
acq = f"{keys[1] if keys[1] else ''}"
chunk = f"{num_part if activate_acq_partioned else ''}"
print(f"{keys=}")
print(f"{keys}")
return "_".join([
part for part in [
subject_name,
Expand Down
22 changes: 0 additions & 22 deletions xnat2mids/protocols/protocol_RM_brain_old_old.tsv

This file was deleted.

Loading

0 comments on commit 56b38da

Please sign in to comment.