def setup(self, ctx): self._append_view(TextView(f"Remove {self.noun}?")) featuresettings = set(feature.setting for feature in ctx.spec.features if hasattr(feature, "setting")) self.confs = set( frozenset( setting.get("confounds_removal", []) + (["ICA-AROMA"] if setting.get("ica_aroma") is True else []) ) for setting in ctx.spec.settings[:-1] # only include active settings if setting.get("output_image", False) or setting["name"] in featuresettings) suggestion = ["ICA-AROMA"] if len(self.confs) > 0: inverse_options = {v: k for k, v in self.options.items()} suggestion = [ inverse_options[s] for s in first(self.confs) if s in inverse_options ] self.input_view = MultipleChoiceInputView(list( self.options.keys()), checked=suggestion, isVertical=True) self._append_view(self.input_view) self._append_view(SpacerView(1)) self.valuedict = None
def setup(self, ctx): self.choice = None self._append_view( TextView( "Specify the variables for which to calculate interaction terms" )) self.variables = ctx.database.metadata(ctx.spec.models[-1].spreadsheet, "variables") self.variables = apply_filters_to_variables( ctx.spec.models[-1].filters, self.variables) contrastvariables = set( ravel(contrast["variable"] for contrast in ctx.spec.models[-1].contrasts if contrast.get("type") == "infer") ) # names of all variables added to the model in the previous step self.variables = [ variable for variable in self.variables if variable["name"] in contrastvariables ] assert len( self.variables) > 0, "No variables to calculate interaction terms" varnames = [variable["name"] for variable in self.variables] options = [format_column(varname) for varname in varnames] self.str_by_varname = dict(zip(varnames, options)) self.input_view = MultipleChoiceInputView(options, isVertical=True) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self._append_view(TextView("Select which interaction terms to add to the model")) nvar = len(self.variables) terms = list( chain.from_iterable(combinations(self.variables, i) for i in range(2, nvar + 1)) ) self.term_by_str = {" * ".join(termtpl): termtpl for termtpl in terms} self.options = list(self.term_by_str.keys()) self.input_view = MultipleChoiceInputView(self.options, isVertical=True) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self._append_view(TextView("Specify the variables to add to the model")) self.variables = [ variable for variable in ctx.spec.analyses[-1].variables if variable.type != "id" ] self.varname_by_str = { _format_column(variable.name): variable.name for variable in self.variables } options = list(self.varname_by_str.keys()) self.input_view = MultipleChoiceInputView(options, checked=options) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self._append_view( TextView("Specify the variables for which to calculate interaction terms") ) assert ( len(ctx.spec.analyses[-1].variables) > 0 ), "No variables to calculate interaction terms" self.varname_by_str = { _format_column(variable.name): variable.name for variable in ctx.spec.analyses[-1].variables if variable.type != "id" } self.options = list(self.varname_by_str.keys()) self.input_view = MultipleChoiceInputView(self.options, isVertical=True) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self._append_view(TextView("Select subject-level analyses to include in this analysis")) assert ctx.spec.analyses is not None namesset = set() for analysis in ctx.spec.analyses: assert analysis.level is not None if ( analysis.level == "first" and analysis.type != "atlas_based_connectivity" and analysis.type != "image_output" ): namesset.add(analysis.name) names = list(namesset) self.input_view = MultipleChoiceInputView(names, checked=names) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self.is_first_run = True self.entities_by_analysis = self._resolve_tags(ctx) entitiesset = set.union(*[set(entities) for entities in self.entities_by_analysis.values()]) entitiesset &= set(self.aggregate_order) across = ctx.spec.analyses[-1].across if across in entitiesset: entitiesset.remove(across) self.entities = list(entitiesset) self.options = [ p.inflect(f"Aggregate across plural('{entity}')") for entity in self.entities ] self.optionstr_by_entity = {k: v for k, v in zip(self.entities, self.options)} if len(self.options) > 0: self._append_view(TextView("Aggregate scan-level statistics before analysis?")) self.input_view = MultipleChoiceInputView(self.options, checked=self.options) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self._append_view(TextView("ICA-AROMA will be performed")) self._append_view(SpacerView(1)) self._append_view(TextView("Remove other nuisance regressors?")) self.confs = set( analysis.tags.confounds_removed.as_tupl() for analysis in ctx.spec.analyses if analysis.tags is not None and analysis.tags.confounds_removed is not None and analysis.type != "image_output" ) suggestion = [] if len(self.confs) > 0: revopts = {v: k for k, v in self.options.items()} suggestion = [revopts[s] for s in ravel(first(self.confs))[1:] if s in revopts] self.input_view = MultipleChoiceInputView( list(self.options.keys()), checked=suggestion, isVertical=True ) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self._append_view( TextView("Specify the variables to add to the model")) self.variables = ctx.database.metadata(ctx.spec.models[-1].spreadsheet, "variables") self.variables = apply_filters_to_variables( ctx.spec.models[-1].filters, self.variables) self.variables = [ variable for variable in self.variables if variable["type"] != "id" ] varnames = [variable["name"] for variable in self.variables] options = [format_column(varname) for varname in varnames] self.varname_by_str = dict(zip(options, varnames)) self.input_view = MultipleChoiceInputView(options, checked=options) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self.result = None if (not hasattr(ctx.spec.features[-1], "conditions") or ctx.spec.features[-1].conditions is None or len(ctx.spec.features[-1].conditions) == 0): _get_conditions(ctx) self._append_view(TextView("Select conditions to add to the model")) conditions = ctx.spec.features[-1].conditions assert len(conditions) > 0, "No conditions found" self.options = [ _format_variable(condition) for condition in conditions ] self.str_by_varname = dict(zip(conditions, self.options)) self.input_view = MultipleChoiceInputView(self.options, checked=[*self.options]) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self.choice = None self.should_run = False self.is_first_run = True assert ctx.spec.features is not None self.namesset = set( feature.name for feature in ctx.spec.features if feature.type not in ["atlas_based_connectivity"]) assert len(self.namesset) > 0 if len(self.namesset) > 1: self.should_run = True self._append_view(TextView("Specify features to use")) names = sorted(list(self.namesset)) self.input_view = MultipleChoiceInputView(names, checked=names) self._append_view(self.input_view) self._append_view(SpacerView(1))
def setup(self, ctx): self.is_first_run = True self.choice = None # get entities to ask for model_obj = ctx.spec.models[-1] inputs = set(model_obj.inputs) assert inputs is not None and len(inputs) > 0 featureobjs = [] for obj in ctx.spec.features: if obj.name in inputs: if obj.type not in ["atlas_based_connectivity"]: featureobjs.append(obj) filepaths = ctx.database.get(**bold_filedict) setting_filters = dict() for setting in ctx.spec.settings: setting_filters[setting["name"]] = setting.get("filters") self.feature_entities = dict() for obj in featureobjs: filters = setting_filters[obj.setting] feature_filepaths = [*filepaths] if filters is not None and len(filters) > 0: feature_filepaths = ctx.database.applyfilters( feature_filepaths, filters) self.feature_entities[obj.name], _ = ctx.database.multitagvalset( aggregate_order, filepaths=feature_filepaths) entitiesset = set.union( * [set(entitylist) for entitylist in self.feature_entities.values()]) across = ctx.spec.models[-1].across assert across not in entitiesset self.entities = [ entity for entity in aggregate_order if entity in entitiesset ] # maintain order display_strs = [ entity_display_aliases[entity] if entity in entity_display_aliases else entity for entity in self.entities ] self.options = [ humanize(p.plural(display_str)) for display_str in display_strs ] self.optionstr_by_entity = dict(zip(self.entities, self.options)) if len(self.options) > 0: self._append_view( TextView("Aggregate scan-level statistics before analysis?")) self.input_view = MultipleChoiceInputView( self.options, checked=[ option for option in self.options if option != "task" ]) self._append_view(self.input_view) self._append_view(SpacerView(1))