Пример #1
0
    def __init__(self, parent, gpa_settings):

        wx.Frame.__init__(self, parent=parent,
                          title="CPAC - FSL FEAT Presets",
                          size=(700, 275))

        self.parent = parent
        self.gpa_settings = gpa_settings

        if "pheno_file" not in self.gpa_settings.keys():
            self.gpa_settings["pheno_file"] = ""
        if "participant_id_label" not in self.gpa_settings.keys():
            self.gpa_settings["participant_id_label"] = ""
        if "covariate" not in self.gpa_settings.keys():
            self.gpa_settings["covariate"] = ""

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.panel = wx.Panel(self)
        self.window = wx.ScrolledWindow(self.panel)

        self.page = generic_class.GenericClass(self.window,
                                               " FSL FEAT Group-Level "
                                               "Analysis - Model Presets")

        self.page.add(label="Phenotype/EV File ",
                      control=control.COMBO_BOX,
                      name="pheno_file",
                      type=dtype.STR,
                      comment="Full path to a .csv file containing EV "
                              "information for each subject.",
                      values=self.gpa_settings['pheno_file'])

        self.page.add(label="Participant Column Name ",
                      control=control.TEXT_BOX,
                      name="participant_id_label",
                      type=dtype.STR,
                      comment="Name of the participants column in your EV "
                              "file.",
                      values=self.gpa_settings['participant_id_label'],
                      style=wx.EXPAND | wx.ALL,
                      size=(160, -1))

        if "Covariate" in self.gpa_settings["flame_preset"]:
            self.page.add(label="Phenotype covariate to include: ",
                          control=control.TEXT_BOX,
                          name='covariate',
                          type=dtype.STR,
                          values=self.gpa_settings['covariate'],
                          comment="For the additional covariate for the "
                                  "single group average, enter the column "
                                  "name of the covariate in the phenotype "
                                  "file provided.",
                          size=(160, -1))
        elif "Unpaired" in self.gpa_settings["flame_preset"]:
            self.page.add(label="Two groups from pheno to compare: ",
                          control=control.TEXT_BOX,
                          name='covariate',
                          type=dtype.STR,
                          values=self.gpa_settings['covariate'],
                          comment="Enter the two column names of the group "
                                  "variables in the phenotype provided, "
                                  "separated by a comma. If the two groups "
                                  "are encoded in a single column, enter the "
                                  "name of that one column.",
                          size=(320, -1))

        self.page.set_sizer()

        mainSizer.Add(self.window, 1, wx.EXPAND)

        btnPanel = wx.Panel(self.panel, -1)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        buffer = wx.StaticText(btnPanel, label="\t\t\t\t\t\t")
        hbox.Add(buffer)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "Cancel", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.cancel, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "< Back", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.go_back, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        next = wx.Button(btnPanel, 3, "Generate Model", (200, -1),
                         wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.click_OK, id=3)
        hbox.Add(next, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        # reminder: functions bound to buttons require arguments
        #           (self, event)
        btnPanel.SetSizer(hbox)

        mainSizer.Add(
            btnPanel, 0.5,  flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20)

        self.panel.SetSizer(mainSizer)

        # TODO
        # text blurb depending on the specific preset

        self.Show()
Пример #2
0
    def __init__(self, parent, gpa_settings):

        wx.Frame.__init__(
            self, parent=parent, title="CPAC - FSL FEAT Presets",
            size=(550, 325))

        self.parent = parent
        self.gpa_settings = gpa_settings

        if "condition_type" not in self.gpa_settings.keys():
            self.gpa_settings["condition_type"] = "Sessions"
        if "conditions_list" not in self.gpa_settings.keys():
            self.gpa_settings["conditions_list"] = []

        if "Two-Sample Paired" in self.gpa_settings["flame_preset"]:
            num_condition = "two"
        elif "Tripled" in self.gpa_settings["flame_preset"]:
            num_condition = "three"

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        self.panel = wx.Panel(self)
        self.window = wx.ScrolledWindow(self.panel)

        self.page = generic_class.GenericClass(self.window,
                                               " Group-Level Analysis - FSL "
                                               "FEAT Presets")

        # TODO
        # text blurb depending on the specific preset

        self.page.add(label="Conditions: Sessions or Series? ",
                      control=control.CHOICE_BOX,
                      name="condition_type",
                      type=dtype.LSTR,
                      comment="Choose whether the {0} paired conditions you "
                              "wish to compare using the {1} are Sessions or "
                              "Series/Scans.\n\nFor example, if each "
                              "participant has {0} conditions each, are they "
                              "separated by session, or by multiple "
                              "functional series or scans within each a "
                              "single session each?".format(num_condition,
                                                            self.gpa_settings["flame_preset"]),
                      values=["Sessions", "Series"])

        self.page.add(label='Session or Series/Scan IDs: ',
                      control=control.LISTBOX_COMBO,
                      name='conditions_list',
                      type=dtype.LSTR,
                      values=self.gpa_settings['conditions_list'],
                      comment="Enter the {0} session or series/scan ID names "
                              "you wish to compare.\n\nIf they are sessions, "
                              "they can be found under 'unique_id' in the "
                              "individual-level data configuration YAML file "
                              "for the data in question, or in the "
                              "'participant_session' IDs that you would see "
                              "in the individual-level analysis output dir"
                              "ectory (ex. '3005_1' would be participant "
                              "3005, session 1).\n\nIf they are series/"
                              "scans, they will be the functional scan "
                              "names, which can be found in the data config"
                              "uration YAML file nested under "
                              "'func'.".format(num_condition),
                      size=(200, 100),
                      combo_type=7)

        self.page.set_sizer()

        mainSizer.Add(self.window, 1, wx.EXPAND)

        btnPanel = wx.Panel(self.panel, -1)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        buffer = wx.StaticText(btnPanel, label="\t\t\t\t\t\t")
        hbox.Add(buffer)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "Cancel", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.cancel, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "< Back", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.go_back, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        next = wx.Button(btnPanel, 3, "Generate Model", (200, -1),
                         wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.click_OK, id=3)
        hbox.Add(next, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        # reminder: functions bound to buttons require arguments
        #           (self, event)
        btnPanel.SetSizer(hbox)

        mainSizer.Add(
            btnPanel, 0.5,  flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20)

        self.panel.SetSizer(mainSizer)

        # TODO
        # text blurb depending on the specific preset

        for ctrl in self.page.get_ctrl_list():

            name = ctrl.get_name()
            value = self.gpa_settings[name]

            if "conditions_list" in name:
                if isinstance(value, str):
                    value = value.replace("[", "").replace("]", "")
                    if "\"" in value:
                        value = value.replace("\"", "")
                    if "'" in value:
                        value = value.replace("'", "")
                    values = value.split(",")
                else:
                    # instead, is a list- most likely when clicking
                    # "Back" on the modelDesign_window
                    values = value

                new_derlist = []

                for val in values:
                    new_derlist.append(val)

                ctrl.set_value(new_derlist)
            elif "condition_type" in name:
                ctrl.set_value(value)

        self.Show()
Пример #3
0
    def __init__(self, parent, gpa_settings, dmatrix_obj, varlist):

        wx.Frame.__init__(self,
                          parent=parent,
                          title="CPAC - Create New FSL FEAT Model",
                          size=(850, 650))

        self.parent = parent

        self.gpa_settings = gpa_settings
        self.dmatrix_obj = dmatrix_obj
        self.contrasts_list = varlist

        if 'contrasts' not in self.gpa_settings.keys():
            self.gpa_settings['file path for blank contrasts'] = {}

        #if 'custom_contrasts' not in self.gpa_settings.keys():
        #    self.gpa_settings['custom_contrasts'] = 'None'

        if 'f_tests' not in self.gpa_settings.keys():
            self.gpa_settings['f_tests'] = []

        if 'model_name' not in self.gpa_settings.keys():
            self.gpa_settings['model_name'] = ''

        if 'output_dir' not in self.gpa_settings.keys():
            self.gpa_settings['output_dir'] = ''

        mainSizer = wx.BoxSizer(wx.VERTICAL)

        self.panel = wx.Panel(self)
        self.window = wx.ScrolledWindow(self.panel)
        self.page = generic_class.GenericClass(self.window,
                                               " FSL Model Design")

        # build 'Available contrasts' string
        contrasts_text = 'Available EVs for contrasts:\n'

        con_length = 65

        for con in varlist:
            contrasts_text = contrasts_text + '    ' + con

            if len(contrasts_text) > con_length:
                contrasts_text = contrasts_text + '\n'
                con_length += 50

        varlist_sizer = wx.BoxSizer(wx.HORIZONTAL)
        var_list_text = wx.StaticText(self.window, label=str(contrasts_text))
        varlist_sizer.Add(var_list_text)

        self.page.add_pheno_load_panel(varlist_sizer)

        #self.page.add(label = 'Contrasts ',
        #              control = control.LISTBOX_COMBO,
        #              name = 'contrasts',
        #              type = dtype.LSTR,
        #              values = self.gpa_settings['contrasts'],
        #              comment = "This field shows where the blank contrast files are\
        #              located within the local system. Use this file to input the desired \
        #              contrast description. This will be a CSV file."
        # 'Specify your contrasts in this window. '
        #          'For example, if two of your available '
        #          'contrasts are EV1 and EV0, you can enter '
        #          'contrast descriptions such as \'EV1 - EV0 '
        #          '= 0\' or \'EV1 = 0\' . Consult the User '
        #          'Guide for more information about describing '
        #          'contrasts. Alternatively, you can provide '
        #          'your own custom-written contrasts matrix in '
        #          'a CSV file in the \'Custom Contrasts '
        #          'Matrix\' field below.',
        #              size = (300,200),
        #              combo_type = 4)

        # this sends the list of available contrast names to the 'Add
        # Contrast' dialog box, so that it may do validation immediately when
        # the user enters contrast strings
        for ctrl in self.page.get_ctrl_list():
            name = ctrl.get_name()
            if name == 'contrasts':
                ctrl.set_available_contrasts(varlist)
                ctrl.set_design_matrix(self.dmatrix_obj)

        self.page.add(
            label='f-Tests ',
            control=control.LISTBOX_COMBO,
            name='f_tests',
            type=dtype.LSTR,
            values=self.gpa_settings['f_tests'],
            comment=
            'Optional: Specify your desired f-tests, if any, in this window.',
            size=(300, 120),
            combo_type=5)

        self.page.add(
            label="Custom Contrasts File ",
            control=control.COMBO_BOX,
            name="contrast_out_path",
            type=dtype.STR,
            comment=
            "Optional: Full path to a CSV file which specifies the contrasts you wish to run in group analysis. This allows you to describe your own custom contrasts matrix.Consult the User Guide for proper formatting.\n\nIf you wish to use the standard contrast builder, leave this field blank. If you provide a path for this option, CPAC will use your custom contrasts matrix instead, and will use the f-tests described in this custom file only (ignoring those you have input in the f-tests field in the GUI above).\n\nIf you wish to include f-tests, create a new column in your CSV file for each f-test named 'f_test_1', 'f_test_2', .. etc. Then, mark the contrasts you would like to include in each f-test with a 1, and mark the rest 0. Note that you must select at least two contrasts per f-test.",
            values=str(self.gpa_settings['custom_contrasts']))

        self.page.add(
            label="Model Name ",
            control=control.TEXT_BOX,
            name="model_name",
            type=dtype.STR,
            comment=
            "Specify a name for the new model. Output and working directories for group analysis, as well as the FLAMEO model files (.mat, .con, .grp, etc.) will be labeled with this name.",
            values=self.gpa_settings['model_name'],
            size=(200, -1))

        self.page.add(
            label="Output Directory ",
            control=control.DIR_COMBO_BOX,
            name="output_dir",
            type=dtype.STR,
            comment=
            "Full path to the directory where CPAC should place the model files (.mat, .con, .grp) and the outputs of group analysis.",
            values=self.gpa_settings['output_dir'])

        self.page.set_sizer()

        mainSizer.Add(self.window, 1, wx.EXPAND)

        btnPanel = wx.Panel(self.panel, -1)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        buffer1 = wx.StaticText(btnPanel, label="\t\t\t\t\t\t")
        hbox.Add(buffer1)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "Cancel", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.cancel, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        back = wx.Button(btnPanel, 1, "< Back", (200, -1), wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, lambda event: self.back(event), id=1)
        hbox.Add(back, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        save = wx.Button(btnPanel, wx.ID_SAVE, "Save Settings", (200, -1),
                         wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON,
                  lambda event: self.save(event, 'save'),
                  id=wx.ID_SAVE)
        hbox.Add(save, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)
        btnPanel.SetSizer(hbox)

        mainSizer.Add(btnPanel, 0.5, flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20)

        self.panel.SetSizer(mainSizer)

        self.Show()
Пример #4
0
    def __init__(self, parent, gpa_settings=None):

        wx.Frame.__init__(
            self, parent=parent, title="CPAC - FSL FEAT Presets",
            size=(900, 550))

        self.parent = parent

        mainSizer = wx.BoxSizer(wx.VERTICAL)
        vertSizer = wx.BoxSizer(wx.VERTICAL)

        self.panel = wx.Panel(self)
        self.window = wx.ScrolledWindow(self.panel, size=(-1, 255))
        self.page = generic_class.GenericClass(self.window,
                                               " FSL FEAT Group-Level "
                                               "Analysis - Model Presets")

        if not gpa_settings:
            # if this window is being opened for the first time
            self.gpa_settings = {}
            self.gpa_settings["flame_preset"] = ""
            self.gpa_settings["pipeline_dir"] = ""
            self.gpa_settings["participant_list"] = "None"
            self.gpa_settings['derivative_list'] = ""
            self.gpa_settings['z_threshold'] = 2.3
            self.gpa_settings['p_threshold'] = 0.05
            self.gpa_settings["model_name"] = ""
            self.gpa_settings["output_dir"] = ""
        else:
            # if we're coming back from the "next" window
            self.gpa_settings = gpa_settings

        self.page.add(label="Choose Preset: ",
                      control=control.CHOICE_BOX,
                      name="flame_preset",
                      type=dtype.LSTR,
                      comment="Select the type of preset you'd like to "
                              "generate. The preset generator will prompt "
                              "you for more information relevant to the "
                              "type of preset you selected on the next "
                              "window (except for the Single Group Average "
                              "(One-Sample T-Test), which needs no "
                              "additional information).",
                      values=["Single Group Average (One-Sample T-Test)",
                              "Single Group Average with Additional Covariate",
                              "Unpaired Two-Group Difference (Two-Sample Unpaired T-Test)",
                              "Paired Two-Group Difference (Two-Sample Paired T-Test)",
                              "Tripled Two-Group Difference ('Tripled' T-Test)"])

        self.page.add(label="Pipeline Output Directory ",
                      control=control.DIR_COMBO_BOX,
                      name="pipeline_dir",
                      type=dtype.STR,
                      comment="Full path to the individual-level pipeline "
                              "output directory you wish to run FSL-FEAT for. "
                              "\n\nThis will be the path to a directory titled "
                              "'pipeline_{name}'.",
                      values=self.gpa_settings['pipeline_dir'])

        self.page.add(label="[Optional] Participant Inclusion List ",
                      control=control.COMBO_BOX,
                      name="participant_list",
                      type=dtype.STR,
                      comment="[Optional] Full path to the group-level "
                              "analysis participant list text file. Use this "
                              "to quickly prune participants from your "
                              "analysis. This should be a text "
                              "file with each participant ID you "
                              "want included in the model, on each line.",
                      values=self.gpa_settings['participant_list'])

        self.page.add(label="Select Derivatives ",
                      control=control.CHECKLIST_BOX,
                      name="derivative_list",
                      type=dtype.LSTR,
                      values=['ALFF',
                              'f/ALFF',
                              'ReHo',
                              'ROI Average SCA',
                              'Dual Regression',
                              'Multiple Regression SCA',
                              'Network Centrality',
                              'VMHC'],
                      comment="Select which derivatives you would like to "
                              "include when running group analysis.\n\nWhen "
                              "including Dual Regression, make sure to "
                              "correct your P-value for the number of maps "
                              "you are comparing.\n\nWhen including "
                              "Multiple Regression SCA, you must have more "
                              "degrees of freedom (subjects) than there were "
                              "time series.",
                      size=(350,180))

        self.page.add(label="Z threshold ",
                      control=control.FLOAT_CTRL,
                      name='z_threshold',
                      type=dtype.NUM,
                      comment="Only voxels with a Z-score higher than this "
                              "value will be considered significant.",
                      values=self.gpa_settings['z_threshold'])

        self.page.add(label="Cluster Significance Threshold (P-value) ",
                      control=control.FLOAT_CTRL,
                      name='p_threshold',
                      type=dtype.NUM,
                      comment="Significance threshold (P-value) to use when "
                              "doing cluster correction for multiple "
                              "comparisons.",
                      values=self.gpa_settings['p_threshold'])

        self.page.add(label="Model Name ",
                      control=control.TEXT_BOX,
                      name="model_name",
                      type=dtype.STR,
                      comment="Specify a name for the new model. Output and "
                              "working directories for group analysis, as "
                              "well as the FLAME model files (.mat, .con, "
                              ".grp, etc.) will be labeled with this name.",
                      values=self.gpa_settings['model_name'],
                      size=(200, -1))

        self.page.add(label="Output Directory ",
                      control=control.DIR_COMBO_BOX,
                      name="output_dir",
                      type=dtype.STR,
                      comment="Full path to the directory where CPAC should "
                              "place the model files (.mat, .con, .grp) and "
                              "the outputs of group analysis.",
                      values=self.gpa_settings['output_dir'])

        if gpa_settings:
            # manually re-set the preset, participant list, and derivatives
            for ctrl in self.page.get_ctrl_list():

                name = ctrl.get_name()
                if name == 'z_threshold':
                    ctrl.set_value(self.gpa_settings['z_threshold'])

                elif name == 'p_threshold':
                    ctrl.set_value(self.gpa_settings['p_threshold'])

                elif ("list" in name) and (name != "participant_list"):

                    value = self.gpa_settings[name]
                    if isinstance(value, str):
                        value = value.replace("[", "").replace("]", "")
                        if "\"" in value:
                            value = value.replace("\"", "")
                        if "'" in value:
                            value = value.replace("'", "")
                        values = value.split(",")
                    else:
                        # instead, is a list- most likely when clicking
                        # "Back" on the modelDesign_window
                        values = value
                    new_derlist = []

                    for val in values:
                        new_derlist.append(val)
                    ctrl.set_value(new_derlist)
                    ctrl.set_selection(new_derlist)

                else:
                    ctrl.set_value(self.gpa_settings[name])

        self.page.set_sizer()
        mainSizer.Add(self.window, 1, wx.EXPAND)

        btnPanel = wx.Panel(self.panel, -1)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        buffer = wx.StaticText(btnPanel, label="\t\t\t\t\t\t")
        hbox.Add(buffer)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "Cancel", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.cancel, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        next = wx.Button(btnPanel, 3, "OK", (200, -1), wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.load_next_stage, id=3)
        hbox.Add(next, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        # reminder: functions bound to buttons require arguments
        #           (self, event)
        btnPanel.SetSizer(hbox)

        mainSizer.Add(
            btnPanel, 0.5,  flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20)

        self.panel.SetSizer(mainSizer)

        self.Show()
Пример #5
0
    def __init__(self, parent):

        wx.Frame.__init__(self,
                          parent=parent,
                          title="CPAC - Create New FSL Model",
                          size=(900, 590))

        mainSizer = wx.BoxSizer(wx.VERTICAL)

        self.panel = wx.Panel(self)

        self.window = wx.ScrolledWindow(self.panel)

        self.page = generic_class.GenericClass(self.window, "FSL Model Setup")

        self.page.add(
            label="Subject List ",
            control=control.COMBO_BOX,
            name="subjectListFile",
            type=dtype.STR,
            comment=
            "Full path to a list of subjects to be included in the model.\n\nThis should be a text file with one subject per line.\n\nTip 1: A list in this format contaning all subjects run through CPAC was generated along with the main CPAC subject list (see subject_list_group_analysis.txt).\n\nTIp 2: An easy way to manually create this file is to copy the subjects column from your Regressor/EV spreadsheet.",
            values="")

        self.page.add(
            label="EV File ",
            control=control.COMBO_BOX,
            name="phenotypicFile",
            type=dtype.STR,
            comment=
            "Full path to a .csv file containing EV information for each subject.\n\nTip: A file in this format (containing a single column listing all subjects run through CPAC) was generated along with the main CPAC subject list (see template_phenotypic.csv).",
            values="")

        self.page.add(label="Subjects Column Name ",
                      control=control.TEXT_BOX,
                      name="subjectColumn",
                      type=dtype.STR,
                      comment="Name of the subjects column in your EV file.",
                      values="",
                      style=wx.EXPAND | wx.ALL,
                      size=(160, -1))

        self.page.add(
            label="EVs to Include ",
            control=control.TEXTBOX_COMBO,
            name="columnsInModel",
            type=dtype.LSTR,
            comment=
            "Specify the names of columns in your EV file that you would like to include in this model.\n\nColumn names should be separated by commas and appear exactly as they do in your EV file.\n\nBy clicking the add button on the right, you can also add measure generated by CPAC to the list of EVs",
            values="",
            style=wx.EXPAND | wx.ALL,
            size=(400, -1))

        self.page.add(
            label="EV Type ",
            control=control.TEXT_BOX,
            name="categoricalVsDirectional",
            type=dtype.LNUM,
            comment=
            "Specify whether each of the EVs in this model should be treated as categorical or continuous.\n\nTo do this, place a 1 (categorical) or 0 (continuous) in the same list position as the corresponding EV.\n\nFor example, if the EVs to include were:\nage, sex, diagnosis, mean_fd\n\nOne might specify:\n0,1,1,0",
            values="",
            style=wx.EXPAND | wx.ALL,
            size=(160, -1))

        self.page.add(
            label="Demean ",
            control=control.TEXT_BOX,
            name="deMean",
            type=dtype.LNUM,
            comment=
            "Specify whether to demean each of the EVs in this model.\n\nTo do this, place a 1 (demean) or 0 (don't demean) in the same list position as the corresponding EV.\n\nFor example, if the EVs to include were:\nage, sex, diagnosis, mean_fd\n\nOne might specify:\n1,0,0,1\n\nNote that only continuous EV's should be demeaned.",
            values="",
            style=wx.EXPAND | wx.ALL,
            size=(160, -1))

        self.page.add(
            label="Contrast File ",
            control=control.COMBO_BOX,
            name="contrastFile",
            type=dtype.STR,
            comment=
            "Full path to a .csv file containing contrasts to be applied to this model.\n\nWhen specifying EVs in this file:\n\n- Continuous EVs should appear the same as their corresponding column name in the EV file.\n\n- Categorical EVs must be split into multiple columns (one for each category), with names of the format EVname__N (e.g. diagnosis__1, diagnosis__2, diagnosis__3)\n\nIf you wish to include F-tests in your model, create a column for each desired F-test, with names in the format f_test_1, f_test_2, etc.",
            values="")

        self.page.add(
            label="Model Group Variances Seperately ",
            control=control.CHOICE_BOX,
            name='modelGroupVariancesSeparately',
            type=dtype.NUM,
            comment=
            "Specify whether FSL should model the variance for each group separately.\n\nIf this option is enabled, you must specify a grouping variable below.",
            values=["Off", "On"])

        self.page.add(
            label="Grouping Variable ",
            control=control.TEXT_BOX,
            name="groupingVariable",
            type=dtype.STR,
            comment=
            "The name of the EV that should be used to group subjects when modeling variances.\n\nIf you do not wish to model group variances separately, set this value to None.",
            values="None",
            size=(160, -1))

        self.page.add(label="Model Name ",
                      control=control.TEXT_BOX,
                      name="modelName",
                      type=dtype.STR,
                      comment="Specify a name for the new model.",
                      values="",
                      size=(200, -1))

        self.page.add(
            label="Output Directory ",
            control=control.DIR_COMBO_BOX,
            name="outputModelFilesDirectory",
            type=dtype.STR,
            comment=
            "Full path to the directory where CPAC should place model files.",
            values="")

        self.page.add(
            label="Model CSV File Name ",
            control=control.TEXT_BOX,
            name="outputModelFile",
            type=dtype.STR,
            comment=
            "In addition to the standard FSL model files, CPAC will output a .csv containing the subjects and EVs specified above.\n\nColumn names in this file will be the same as in the contrasts file, and will have been demeaned as specified.",
            values="",
            style=wx.EXPAND | wx.ALL,
            size=(600, -1),
            validation_req=False)

        self.page.set_sizer()

        mainSizer.Add(self.window, 1, wx.EXPAND)

        btnPanel = wx.Panel(self.panel, -1)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        #         run = wx.Button(btnPanel, ID_RUN, "Create Model", (
        #             280, -1), wx.DefaultSize, 0)
        #         self.Bind(wx.EVT_BUTTON, lambda event: self.save(
        #             event, 'run'), id=ID_RUN)
        #         hbox.Add(run, 0, flag=wx.LEFT | wx.ALIGN_LEFT, border=10)

        buffer = wx.StaticText(btnPanel, label="\t\t\t\t\t\t")
        hbox.Add(buffer)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "Cancel", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.cancel, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        load = wx.Button(btnPanel, wx.ID_ADD, "Load Settings", (200, -1),
                         wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.load, id=wx.ID_ADD)
        hbox.Add(load, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        save = wx.Button(btnPanel, wx.ID_SAVE, "Save Settings", (200, -1),
                         wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON,
                  lambda event: self.save(event, 'save'),
                  id=wx.ID_SAVE)
        hbox.Add(save, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        btnPanel.SetSizer(hbox)

        mainSizer.Add(btnPanel, 0.5, flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20)

        self.panel.SetSizer(mainSizer)

        self.Show()
Пример #6
0
    def __init__(self, parent, gpa_settings=None):

        wx.Frame.__init__(
            self, parent=parent, title="CPAC - Create New FSL Model", size=(900, 650))


        if gpa_settings == None:
            self.gpa_settings = {}
            self.gpa_settings['participant_list'] = ''
            self.gpa_settings['pheno_file'] = ''
            self.gpa_settings['participant_id_label'] = ''
            self.gpa_settings['design_formula'] = ''
            self.gpa_settings['mean_mask'] = ''
            self.gpa_settings['custom_roi_mask'] = 'None'
            self.gpa_settings['coding_scheme'] = ''
            self.gpa_settings['derivative_list'] = ''
            self.gpa_settings['sessions_list'] = []
            self.gpa_settings['series_list'] = []
            self.gpa_settings['group_sep'] = ''
            self.gpa_settings['grouping_var'] = 'None'
            self.gpa_settings['z_threshold'] = ''
            self.gpa_settings['p_threshold'] = ''
        else:
            self.gpa_settings = gpa_settings
        

        self.parent = parent

        mainSizer = wx.BoxSizer(wx.VERTICAL)

        vertSizer = wx.BoxSizer(wx.VERTICAL)

        self.panel = wx.Panel(self)

        self.window = wx.ScrolledWindow(self.panel, size=(-1,300))
        

        self.page = generic_class.GenericClass(self.window, " FSL Model Setup")

        self.page.add(label="Participant List ",
                      control=control.COMBO_BOX,
                      name="participant_list",
                      type=dtype.STR,
                      comment="Full path to a list of participants to be " \
                              "included in the model.\n\nThis should be a " \
                              "CSV file with at least one column marked " \
                              "'Participant', and columns marked 'Session' " \
                              "and/or 'Series' if repeated measures " \
                              "analysis is to be run.\n\n",
                      values=self.gpa_settings['participant_list'])

        self.page.add(label="Phenotype/EV File ",
                      control=control.COMBO_BOX,
                      name="pheno_file",
                      type=dtype.STR,
                      comment="Full path to a .csv file containing EV information for each subject.\n\nTip: A file in this format (containing a single column listing all subjects run through CPAC) was generated along with the main CPAC subject list (see template_phenotypic.csv).",
                      values=self.gpa_settings['pheno_file'])

        self.page.add(label="Participant Column Name ",
                      control=control.TEXT_BOX,
                      name="participant_id_label",
                      type=dtype.STR,
                      comment="Name of the participants column in your EV file.",
                      values=self.gpa_settings['participant_id_label'],
                      style=wx.EXPAND | wx.ALL,
                      size=(160, -1))

        
        load_panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
        load_pheno_btn = wx.Button(self.window, 2, 'Load Phenotype File', (220,10), wx.DefaultSize, 0)
        load_panel_sizer.Add(load_pheno_btn)

        self.Bind(wx.EVT_BUTTON, self.populateEVs, id=2)


        self.page.add_pheno_load_panel(load_panel_sizer)

        self.page.add(label = "Model Setup ",
                      control = control.GPA_CHECKBOX_GRID,
                      name = "model_setup",
                      type = 10,
                      values = '',
                      comment="A list of EVs from your phenotype file will populate in this window. From here, you can select whether the EVs should be treated as categorical or if they should be demeaned (continuous/non-categorical EVs only). 'MeanFD', 'MeanFD_Jenkinson', 'Measure Mean', and 'Custom_ROI_Mean' will also appear in this window automatically as options to be used as regressors that can be included in your model design. Note that the MeanFD and mean of measure values are automatically calculated and supplied by C-PAC via individual-level analysis.",
                      size = (450, -1))

        self.page.add(label="Design Matrix Formula ",
                      control=control.TEXT_BOX,
                      name="design_formula",
                      type=dtype.STR,
                      comment="Specify the formula to describe your model design. Essentially, including EVs in this formula inserts them into the model. The most basic format to include each EV you select would be 'EV + EV + EV + ..', etc. You can also select to include MeanFD, MeanFD_Jenkinson, Measure_Mean, and Custom_ROI_Mean here. See the C-PAC User Guide for more detailed information regarding formatting your design formula.",
                      values= self.gpa_settings['design_formula'],
                      size=(450, -1))

        self.page.add(label="Custom ROI Mean Mask ",
                      control=control.COMBO_BOX,
                      name="custom_roi_mask",
                      type=dtype.STR,
                      comment="Optional: Full path to a NIFTI file containing one or more ROI masks. The means of the masked regions will then be computed for each subject's output and will be included in the model as regressors (one for each ROI in the mask file) if you include 'Custom_ROI_Mean' in the Design Matrix Formula.",
                      values=self.gpa_settings['custom_roi_mask'])

        self.page.add(label = "Select Derivatives ",
                    control = control.CHECKLIST_BOX,
                    name = "derivative_list",
                    type = dtype.LSTR,
                    values = ['ALFF',
                              'ALFF (smoothed)',
                              'f/ALFF',
                              'f/ALFF (smoothed)',
                              'ReHo',
                              'ReHo (smoothed)',
                              'ROI Average SCA',
                              'ROI Average SCA (smoothed)',
                              'Dual Regression',
                              'Dual Regression (smoothed)',
                              'Multiple Regression SCA',
                              'Multiple Regression SCA (smoothed)',
                              'Network Centrality',
                              'Network Centrality (smoothed)',
                              'VMHC'],
                    comment = "Select which derivatives you would like to include when running group analysis.\n\nWhen including Dual Regression, make sure to correct your P-value for the number of maps you are comparing.\n\nWhen including Multiple Regression SCA, you must have more degrees of freedom (subjects) than there were time series.",
                    size = (350,160))

        self.page.add(label="Coding Scheme ", 
                     control=control.CHOICE_BOX, 
                     name="coding_scheme", 
                     type=dtype.LSTR, 
                     comment="Choose the coding scheme to use when generating your model. 'Treatment' encoding is generally considered the typical scheme. Consult the User Guide for more information.", 
                     values=["Treatment", "Sum"])

        self.page.add(label="Mask for Means Calculation ", 
                 control=control.CHOICE_BOX, 
                 name='mean_mask', 
                 type=dtype.LSTR, 
                 comment = "Choose whether to use a group mask or individual-specific mask when calculating the output means to be used as a regressor.\n\nThis only takes effect if you include the 'Measure_Mean' or 'Custom_ROI_Mean' regressors in your Design Matrix Formula.", 
                 values=["Group Mask","Individual Mask"])

        self.page.add(label="Z threshold ", 
                     control=control.FLOAT_CTRL, 
                     name='z_threshold', 
                     type=dtype.NUM, 
                     comment="Only voxels with a Z-score higher than this value will be considered significant.", 
                     values=2.3)

        self.page.add(label="Cluster Significance Threshold ", 
                     control=control.FLOAT_CTRL, 
                     name='p_threshold', 
                     type=dtype.NUM, 
                     comment="Significance threshold (P-value) to use when doing cluster correction for multiple comparisons.", 
                     values=0.05)

        self.page.add(label="Model Group Variances Separately ",
                      control=control.CHOICE_BOX,
                      name='group_sep',
                      type=dtype.NUM,
                      comment="Specify whether FSL should model the variance for each group separately.\n\nIf this option is enabled, you must specify a grouping variable below.",
                      values=['Off', 'On'])

        self.page.add(label="Grouping Variable ",
                      control=control.TEXT_BOX,
                      name="grouping_var",
                      type=dtype.STR,
                      comment="The name of the EV that should be used to group subjects when modeling variances.\n\nIf you do not wish to model group variances separately, set this value to None.",
                      values=self.gpa_settings['grouping_var'],
                      size=(160, -1))

        self.page.add(label = 'Sessions (Repeated Measures Only) ',
                      control = control.LISTBOX_COMBO,
                      name = 'sessions_list',
                      type = dtype.LSTR,
                      values = self.gpa_settings['sessions_list'],
                      comment = 'Enter the session names in your dataset ' \
                                'that you wish to include within the same ' \
                                'model (this is for repeated measures/' \
                                'within-subject designs).\n\nTip: These ' \
                                'will be the names listed as "unique_id" in '\
                                'the original individual-level participant ' \
                                'list, or the labels in the original data ' \
                                'directories you marked as {session} while ' \
                                'creating the CPAC participant list.',
                      size = (200,100),
                      combo_type = 7)

        self.page.add(label = 'Series/Scans (Repeated Measures Only) ',
                      control = control.LISTBOX_COMBO,
                      name = 'series_list',
                      type = dtype.LSTR,
                      values = self.gpa_settings['series_list'],
                      comment = 'Enter the series names in your dataset ' \
                                'that you wish to include within the same ' \
                                'model (this is for repeated measures/' \
                                'within-subject designs).\n\nTip: These ' \
                                'will be the labels listed under "rest:"" '\
                                'in the original individual-level ' \
                                'participant list, or the labels in the ' \
                                'original data directories you marked as ' \
                                '{series} while creating the CPAC ' \
                                'participant list.',
                      size = (200,100),
                      combo_type = 8)


        self.page.set_sizer()
        
        
        if 'group_sep' in self.gpa_settings.keys():

            for ctrl in self.page.get_ctrl_list():

                name = ctrl.get_name()

                if name == 'group_sep':

                    if self.gpa_settings['group_sep'] == True:
                        ctrl.set_value('On')
                    elif self.gpa_settings['group_sep'] == False:
                        ctrl.set_value('Off')


        mainSizer.Add(self.window, 1, wx.EXPAND)

        btnPanel = wx.Panel(self.panel, -1)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        buffer = wx.StaticText(btnPanel, label="\t\t\t\t\t\t")
        hbox.Add(buffer)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "Cancel", (
            220, 10), wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.cancel, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)
        
        load = wx.Button(btnPanel, wx.ID_ADD, "Load Settings", (
            200, -1), wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.load, id=wx.ID_ADD)
        hbox.Add(load, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)
        
        next = wx.Button(btnPanel, 3, "Next >", (200, -1), wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.load_next_stage, id=3)
        hbox.Add(next, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        # reminder: functions bound to buttons require arguments
        #           (self, event)
        btnPanel.SetSizer(hbox)

        mainSizer.Add(
            btnPanel, 0.5,  flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20)

        self.panel.SetSizer(mainSizer)

        self.Show()

        # this fires only if we're coming BACK to this page from the second
        # page, and these parameters are already pre-loaded. this is to
        # automatically repopulate the 'Model Setup' checkbox grid and other
        # settings under it
        if self.gpa_settings['pheno_file'] != '':

            phenoFile = open(os.path.abspath(self.gpa_settings['pheno_file']))

            phenoHeaderString = phenoFile.readline().rstrip('\r\n')
            phenoHeaderItems = phenoHeaderString.split(',')
            phenoHeaderItems.remove(self.gpa_settings['participant_id_label'])

            # update the 'Model Setup' box and populate it with the EVs and
            # their associated checkboxes for categorical and demean
            for ctrl in self.page.get_ctrl_list():

                name = ctrl.get_name()

                if name == 'model_setup':
                    ctrl.set_value(phenoHeaderItems)
                    ctrl.set_selection(self.gpa_settings['ev_selections'])

                if name == 'coding_scheme':
                    ctrl.set_value(self.gpa_settings['coding_scheme'])

                if name == 'mean_mask':
                    ctrl.set_value(self.gpa_settings['mean_mask'])

                if name == 'z_threshold':
                    ctrl.set_value(self.gpa_settings['z_threshold'][0])

                if name == 'p_threshold':
                    ctrl.set_value(self.gpa_settings['p_threshold'])
                    
                if name == 'group_sep':
                    ctrl.set_value(self.gpa_settings['group_sep'])

                if name == 'grouping_var':
                    ctrl.set_value(self.gpa_settings['grouping_var'])

                if ("list" in name) and (name != "participant_list"):

                    value = self.gpa_settings[name]

                    if isinstance(value, str):
                        value = value.replace("[","").replace("]","")
                        if "\"" in value:
                            value = value.replace("\"","")
                        if "'" in value:
                            value = value.replace("'","")
                        values = value.split(",")
                    else:
                        # instead, is a list- most likely when clicking
                        # "Back" on the modelDesign_window
                        values = value

                    new_derlist = []

                    for val in values:
                        new_derlist.append(val)                      

                    ctrl.set_value(new_derlist)
Пример #7
0
    def __init__(self, parent, gpa_settings=None):

        wx.Frame.__init__(self,
                          parent=parent,
                          title="CPAC - Create New FSL Model",
                          size=(850, 600))

        if gpa_settings == None:
            self.gpa_settings = {}
            self.gpa_settings['subject_list'] = ''
            self.gpa_settings['pheno_file'] = ''
            self.gpa_settings['subject_id_label'] = ''
            self.gpa_settings['design_formula'] = ''
        else:
            self.gpa_settings = gpa_settings

        self.parent = parent

        mainSizer = wx.BoxSizer(wx.VERTICAL)

        vertSizer = wx.BoxSizer(wx.VERTICAL)

        self.panel = wx.Panel(self)

        self.window = wx.ScrolledWindow(self.panel, size=(-1, 300))

        self.page = generic_class.GenericClass(self.window, " FSL Model Setup")

        self.page.add(
            label="Subject List ",
            control=control.COMBO_BOX,
            name="subject_list",
            type=dtype.STR,
            comment=
            "Full path to a list of subjects to be included in the model.\n\nThis should be a text file with one subject per line.\n\nTip 1: A list in this format contaning all subjects run through CPAC was generated along with the main CPAC subject list (see subject_list_group_analysis.txt).\n\nTIp 2: An easy way to manually create this file is to copy the subjects column from your Regressor/EV spreadsheet.",
            values=self.gpa_settings['subject_list'])

        self.page.add(
            label="Phenotype/EV File ",
            control=control.COMBO_BOX,
            name="pheno_file",
            type=dtype.STR,
            comment=
            "Full path to a .csv file containing EV information for each subject.\n\nTip: A file in this format (containing a single column listing all subjects run through CPAC) was generated along with the main CPAC subject list (see template_phenotypic.csv).",
            values=self.gpa_settings['pheno_file'])

        self.page.add(label="Subjects Column Name ",
                      control=control.TEXT_BOX,
                      name="subject_id_label",
                      type=dtype.STR,
                      comment="Name of the subjects column in your EV file.",
                      values=self.gpa_settings['subject_id_label'],
                      style=wx.EXPAND | wx.ALL,
                      size=(160, -1))

        load_panel_sizer = wx.BoxSizer(wx.HORIZONTAL)
        load_pheno_btn = wx.Button(self.window, 2, 'Load Phenotype File',
                                   (220, 10), wx.DefaultSize, 0)
        load_panel_sizer.Add(load_pheno_btn)

        self.Bind(wx.EVT_BUTTON, self.populateEVs, id=2)

        self.page.add_pheno_load_panel(load_panel_sizer)

        # experimental checkbox row stuff
        self.page.add(
            label="Model Setup ",
            control=control.CHECKBOX_GRID,
            name="model_setup",
            type=9,  #dtype.LBOOL,
            values='',
            comment=
            "A list of EVs from your phenotype file will populate in this window. From here, you can select whether the EVs should be treated as categorical or if they should be demeaned (continuous/non-categorical EVs only). 'MeanFD' and 'Measure Mean' will also appear in this window automatically as options to be used as regressors that can be included in your model design. Note that the MeanFD and mean of measure values are automatically calculated and supplied by C-PAC via individual-level analysis.",
            size=(450, -1))

        self.page.add(
            label="Design Matrix Formula ",
            control=control.TEXT_BOX,
            name="design_formula",
            type=dtype.STR,
            comment=
            "Specify the formula to describe your model design. Essentially, including EVs in this formula inserts them into the model. The most basic format to include each EV you select would be 'EV + EV + EV + ..', etc. You can also select to include MeanFD and Measure_Mean here. See the C-PAC User Guide for more detailed information regarding formatting your design formula.",
            values=self.gpa_settings['design_formula'],
            size=(450, -1))

        self.page.set_sizer()

        mainSizer.Add(self.window, 1, wx.EXPAND)

        btnPanel = wx.Panel(self.panel, -1)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        buffer = wx.StaticText(btnPanel, label="\t\t\t\t\t\t")
        hbox.Add(buffer)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "Cancel", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.cancel, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        load = wx.Button(btnPanel, wx.ID_ADD, "Load Settings", (200, -1),
                         wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.load, id=wx.ID_ADD)
        hbox.Add(load, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        next = wx.Button(btnPanel, 3, "Next >", (200, -1), wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.load_next_stage, id=3)
        hbox.Add(next, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        # reminder: functions bound to buttons require arguments
        #           (self, event)

        btnPanel.SetSizer(hbox)

        text_sizer = wx.BoxSizer(wx.HORIZONTAL)
        measure_text = wx.StaticText(
            self.window,
            label=
            'Note: Regressor options \'MeanFD\' and \'Measure_Mean\' are automatically demeaned prior to being inserted into the model.'
        )
        text_sizer.Add(measure_text)

        mainSizer.Add(text_sizer)

        mainSizer.Add(btnPanel, 0.5, flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20)

        self.panel.SetSizer(mainSizer)

        self.Show()

        # this fires only if we're coming BACK to this page from the second
        # page, and these parameters are already pre-loaded. this is to
        # automatically repopulate the 'Model Setup' checkbox grid
        if self.gpa_settings['pheno_file'] != '':

            phenoFile = open(os.path.abspath(self.gpa_settings['pheno_file']))

            phenoHeaderString = phenoFile.readline().rstrip('\r\n')
            phenoHeaderItems = phenoHeaderString.split(',')
            phenoHeaderItems.remove(self.gpa_settings['subject_id_label'])

            # update the 'Model Setup' box and populate it with the EVs and
            # their associated checkboxes for categorical and demean
            for ctrl in self.page.get_ctrl_list():

                if ctrl.get_name() == 'model_setup':
                    ctrl.set_value(phenoHeaderItems)
                    ctrl.set_selection(self.gpa_settings['ev_selections'])
Пример #8
0
    def __init__(self, parent, gpa_settings, varlist):

        wx.Frame.__init__(self,
                          parent=parent,
                          title="CPAC - Create New FSL Model",
                          size=(850, 650))

        self.parent = parent

        self.gpa_settings = gpa_settings

        self.contrasts_list = varlist

        if 'contrasts' not in self.gpa_settings.keys():
            self.gpa_settings['contrasts'] = {}

        if 'custom_contrasts' not in self.gpa_settings.keys():
            self.gpa_settings['custom_contrasts'] = 'None'

        if 'f_tests' not in self.gpa_settings.keys():
            self.gpa_settings['f_tests'] = []

        if 'model_name' not in self.gpa_settings.keys():
            self.gpa_settings['model_name'] = ''

        if 'output_dir' not in self.gpa_settings.keys():
            self.gpa_settings['output_dir'] = ''

        mainSizer = wx.BoxSizer(wx.VERTICAL)

        self.panel = wx.Panel(self)

        self.window = wx.ScrolledWindow(self.panel)

        self.page = generic_class.GenericClass(self.window,
                                               " FSL Model Design")

        phenoFile = open(os.path.abspath(self.gpa_settings['pheno_file']))
        phenoHeaderString = phenoFile.readline().rstrip('\r\n')
        self.phenoHeaderItems = phenoHeaderString.split(',')

        if self.gpa_settings['subject_id_label'] in self.phenoHeaderItems:
            self.phenoHeaderItems.remove(self.gpa_settings['subject_id_label'])
        else:
            errSubID = wx.MessageDialog(
                self, 'Please enter the name of the subject ID column' \
                ' as it is labeled in the phenotype file.',
                'Blank/Incorrect Subject Header Input',
                wx.OK | wx.ICON_ERROR)
            errSubID.ShowModal()
            errSubID.Destroy()
            raise Exception

        # build 'Available contrasts' string
        contrasts_text = 'Available EVs for contrasts:\n'

        con_length = 65

        for con in varlist:
            contrasts_text = contrasts_text + '    ' + con

            if len(contrasts_text) > con_length:
                contrasts_text = contrasts_text + '\n'
                con_length += 50

        varlist_sizer = wx.BoxSizer(wx.HORIZONTAL)
        var_list_text = wx.StaticText(self.window, label=str(contrasts_text))
        varlist_sizer.Add(var_list_text)

        self.page.add_pheno_load_panel(varlist_sizer)

        self.page.add(
            label='Contrasts ',
            control=control.LISTBOX_COMBO,
            name='contrasts',
            type=dtype.LSTR,
            values=self.gpa_settings['contrasts'],
            comment=
            'Specify your contrasts in this window. For example, if two of your available contrasts are EV1 and EV0, you can enter contrast descriptions such as EV1 > EV0 or EV1+ . Consult the User Guide for more information about describing contrasts. Alternatively, you can provide your own custom-written contrasts matrix in a CSV file in the \'Custom Contrasts Matrix\' field below.',
            size=(300, 200),
            combo_type=4)

        # this sends the list of available contrast names to the 'Add
        # Contrast' dialog box, so that it may do validation immediately when
        # the user enters contrast strings
        for ctrl in self.page.get_ctrl_list():
            name = ctrl.get_name()
            if name == 'contrasts':
                ctrl.set_available_contrasts(varlist)

        self.page.add(
            label='f-Tests ',
            control=control.LISTBOX_COMBO,
            name='f_tests',
            type=dtype.LSTR,
            values=self.gpa_settings['f_tests'],
            comment=
            'Optional: Specify your desired f-tests, if any, in this window.',
            size=(300, 120),
            combo_type=5)

        self.page.add(
            label="Custom Contrasts Matrix ",
            control=control.COMBO_BOX,
            name="custom_contrasts",
            type=dtype.STR,
            comment=
            "Optional: Full path to a CSV file which specifies the contrasts you wish to run in group analysis. This allows you to describe your own custom contrasts matrix if you do not wish to use the contrasts builder above. Consult the User Guide for proper formatting.\n\nIf you wish to use the standard contrast builder, leave this field blank. If you provide a path for this option, CPAC will use your custom contrasts matrix instead, and will use the f-tests described in this custom file only (ignoring those you have input in the f-tests field in the GUI above).\n\nIf you wish to include f-tests, create a new column in your CSV file for each f-test named 'f_test_1', 'f_test_2', .. etc. Then, mark the contrasts you would like to include in each f-test with a 1, and mark the rest 0. Note that you must select at least two contrasts per f-test.",
            values=str(self.gpa_settings['custom_contrasts']))

        self.page.add(
            label="Model Name ",
            control=control.TEXT_BOX,
            name="model_name",
            type=dtype.STR,
            comment=
            "Specify a name for the new model. Output and working directories for group analysis, as well as the FLAMEO model files (.mat, .con, .grp, etc.) will be labeled with this name.",
            values=self.gpa_settings['model_name'],
            size=(200, -1))

        self.page.add(
            label="Output Directory ",
            control=control.DIR_COMBO_BOX,
            name="output_dir",
            type=dtype.STR,
            comment=
            "Full path to the directory where CPAC should place the model files (.mat, .con, .grp) and the outputs of group analysis.",
            values=self.gpa_settings['output_dir'])

        self.page.set_sizer()

        mainSizer.Add(self.window, 1, wx.EXPAND)

        btnPanel = wx.Panel(self.panel, -1)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        #         run = wx.Button(btnPanel, ID_RUN, "Create Model", (
        #             280, -1), wx.DefaultSize, 0)
        #         self.Bind(wx.EVT_BUTTON, lambda event: self.save(
        #             event, 'run'), id=ID_RUN)
        #         hbox.Add(run, 0, flag=wx.LEFT | wx.ALIGN_LEFT, border=10)

        buffer1 = wx.StaticText(btnPanel, label="\t\t\t\t\t\t")
        hbox.Add(buffer1)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "Cancel", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.cancel, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        back = wx.Button(btnPanel, 1, "< Back", (200, -1), wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, lambda event: self.back(event), id=1)
        hbox.Add(back, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        save = wx.Button(btnPanel, wx.ID_SAVE, "Save Settings", (200, -1),
                         wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON,
                  lambda event: self.save(event, 'save'),
                  id=wx.ID_SAVE)
        hbox.Add(save, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        btnPanel.SetSizer(hbox)

        mainSizer.Add(btnPanel, 0.5, flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20)

        self.panel.SetSizer(mainSizer)

        self.Show()
Пример #9
0
    def __init__(self, parent, gpa_settings, varlist):

        wx.Frame.__init__(self,
                          parent=parent,
                          title="CPAC - Create New FSL Model",
                          size=(750, 550))

        self.parent = parent

        self.gpa_settings = gpa_settings

        self.contrasts_list = varlist

        if 'contrasts' not in self.gpa_settings.keys():
            self.gpa_settings['contrasts'] = {}

        if 'grouping_var' not in self.gpa_settings.keys():
            self.gpa_settings['grouping_var'] = 'None'

        if 'model_name' not in self.gpa_settings.keys():
            self.gpa_settings['model_name'] = ''

        if 'output_dir' not in self.gpa_settings.keys():
            self.gpa_settings['output_dir'] = ''

        mainSizer = wx.BoxSizer(wx.VERTICAL)

        self.panel = wx.Panel(self)

        self.window = wx.ScrolledWindow(self.panel)

        self.page = generic_class.GenericClass(self.window,
                                               " FSL Model Design")

        phenoFile = open(os.path.abspath(self.gpa_settings['pheno_file']))
        phenoHeaderString = phenoFile.readline().rstrip('\r\n')
        self.phenoHeaderItems = phenoHeaderString.split(',')

        if self.gpa_settings['subject_id_label'] in self.phenoHeaderItems:
            self.phenoHeaderItems.remove(self.gpa_settings['subject_id_label'])
        else:
            errSubID = wx.MessageDialog(
                self, 'Please enter the name of the subject ID column' \
                ' as it is labeled in the phenotype file.',
                'Blank/Incorrect Subject Header Input',
                wx.OK | wx.ICON_ERROR)
            errSubID.ShowModal()
            errSubID.Destroy()
            raise Exception

        # build 'Available contrasts' string
        contrasts_text = 'Available contrasts:\n'

        con_length = 65

        for con in varlist:
            contrasts_text = contrasts_text + '    ' + con

            if len(contrasts_text) > con_length:
                contrasts_text = contrasts_text + '\n'
                con_length += 50

        varlist_sizer = wx.BoxSizer(wx.HORIZONTAL)
        var_list_text = wx.StaticText(self.window, label=str(contrasts_text))
        varlist_sizer.Add(var_list_text)

        self.page.add_pheno_load_panel(varlist_sizer)

        self.page.add(
            label='Contrasts ',
            control=control.LISTBOX_COMBO,
            name='contrastStrings',
            type=dtype.LSTR,
            values=self.gpa_settings['contrasts'],
            comment=
            'Specify your contrasts in this window. For example, if two of your available contrasts are EV1 and EV0, you can enter contrast descriptions such as EV1 > EV0 or EV1+ .',
            size=(300, 200),
            combo_type=4)

        # this sends the list of available contrast names to the 'Add
        # Contrast' dialog box, so that it may do validation immediately when
        # the user enters contrast strings
        for ctrl in self.page.get_ctrl_list():
            name = ctrl.get_name()
            if name == 'contrastStrings':
                ctrl.set_available_contrasts(varlist)

        self.page.add(
            label="Model Group Variances Seperately ",
            control=control.CHOICE_BOX,
            name='modelGroupVariancesSeparately',
            type=dtype.NUM,
            comment=
            "Specify whether FSL should model the variance for each group separately.\n\nIf this option is enabled, you must specify a grouping variable below.",
            values=['Off', 'On'])

        self.page.add(
            label="Grouping Variable ",
            control=control.TEXT_BOX,
            name="groupingVariable",
            type=dtype.STR,
            comment=
            "The name of the EV that should be used to group subjects when modeling variances.\n\nIf you do not wish to model group variances separately, set this value to None.",
            values=self.gpa_settings['grouping_var'],
            size=(160, -1))

        self.page.add(label="Model Name ",
                      control=control.TEXT_BOX,
                      name="modelName",
                      type=dtype.STR,
                      comment="Specify a name for the new model.",
                      values=self.gpa_settings['model_name'],
                      size=(200, -1))

        self.page.add(
            label="Output Directory ",
            control=control.DIR_COMBO_BOX,
            name="outputModelFilesDirectory",
            type=dtype.STR,
            comment=
            "Full path to the directory where CPAC should place the model files (.mat, .con, .grp) and the outputs of group analysis.",
            values=self.gpa_settings['output_dir'])

        if 'group_sep' in self.gpa_settings.keys():

            for ctrl in self.page.get_ctrl_list():

                name = ctrl.get_name()

                if name == 'modelGroupVariancesSeparately':

                    if self.gpa_settings['group_sep'] == True:
                        ctrl.set_value('On')
                    elif self.gpa_settings['group_sep'] == False:
                        ctrl.set_value('Off')

        self.page.set_sizer()

        mainSizer.Add(self.window, 1, wx.EXPAND)

        btnPanel = wx.Panel(self.panel, -1)
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        #         run = wx.Button(btnPanel, ID_RUN, "Create Model", (
        #             280, -1), wx.DefaultSize, 0)
        #         self.Bind(wx.EVT_BUTTON, lambda event: self.save(
        #             event, 'run'), id=ID_RUN)
        #         hbox.Add(run, 0, flag=wx.LEFT | wx.ALIGN_LEFT, border=10)

        buffer1 = wx.StaticText(btnPanel, label="\t\t\t\t\t\t")
        hbox.Add(buffer1)

        cancel = wx.Button(btnPanel, wx.ID_CANCEL, "Cancel", (220, 10),
                           wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, self.cancel, id=wx.ID_CANCEL)
        hbox.Add(cancel, 0, flag=wx.LEFT | wx.BOTTOM, border=5)

        back = wx.Button(btnPanel, 1, "< Back", (200, -1), wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON, lambda event: self.back(event), id=1)
        hbox.Add(back, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        save = wx.Button(btnPanel, wx.ID_SAVE, "Save Settings", (200, -1),
                         wx.DefaultSize, 0)
        self.Bind(wx.EVT_BUTTON,
                  lambda event: self.save(event, 'save'),
                  id=wx.ID_SAVE)
        hbox.Add(save, 0.6, flag=wx.LEFT | wx.BOTTOM, border=5)

        btnPanel.SetSizer(hbox)

        mainSizer.Add(btnPanel, 0.5, flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20)

        self.panel.SetSizer(mainSizer)

        self.Show()