Skip to content

Commit

Permalink
refactor(styling):Refactor code formatting and style
Browse files Browse the repository at this point in the history
  • Loading branch information
jjjermiah committed Jan 30, 2024
1 parent 90e8e2f commit 6d6da1b
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 41 deletions.
8 changes: 7 additions & 1 deletion src/nbiatoolkit/dicomsort/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
from .dicomsort import DICOMSorter, DICOMSorter_cli
from .helper_functions import parseDICOMKeysFromFormat, sanitizeFileName, truncateUID

__all__ = ["DICOMSorter", "parseDICOMKeysFromFormat", "sanitizeFileName", "truncateUID", "DICOMSorter_cli"]
__all__ = [
"DICOMSorter",
"parseDICOMKeysFromFormat",
"sanitizeFileName",
"truncateUID",
"DICOMSorter_cli",
]
6 changes: 2 additions & 4 deletions src/nbiatoolkit/nbia.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tqdm import tqdm
from pyfiglet import Figlet
import os

# set __version__ variable
__version__ = "0.12.1"

Expand Down Expand Up @@ -147,10 +148,7 @@ def getPatients(self, Collection: str = "") -> Union[list[dict[str, str]], None]
patient["PatientId"]
)


patientList.append(
patient
)
patientList.append(patient)

return patientList

Expand Down
131 changes: 95 additions & 36 deletions src/nbiatoolkit/nbia_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
query: str
output: str | None = None


def version():
f = Figlet(font="slant")
print(f.renderText("NBIAToolkit"))
Expand All @@ -41,9 +42,8 @@ def writeResultsToFile(results: List, output: str) -> None:

# open the file in write mode
with open(output, "w") as f:

if isinstance(results[0], dict):

Check warning on line 45 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L44-L45

Added lines #L44 - L45 were not covered by tests
# write the header
# write the header
f.write("\t".join(results[0].keys()) + "\n")

Check warning on line 47 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L47

Added line #L47 was not covered by tests
# write the results
for result in results:
Expand Down Expand Up @@ -83,27 +83,23 @@ def getResults_cli(func, **kwargs) -> None:
writeResultsToFile(results, output)
return
elif not isinstance(results, list) or not len(results):

return

Check warning on line 86 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L82-L86

Added lines #L82 - L86 were not covered by tests
# Print the result
elif isinstance(results[0], dict) and len(results):
print("\t".join(results[0].keys()))
for result in results:
print("\t".join(str(value) for value in result.values())) # type: ignore
print("\t".join(str(value) for value in result.values())) # type: ignore
return

Check warning on line 92 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L88-L92

Added lines #L88 - L92 were not covered by tests

elif(isinstance(results, list)):
elif isinstance(results, list):
for result in results:
print(result)
return

Check warning on line 97 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L94-L97

Added lines #L94 - L97 were not covered by tests


print(f"No {query} found. Check parameters using -h or try again later.")
return

Check warning on line 100 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L99-L100

Added lines #L99 - L100 were not covered by tests




def cli_wrapper(func, **kwargs) -> List[str] | None:
"""
Wraps a function call with a loading animation.
Expand Down Expand Up @@ -155,22 +151,26 @@ def loading_animation():
# Find the maximum length of the loading animation strings
# print(animations[0])
while not done_event.is_set():

if done_event.is_set():

Check warning on line 154 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L153-L154

Added lines #L153 - L154 were not covered by tests
# clear the line
# sys.stdout.write("\033[F")
# print( len(animations[0]))
# print(" " * len(animations[0]), end="\r")
break

Check warning on line 159 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L159

Added line #L159 was not covered by tests


def getPatients_cli() -> None:
global query
global output
query = "patients"
p = general_argParser()

Check warning on line 166 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L165-L166

Added lines #L165 - L166 were not covered by tests

p.add_argument(

Check warning on line 168 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L168

Added line #L168 was not covered by tests
"--collection", dest="collection", action="store", required=True, type=str,
"--collection",
dest="collection",
action="store",
required=True,
type=str,
)
args = p.parse_args()

Check warning on line 175 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L175

Added line #L175 was not covered by tests

Expand All @@ -192,8 +192,12 @@ def getCollections_cli() -> None:
p = general_argParser()

Check warning on line 192 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L192

Added line #L192 was not covered by tests

p.add_argument(

Check warning on line 194 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L194

Added line #L194 was not covered by tests
"--prefix", dest="prefix", action="store", default="", type=str,
help = "The prefix to filter collections by, i.e \'TCGA\', \'LIDC\', \'NSCLC\'"
"--prefix",
dest="prefix",
action="store",
default="",
type=str,
help="The prefix to filter collections by, i.e 'TCGA', 'LIDC', 'NSCLC'",
)
args = p.parse_args()
if args.version:
Expand All @@ -205,59 +209,97 @@ def getCollections_cli() -> None:

return getResults_cli(func=NBIAClient().getCollections, prefix=args.prefix)

Check warning on line 210 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L210

Added line #L210 was not covered by tests


def getBodyPartCounts_cli() -> None:
p = argparse.ArgumentParser(description="NBIAToolkit: get body part counts")

Check warning on line 214 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L214

Added line #L214 was not covered by tests

p.add_argument(

Check warning on line 216 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L216

Added line #L216 was not covered by tests
"--collection", dest="collection", action="store", default = "", type=str,
"--collection",
dest="collection",
action="store",
default="",
type=str,
)

args = p.parse_args()

Check warning on line 224 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L224

Added line #L224 was not covered by tests

global query
query = f"BodyPartCounts"

Check warning on line 227 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L227

Added line #L227 was not covered by tests

return getResults_cli(func=NBIAClient().getBodyPartCounts, Collection=args.collection)
return getResults_cli(

Check warning on line 229 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L229

Added line #L229 was not covered by tests
func=NBIAClient().getBodyPartCounts, Collection=args.collection
)

def getSeries_cli() -> None:

def getSeries_cli() -> None:
p = argparse.ArgumentParser(description="NBIAToolkit: get series")

Check warning on line 235 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L235

Added line #L235 was not covered by tests

p.add_argument(

Check warning on line 237 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L237

Added line #L237 was not covered by tests
"--collection", dest="collection", action="store", default = "", type=str,
"--collection",
dest="collection",
action="store",
default="",
type=str,
)

p.add_argument(

Check warning on line 245 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L245

Added line #L245 was not covered by tests
"--patientID", dest="patientID", action="store", default = "", type=str,
"--patientID",
dest="patientID",
action="store",
default="",
type=str,
)

p.add_argument(

Check warning on line 253 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L253

Added line #L253 was not covered by tests
"--studyInstanceUID", dest="studyInstanceUID", action="store", default = "", type=str,
"--studyInstanceUID",
dest="studyInstanceUID",
action="store",
default="",
type=str,
)

p.add_argument(

Check warning on line 261 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L261

Added line #L261 was not covered by tests
"--modality", dest="modality", action="store", default = "", type=str,
"--modality",
dest="modality",
action="store",
default="",
type=str,
)

p.add_argument(

Check warning on line 269 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L269

Added line #L269 was not covered by tests
"--seriesInstanceUID", dest="seriesInstanceUID", action="store", default = "", type=str,
"--seriesInstanceUID",
dest="seriesInstanceUID",
action="store",
default="",
type=str,
)

p.add_argument(

Check warning on line 277 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L277

Added line #L277 was not covered by tests
"--bodyPartExamined", dest="bodyPartExamined", action="store", default = "", type=str,
"--bodyPartExamined",
dest="bodyPartExamined",
action="store",
default="",
type=str,
)

p.add_argument(

Check warning on line 285 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L285

Added line #L285 was not covered by tests
"--manufacturerModelName", dest="manufacturerModelName", action="store", default = "", type=str,
"--manufacturerModelName",
dest="manufacturerModelName",
action="store",
default="",
type=str,
)

p.add_argument(

Check warning on line 293 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L293

Added line #L293 was not covered by tests
"--manufacturer", dest="manufacturer", action="store", default = "", type=str,
"--manufacturer",
dest="manufacturer",
action="store",
default="",
type=str,
)

args = p.parse_args()

Check warning on line 301 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L301

Added line #L301 was not covered by tests


global query
query = f"series"

Check warning on line 304 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L304

Added line #L304 was not covered by tests

Expand All @@ -273,6 +315,7 @@ def getSeries_cli() -> None:
Manufacturer=args.manufacturer,
)


def downloadSingleSeries_cli() -> None:
global query
query = f"series"

Check warning on line 321 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L321

Added line #L321 was not covered by tests
Expand All @@ -281,47 +324,63 @@ def downloadSingleSeries_cli() -> None:
p = argparse.ArgumentParser(description="NBIAToolkit: download a single series")

Check warning on line 324 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L324

Added line #L324 was not covered by tests

p.add_argument(

Check warning on line 326 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L326

Added line #L326 was not covered by tests
"--seriesUID", dest="seriesUID", action="store", required=True, type=str,
"--seriesUID",
dest="seriesUID",
action="store",
required=True,
type=str,
)

p.add_argument(

Check warning on line 334 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L334

Added line #L334 was not covered by tests
"--downloadDir", dest="downloadDir", action="store", required=True, type=str,
help = "The directory to download the series to"
"--downloadDir",
dest="downloadDir",
action="store",
required=True,
type=str,
help="The directory to download the series to",
)

p.add_argument(

Check warning on line 343 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L343

Added line #L343 was not covered by tests
"--filePattern", dest="filePattern", action="store", type=str,
"--filePattern",
dest="filePattern",
action="store",
type=str,
default="%PatientID/%StudyInstanceUID/%SeriesInstanceUID/%SOPInstanceUID.dcm",
help = "The file pattern to use when downloading the series"
help="The file pattern to use when downloading the series",
)

p.add_argument(

Check warning on line 352 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L352

Added line #L352 was not covered by tests
"--overwrite", action="store_true", default=False, help="Overwrite existing files"
"--overwrite",
action="store_true",
default=False,
help="Overwrite existing files",
)


args = p.parse_args()

Check warning on line 359 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L359

Added line #L359 was not covered by tests



return getResults_cli(

Check warning on line 361 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L361

Added line #L361 was not covered by tests
func=NBIAClient()._downloadSingleSeries,
SeriesInstanceUID=args.seriesUID,
downloadDir=args.downloadDir,
filePattern=args.filePattern,
overwrite=args.overwrite)
overwrite=args.overwrite,
)


def general_argParser():
global query
p = argparse.ArgumentParser(description=f"NBIAToolkit: {query} ")

Check warning on line 372 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L372

Added line #L372 was not covered by tests

p.add_argument(

Check warning on line 374 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L374

Added line #L374 was not covered by tests
"--output", dest="output", action="store", type=str, help="Output file (tsv works best)"
"--output",
dest="output",
action="store",
type=str,
help="Output file (tsv works best)",
)

p.add_argument(

Check warning on line 382 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L382

Added line #L382 was not covered by tests
"--version", "-v", action="store_true", help="Print the version number and exit"
)

return p

Check warning on line 386 in src/nbiatoolkit/nbia_cli.py

View check run for this annotation

Codecov / codecov/patch

src/nbiatoolkit/nbia_cli.py#L386

Added line #L386 was not covered by tests

0 comments on commit 6d6da1b

Please sign in to comment.