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

[ENH] Add --refresh flag to dm_qc_report #367

Merged
merged 6 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
34 changes: 23 additions & 11 deletions bin/dm_qc_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
<session> Datman name of session to process e.g. DTI_CMH_H001_01_01

Options:
--remake Delete and recreate all QC metrics.
--refresh Update dashboard metadata (e.g. header diffs, scan
lengths) and generate missing metrics, if any. Note
that existing QC metrics will not be modified.
--remake Delete and recreate all QC metrics. Also force update
of dashboard metadata (e.g. header diffs, scan lengths).
--log-to-server If set, all log messages will also be sent to the
configured logging server. This is useful when the
script is run on the queue, since it swallows logging.
Expand All @@ -22,7 +26,7 @@

Requires:
FSL/5.0.10
MATLAB/R2014a - qa-dti phantom pipeline
matlab/R2014a - qa-dti phantom pipeline
AFNI/2014.12.16 - abcd_fmri phantom pipeline
"""

Expand All @@ -47,15 +51,18 @@
logger = logging.getLogger(os.path.basename(__file__))

REMAKE = False
REFRESH = False


def main():
global REMAKE
global REFRESH

arguments = docopt(__doc__)
study = arguments["<study>"]
session = arguments["<session>"]
REMAKE = arguments["--remake"]
REFRESH = arguments["--refresh"]
use_server = arguments["--log-to-server"]
verbose = arguments["--verbose"]
debug = arguments["--debug"]
Expand Down Expand Up @@ -141,7 +148,7 @@ def submit_subjects(config):
subs = get_subids(config)

for subject in subs:
if not (REMAKE or needs_qc(subject, config)):
if not (REMAKE or REFRESH or needs_qc(subject, config)):
continue

command = make_command(subject)
Expand All @@ -150,7 +157,7 @@ def submit_subjects(config):
logger.info(f"Submitting QC job for {subject}.")
datman.utils.submit_job(
command, job_name, "/tmp", system=config.system,
argslist="--mem=3G"
argslist="--mem=5G"
)


Expand Down Expand Up @@ -333,7 +340,7 @@ def update_dashboard(nii_path, header_ignore=None, header_tolerance=None):
"""
db_record = datman.dashboard.get_scan(nii_path)

if REMAKE or db_record.is_outdated_header_diffs():
if REMAKE or REFRESH or db_record.is_outdated_header_diffs():
try:
db_record.update_header_diffs(
standard=db_record.gold_standards[0],
Expand All @@ -344,7 +351,7 @@ def update_dashboard(nii_path, header_ignore=None, header_tolerance=None):
f"exception: {e}"
)

if REMAKE or not db_record.length:
if REMAKE or REFRESH or not db_record.length:
add_scan_length(nii_path, db_record)


Expand Down Expand Up @@ -404,11 +411,16 @@ def add_scan_length(nii_path, scan):


def remove_outputs(metric):
for item in metric.outputs:
try:
os.remove(item)
except FileNotFoundError:
pass
try:
os.remove(metric.manifest_path)
except FileNotFoundError:
pass
for command in metric.outputs:
for item in metric.outputs[command]:
try:
os.remove(item)
except FileNotFoundError:
pass


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion datman/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def write_manifest(self, overwrite=False):
if os.path.exists(self.manifest_path):
if not overwrite:
return
orig = self.read_json()
orig = self.read_manifest()
else:
orig = None

Expand Down
Loading