def _update_qc_reviewers(entries): """ Support function for update_checklist(). Updates QC info on the dashboard. """ try: user = dashboard.get_default_user() except: raise MetadataException( "Can't update dashboard QC information without " "a default dashboard user defined. Please add " "'DEFAULT_DASH_USER' to your config file.") for subject in entries: timepoint = dashboard.get_subject(subject) if not timepoint or not timepoint.sessions: raise MetadataException("{} not found in the in the dashboard " "database.".format(subject)) comment = entries[subject] if not comment: # User was just registering a new QC entry. As long as the # session exists in the database there is no work to do. continue for num in timepoint.sessions: session = timepoint.sessions[num] if session.is_qcd(): # Dont risk writing over QC-ers from the dashboard. continue session.sign_off(user.id)
def _fetch_blacklist( scan=None, subject=None, bids_ses=None, study=None, config=None, use_bids=False, ): """ Helper function for 'read_blacklist()'. Gets the blacklist contents from the dashboard's database """ if not (scan or subject or study or config): raise MetadataException( "Can't retrieve dashboard blacklist info " "without either 1) a scan name 2) a subject " "ID 3) a study ID or 4) a datman config " "object" ) if scan: if use_bids: db_scan = dashboard.get_bids_scan(scan) else: db_scan = dashboard.get_scan(scan) if db_scan and db_scan.blacklisted(): try: return db_scan.get_comment() except Exception: return db_scan.get_comment() return if subject: if use_bids or bids_ses: if not bids_ses: bids_ses = "01" db_subject = dashboard.get_bids_subject(subject, bids_ses, study) else: db_subject = dashboard.get_subject(subject) blacklist = db_subject.get_blacklist_entries() else: if config: study = config.study_name db_study = dashboard.get_project(study) blacklist = db_study.get_blacklisted_scans() entries = {} for entry in blacklist: if use_bids: if not entry.scan.bids_name: # Ignore scans without a bids name if bids was requested continue scan_name = entry.scan.bids_name else: scan_name = str(entry.scan) + "_" + entry.scan.description entries[scan_name] = entry.comment return entries
def _fetch_blacklist(scan=None, subject=None, study=None, config=None): """ Helper function for 'read_blacklist()'. Gets the blacklist contents from the dashboard's database """ if not (scan or subject or study or config): raise MetadataException( "Can't retrieve dashboard blacklist info " "without either 1) a scan name 2) a subject ID 3) a study ID or " "4) a datman config object") if scan: db_scan = dashboard.get_scan(scan) if db_scan and db_scan.blacklisted(): try: return db_scan.get_comment().encode('utf-8') except: return db_scan.get_comment() return if subject: db_subject = dashboard.get_subject(subject) blacklist = db_subject.get_blacklist_entries() else: if config: study = config.study_name db_study = dashboard.get_project(study) blacklist = db_study.get_blacklisted_scans() entries = {} for entry in blacklist: scan_name = str(entry.scan) + "_" + entry.scan.description try: scan_name = scan_name.encode('utf-8') comment = entry.comment.encode('utf-8') except: comment = entry.comment entries[scan_name] = comment return entries
def process_subject(subject, cfg, be, bids_dir, rewrite): """ Convert subject in DATMAN folder to BIDS-style """ ident = scanid.parse(subject) subscan = scan.Scan(subject, cfg) bids_sub = ident.get_bids_name() bids_ses = ident.timepoint exp_path = make_bids_template(bids_dir, "sub-" + bids_sub, "ses-" + bids_ses) dm_to_bids = [] if dashboard.dash_found: db_subject = dashboard.get_subject(subject) db_subject.add_bids(bids_sub, bids_ses) # Construct initial BIDS transformation info scan_list = list(sort_by_series(subscan.niftis)) for i, series in enumerate(scan_list): # Construct bids name logger.info("Processing {}".format(series)) bids_dict = get_tag_bids_spec(cfg, series.tag, series.site) if not bids_dict: continue bids_dict.update({"sub": bids_sub, "ses": bids_ses}) # Deal with reference scans if bids_dict.get('is_ref', False): target_dict = get_tag_bids_spec(cfg, scan_list[i + 1].tag, series.site) bids_dict.update({'task': target_dict['task']}) bids_prefix = be.construct_bids_name(bids_dict) class_path = os.path.join(exp_path, bids_dict["class"]) # Make dm2bids transformation file, update source if applicable bidsfiles = BIDSFile(bids_sub, bids_ses, series, class_path, bids_prefix, bids_dict).update_source(cfg, be) if bidsfiles is None: logger.error("Cannot find derivative of {}".format(series)) logger.warning("Skipping!") continue if isinstance(bidsfiles, list): dm_to_bids.extend(bidsfiles) else: dm_to_bids.append(bidsfiles) # Apply prioritization calls dm_to_bids = prioritize_scans(dm_to_bids) # Prepare fieldmap information (requires knowledge about all scans) dm_to_bids = prepare_fieldmaps(dm_to_bids) # Transfer files over for k in dm_to_bids: if os.path.exists(k.dest_nii) and not rewrite: logger.info("Output file {} already exists!".format(k.dest_nii)) continue k.transfer_files() if dashboard.dash_found: db_series = dashboard.get_scan(k.series.path) db_series.add_bids(str(k)) return