Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_bids_cols(dataframe):
""" Returns columns corresponding to BIDS bits """
bids_comps = list(BIDS_COMP.keys())
bids_comps_present = list(set(dataframe.columns.ravel().tolist()) & set(bids_comps))
return [bit for bit in bids_comps if bit in bids_comps_present]
return in_prov, wf_details, sett_dict
in_iqms = Path(in_iqms)
with in_iqms.open() as jsonfile:
iqms_dict = load(jsonfile)
# Now, the in_iqms file should be correctly named
out_file = str(Path(in_iqms.with_suffix(".html").name).resolve())
# Extract and prune metadata
metadata = iqms_dict.pop("bids_meta", None)
mod = metadata.pop("modality", None)
prov, wf_details, _ = _get_details(iqms_dict, mod)
file_id = [metadata.pop(k, None) for k in list(BIDS_COMP.keys())]
file_id = [comp for comp in file_id if comp is not None]
if in_plots is None:
in_plots = []
else:
if any(("melodic_reportlet" in k for k in in_plots)):
REPORT_TITLES["bold"].insert(3, ("ICA components", "ica-comps"))
if any(("plot_spikes" in k for k in in_plots)):
REPORT_TITLES["bold"].insert(3, ("Spikes", "spikes"))
in_plots = [
(REPORT_TITLES[mod][i] + (read_report_snippet(v),))
for i, v in enumerate(in_plots)
]
pred_qa = None # metadata.pop('mriqc_pred', None)
for root_key in root_adds:
val = self.inputs._outputs.get(root_key, None)
if isinstance(val, dict):
self._out_dict.update(val)
else:
config.loggers.interface.warning(
'Output "%s" is not a dictionary (value="%s"), '
"discarding output.",
root_key,
str(val),
)
# Fill in the "bids_meta" key
id_dict = {}
for comp in list(BIDS_COMP.keys()):
comp_val = getattr(self.inputs, comp, None)
if isdefined(comp_val) and comp_val is not None:
id_dict[comp] = comp_val
id_dict["modality"] = self.inputs.modality
if isdefined(self.inputs.metadata) and self.inputs.metadata:
id_dict.update(self.inputs.metadata)
if self._out_dict.get("bids_meta") is None:
self._out_dict["bids_meta"] = {}
self._out_dict["bids_meta"].update(id_dict)
if isdefined(self.inputs.dataset):
self._out_dict["bids_meta"]["dataset"] = self.inputs.dataset
# Fill in the "provenance" key
rate_label="rater_1",
binarize=True,
site_name=None,
rate_selection="random",
collapse=True,
):
"""
Reads in the labels. Massage labels table to have the
appropriate format
"""
if isinstance(rate_label, str):
rate_label = [rate_label]
output_labels = rate_label
bids_comps = list(BIDS_COMP.keys())
y_df = pd.read_csv(
label_file, index_col=False, dtype={col: str for col in bids_comps}
)
# Find present bids bits and sort by them
bids_comps_present = get_bids_cols(y_df)
y_df = y_df.sort_values(by=bids_comps_present)
y_df.subject_id = y_df.subject_id.str.lstrip("sub-")
y_df[rate_label] = y_df[rate_label].apply(pd.to_numeric, errors="raise")
if len(rate_label) == 2:
np.random.seed(42)
ratermask_1 = ~np.isnan(y_df[[rate_label[0]]].values.ravel())
ratermask_2 = ~np.isnan(y_df[[rate_label[1]]].values.ravel())
all_rated = ratermask_1 & ratermask_2
),
(
[
"summary_fg_mean",
"summary_fg_stdv",
"summary_fg_k",
"summary_fg_p05",
"summary_fg_p95",
],
None,
),
],
}
if csv_file.suffix == ".csv":
def_comps = list(BIDS_COMP.keys())
dataframe = pd.read_csv(
csv_file, index_col=False, dtype={comp: object for comp in def_comps}
)
id_labels = list(set(def_comps) & set(dataframe.columns.ravel().tolist()))
dataframe["label"] = dataframe[id_labels].apply(
_format_labels, args=(id_labels,), axis=1
)
else:
dataframe = pd.read_csv(
csv_file, index_col=False, sep="\t", dtype={"bids_name": object}
)
dataframe = dataframe.rename(index=str, columns={"bids_name": "label"})
nPart = len(dataframe)
def read_iqms(feat_file):
""" Reads in the features """
feat_file = Path(feat_file)
if feat_file.suffix == ".csv":
bids_comps = list(BIDS_COMP.keys())
x_df = pd.read_csv(
feat_file, index_col=False, dtype={col: str for col in bids_comps}
)
# Find present bids bits and sort by them
bids_comps_present = list(set(x_df.columns.ravel().tolist()) & set(bids_comps))
bids_comps_present = [bit for bit in bids_comps if bit in bids_comps_present]
x_df = x_df.sort_values(by=bids_comps_present)
# Remove sub- prefix in subject_id
x_df.subject_id = x_df.subject_id.str.lstrip("sub-")
# Remove columns that are not IQMs
feat_names = list(x_df._get_numeric_data().columns.ravel())
for col in bids_comps:
try:
feat_names.remove(col)
except ValueError: