示例#1
0
    def save_log(self):
        """Save the log"""
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        filename, _ = QFileDialog.getSaveFileName(
            self,
            "QFileDialog.getSaveFileName()",
            "",
            self.filetype,
            options=options)

        # Return without doing anything if a valid file wasn't selected
        if not filename:
            return

        # Define a no-parameter function to save the data using a thread
        log = self.messages

        def save_func():
            with open(filename, "w") as o:
                o.writelines(log)

        RunProgress.run_with_progress(progress_str="Saving Log...",
                                      function=save_func,
                                      slot=None,
                                      parent=self)
示例#2
0
 def submit(self):
     print(f"categorize with {self.cat_min}, {self.cat_max}, {self.cont_min}")
     if self.cat_min > self.cat_max:
         warnings.show_warning(
             "Parameter Error",
             f"'Categorical Minimum' must be <= 'Categorical Maximum'",
         )
     elif self.cat_min > self.cont_min:
         warnings.show_warning(
             "Parameter Error",
             f"'Categorical Minimum' must be < 'Continuous Minimum'",
         )
     elif self.cat_max >= self.cont_min:
         warnings.show_warning(
             "Parameter Error",
             f"'Categorical Maximum' must be < 'Continuous Minimum'",
         )
     else:
         # Run with a progress dialog
         RunProgress.run_with_progress(
             progress_str="Categorizing variables...",
             function=self.get_func(),
             slot=self.appctx.update_data,
             parent=self,
         )
         self.log_command()
         self.accept()
示例#3
0
    def submit(self):
        if self.data_name is None:
            self.data_name = self.le_data_name.placeholderText()

        if self.data_name is not None and self.data_name in [
            d.name for d in self.appctx.datasets
        ]:
            warnings.show_warning(
                "Dataset already exists",
                f"A dataset named '{self.data_name}' already exists.\n"
                f"Use a different name.",
            )
        elif (
            self.top_idx is None
            or self.bottom_idx is None
            or self.top_idx == self.bottom_idx
        ):
            warnings.show_warning(
                "Select Two Datasets", "Two different datasets must be selected."
            )
        else:
            RunProgress.run_with_progress(
                progress_str="Merging Data...",
                function=self.get_func(),
                slot=self.appctx.add_dataset,
                parent=self,
            )
            self.log_command()
            self.accept()
 def submit(self):
     type_errors = (
         self.update_types()
     )  # Convert the types of 'from' and 'to', returning None if successful
     if self.data_name is not None and self.data_name in [
             d.name for d in self.appctx.datasets
     ]:
         warnings.show_warning(
             "Dataset already exists",
             f"A dataset named '{self.data_name}' already exists.\n"
             f"Use a different name or clear the dataset name field.",
         )
     elif type_errors is not None:
         warnings.show_critical("Error", type_errors)
     else:
         # Run with a progress dialog
         if self.data_name is None:
             slot = self.appctx.update_data
         else:
             slot = self.appctx.add_dataset
         RunProgress.run_with_progress(
             progress_str="Recoding variables...",
             function=self.get_func(),
             slot=slot,
             parent=self,
         )
         self.log_command()
         self.accept()
 def submit(self):
     if self.data_name is not None and self.data_name in [
             d.name for d in self.appctx.datasets
     ]:
         show_warning(
             "Dataset already exists",
             f"A dataset named '{self.data_name}' already exists.\n"
             f"Use a different name or clear the dataset name field.",
         )
     elif "converged" not in list(self.dataset.df):
         show_warning("Incorrect Data Input",
                      "A 'converged' column must be present")
     elif "pvalue" not in list(self.dataset.df):
         show_warning("Incorrect Data Input",
                      "A 'pvalue' column must be present")
     else:
         print(f"Adding corrected P-values...")
         # Run with a progress dialog
         if self.data_name is None:
             slot = self.appctx.update_data
         else:
             slot = self.appctx.add_dataset
         RunProgress.run_with_progress(
             progress_str="Adding corrected P-values...",
             function=self.get_func(),
             slot=slot,
             parent=self,
         )
         self.log_command()
         self.accept()
 def submit(self):
     if len(self.filename) == 0:
         self.reject()
         return
     datafile = Path(self.filename)
     if not datafile.exists():
         warnings.show_warning(
             title="File Not Found",
             text=f"The file could not be found:\n'{str(datafile)}''",
         )
     elif not datafile.is_file():
         warnings.show_warning(
             title="Not a File",
             text=
             f"A folder was given instead of a file:\n'{str(datafile)}''",
         )
     elif self.data_name in [d.name for d in self.appctx.datasets]:
         warnings.show_warning(
             title="Dataset already exists",
             text=
             f"A dataset named '{self.data_name}' already exists.  Use a different name.",
         )
     else:
         RunProgress.run_with_progress(
             progress_str=f"Loading {self.kind} file...",
             function=self.get_func(),
             slot=self.appctx.add_dataset,
             parent=self,
         )
         self.log_command()
         self.accept()
示例#7
0
    def save_dataset(self):
        """
        Save the currently selected dataset
        :return:
        """
        options = QFileDialog.Options()
        options |= QFileDialog.DontUseNativeDialog
        filename, _ = QFileDialog.getSaveFileName(
            self,
            "QFileDialog.getSaveFileName()",
            "",
            "All Files (*);;Text Files (*.txt)",
            options=options,
        )

        # Return without doing anything if a valid file wasn't selected
        if not filename:
            return

        # Define a no-parameter function to save the data using a thread
        dataset = self.appctx.datasets[self.appctx.current_dataset_idx]

        def save_func():
            # Save Data
            dataset.df.to_csv(filename, sep="\t")
            # Save Dtypes
            dtypes = {
                variable_name: {
                    "type": str(dtype)
                } if str(dtype) != "category" else {
                    "type": str(dtype),
                    "categories": list(dtype.categories.values.tolist()),
                    "ordered": dtype.ordered,
                }
                for variable_name, dtype in dataset.df.dtypes.iteritems()
            }
            dtypes_filename = filename + ".dtypes"
            dtypes_file = Path(dtypes_filename)
            with dtypes_file.open("w") as f:
                json.dump(dtypes, f)

        RunProgress.run_with_progress(progress_str="Saving Data...",
                                      function=save_func,
                                      slot=None,
                                      parent=self)

        # Log Info
        save_str = (
            f"\nSaved {len(dataset.df):,} observations of {len(list(dataset.df)):,} variables"
            f" in '{dataset.get_selector_name()}' to '{filename}'\n")
        self.appctx.log_info("\n" + "=" * 80 + save_str + "=" * 80)

        # Log Python
        self.appctx.log_python(
            f"# Save data and it's associated datatypes\n"
            f"{dataset.get_python_name()}.to_csv({filename}, sep='\t')\n")
示例#8
0
 def submit(self):
     # Run with a progress dialog
     RunProgress.run_with_progress(
         progress_str="Converting variable types...",
         function=self.get_func(),
         slot=self.appctx.update_data,
         parent=self,
     )
     self.log_command()
     self.accept()
示例#9
0
 def submit(self):
     # Run with a progress dialog
     RunProgress.run_with_progress(
         progress_str="Dropping extra categories...",
         function=self.get_func(),
         slot=self.appctx.update_data,
         parent=self,
     )
     self.log_command()
     self.accept()
    def save(self):
        fileName = QFileDialog.getSaveFileName(
            self, self.tr("Save file"), "", self.tr("PDF files (*.pdf)")
        )[0]
        if fileName:
            self.saved_filename = fileName

        # Generate and save the PDF
        RunProgress.run_with_progress(
            progress_str="Saving PDF...",
            function=self.get_func(),
            slot=lambda: print("Saving PDF"),
            parent=self,
        )
        self.accept()
示例#11
0
 def submit(self):
     if self.data_name is not None and self.data_name in [
             d.name for d in self.appctx.datasets
     ]:
         show_warning(
             "Dataset already exists",
             f"A dataset named '{self.data_name}' already exists.\n"
             f"Use a different name or clear the dataset name field.",
         )
     else:
         print(f"Calculating Percent NA")
         # Run with a progress dialog
         RunProgress.run_with_progress(
             progress_str="Calculating Percent NA...",
             function=self.get_func(),
             slot=self.appctx.add_dataset,
             parent=self,
         )
         self.log_command()
         self.accept()
示例#12
0
 def submit(self):
     if self.data_name is not None and self.data_name in [
             d.name for d in self.appctx.datasets
     ]:
         show_warning(
             "Dataset already exists",
             f"A dataset named '{self.data_name}' already exists.\n"
             f"Use a different name or clear the dataset name field.",
         )
     elif self.outcome is None:
         show_warning("Missing Parameter", "A phenotype must be selected")
     else:
         print(f"Running EWAS...")
         # Run with a progress dialog
         RunProgress.run_with_progress(
             progress_str="Running EWAS...",
             function=self.get_func(),
             slot=self.appctx.add_dataset,
             parent=self,
         )
         self.log_command()
         self.accept()
 def submit(self):
     if self.data_name is not None and self.data_name in [
         d.name for d in self.appctx.datasets
     ]:
         warnings.show_warning(
             "Dataset already exists",
             f"A dataset named '{self.data_name}' already exists.\n"
             f"Use a different name or clear the dataset name field.",
         )
     else:
         # Run with a progress dialog
         if self.data_name is None:
             slot = self.appctx.update_data
         else:
             slot = self.appctx.add_dataset
         RunProgress.run_with_progress(
             progress_str="Filtering variables...",
             function=self.get_func(),
             slot=slot,
             parent=self,
         )
         self.accept()