def loadFile(self, file: str = ""):
        """
        provides a filedialog to load an additional file to the dataframe
        """
        options = QFileDialog.Options()
        if not file:
            file, _ = QFileDialog.getOpenFileName(
                self,
                "QFileDialog.getOpenFileName()",
                "",
                "All Files (*);;mzML Files (*.mzML)",
                options=options)

        if file:
            cdf = Tdf.getTable(self)
            filelist = []
            filePath = file.rsplit("/", 1)[0]
            temp = file.split("/")
            fileName = temp[len(temp) - 1]
            if file:
                # print(file)
                filelist.append(fileName)
                tagged_file = fh.tagfiles(self, filelist)
                df = fh.createRawTable(self, tagged_file, filePath)

                ndf = cdf.append(df, ignore_index=True)

                Tdf.setTable(self, ndf)
                self.drawTable()
            else:
                return False
 def LabelBtn(self):
     """
     Let the user choose the number of labels, it will generate
     the labels for the copied rows and also links the sample to
     the label. Gives an option to continue the samplecount
     over fraction groups.
     """
     labelnum, ok = QInputDialog.getInt(
         self, "Label",
         "Please specify the multiplicity " + "of the selected rows")
     if ok:
         rep = QMessageBox.question(
             self, "Continuous Sample", "Does the samplenumber " +
             "continue over multiple " + "fraction groups?",
             (QMessageBox.Yes | QMessageBox.No), QMessageBox.No)
         if rep == QMessageBox.Yes:
             try:
                 Tdf.modifyLabelSample(self, labelnum, True)
             except ValueError:
                 QMessageBox.about(self, "Warning",
                                   "Unfortunaly, " + "your Number was <1")
         else:
             try:
                 Tdf.modifyLabelSample(self, labelnum, False)
             except ValueError:
                 QMessageBox.about(self, "Warning",
                                   "Unfortunaly, " + "your Number was <1")
         self.drawTable()
 def RemoveBtn(self):
     """
     Enables the user to remove selected rows
     """
     selrows = self.getSelRows()
     Tdf.rmvRow(self, selrows)
     self.drawTable()
 def loadDir(self, filepath: str):
     Files = fh.getFiles(self, filepath)
     delimiters = ["_"]
     preparedFiles = fh.tagfiles(self, sorted(Files), delimiters[0])
     rawTable = fh.createRawTable(self, preparedFiles, filepath)
     Tdf.setTable(self, rawTable)
     self.drawTable()
    def FractionBtn(self):
        """
        Enables the user to change the Fraction of selected rows to a given
        number or give a range.
        """
        selrows = self.getSelRows()

        # first inputdialog
        fracmin, ok = QInputDialog.getInt(
            self, "Fraction",
            "Enter minimal Fractionnumber " + "or single Fractionnumber")
        # second inputdialog if first is accepted
        if ok:
            fracmax, ok = QInputDialog.getInt(
                self, "Fraction", "Enter maximal Fractionnumber " +
                "or 0 for single Fractionnumber")
            if ok:
                # decision if multiple fractions are set or just one
                if fracmax != 0:
                    if fracmax > fracmin:
                        # third messagedialog
                        rep = QMessageBox.question(
                            self, "Fraction Group?",
                            "Do you want to infer a " +
                            "Fraction Group from the " + "given range?",
                            (QMessageBox.Yes | QMessageBox.No), QMessageBox.No)

                        # when confirmed the fraction froup is set
                        # when max fraction is reached.
                        if rep == QMessageBox.Yes:
                            Tdf.modifyFraction(self, selrows, fracmin, fracmax)
                            fractions = fracmax - fracmin + 1
                            numgroups = math.ceil(len(selrows) / fractions)
                            splicelist = [0]
                            for g in range(1, numgroups + 1):
                                splicelist.append(g * fractions)
                            splicelist.append(len(selrows))
                            for group in range(1, numgroups + 1):
                                indexa = splicelist[group - 1]
                                indexb = splicelist[group]
                                subrows = selrows[indexa:indexb]
                                Tdf.modifyGroup(self, subrows, group)
                        else:
                            Tdf.modifyFraction(self, selrows, fracmin, fracmax)

                    elif fracmax == fracmin:
                        Tdf.modifyFraction(self, selrows, fracmin)

                    else:
                        QMessageBox.warning(
                            self, "Error",
                            "Please use " + "a higher integer " +
                            "number for the maximum " + "fractionnumber.")

                else:
                    Tdf.modifyFraction(self, selrows, fracmin)
                self.drawTable()
    def GroupBtn(self):
        """
        Enables the user to change the group of selected rows to a given
        number.
        """
        selrows = self.getSelRows()

        groupnum, ok = QInputDialog.getInt(self, "Group Number",
                                           "Enter Integer Groupnumber")

        if ok:
            Tdf.modifyGroup(self, selrows, groupnum)
            self.drawTable()
 def editField(self):
     if len(self.table.selectedItems()) == 1:
         if not self.drawtableactive:
             itemchanged = self.table.currentItem()
             newvalue = itemchanged.text()
             row = itemchanged.row()
             column = itemchanged.column()
             if column != 2:
                 Tdf.modifyField(self, row, column, newvalue)
                 self.drawTable()
             else:
                 QMessageBox.about(
                     self, "Warning", "Please only, " +
                     "modify attribute columns," + "not the filepath.\n" +
                     "To change the filepath," + "use remove and add file.")
                 self.drawTable()
 def updateTableView(self, rows):
     tabledf = Tdf.getTable(self)
     rowcount = len(tabledf.index)
     for i in range(rowcount):
         self.table.setRowHidden(i, True)
     for i in rows:
         self.table.setRowHidden(i, False)
    def exportBtn(self):
        """
        Exports the table to csv or tsv;default is csv
        """
        options = QFileDialog.Options()
        file, _ = QFileDialog.getSaveFileName(
            self,
            "QFileDialog.getSaveFileName()",
            "",
            "All Files (*);;tsv (*.tsv);; csv (*.csv)",
            options=options)

        if file:
            self.tablefile_loaded = True
            fpath = file.split("/")[-1]
            self.loaded_table = fpath
            df = Tdf.getTable(self)
            temp = file.split("/")
            fileName = temp[len(temp) - 1]
            length = len(fileName)
            if length < 4:
                ftype = "csv"
                file = file + ".csv"
            elif fileName.find('.csv', length - 4) != -1:
                ftype = "csv"
            elif fileName.find('.tsv', length - 4) != -1:
                ftype = "tsv"
            else:
                ftype = "csv"
                file = file + ".csv"

            fh.exportTable(self, df, file, ftype)
Пример #10
0
    def saveFunction(self):
        """
        saves all work from the GUI in chosen folder
        the prefix of the outputfiles can be choosen
        """
        dlg = QFileDialog(self)
        filePath = dlg.getExistingDirectory()

        if filePath:
            filePath = filePath + "/"
            tablePath = ""
            ok = False
            table_empty = self.tview.table.rowCount() <= 0

            if table_empty:
                tablePath = ""
                self.tablefile_loaded = False
                self.tview.tablefile_loaded = False

            if self.tablefile_loaded is False and table_empty is False \
                    and self.tview.tablefile_loaded is False:
                prefix, ok = QInputDialog.getText(
                    self, "Prefix for outputfiles",
                    "Please specify a prefix " + "for the outputfiles")
            if ok:
                tablePath = filePath + prefix + "_design.tsv"
                self.loaded_table = prefix + "_design.tsv"
                self.tablefile_loaded = True

            if self.tablefile_loaded and self.tview.tablefile_loaded is False:
                tablePath = filePath + self.loaded_table

            if self.tview.tablefile_loaded:
                tablePath = filePath + self.tview.loaded_table

            if (ok or self.tablefile_loaded or self.tview.tablefile_loaded) \
                    and table_empty is False:
                df = Tdf.getTable(self.tview)
                fh.exportTable(self.tview, df, tablePath, "tsv")

            xmlPath = filePath + self.loaded_ini
            try:
                self.cview.tree.write(xmlPath)
            except TypeError:
                print("No Config loaded to be saved!")

            if self.loaded_ini != "" and tablePath.split("/")[-1] != "":
                QMessageBox.about(
                    self, "Successfully saved!", "Files have been saved as: " +
                    self.loaded_ini + ", " + tablePath.split("/")[-1])
            elif self.loaded_ini != "":
                QMessageBox.about(self, "Successfully saved!",
                                  "ini has been saved as: " + self.loaded_ini)
            elif tablePath.split("/")[-1] != "":
                QMessageBox.about(
                    self, "Successfully saved!",
                    "Table has been saved as: " + tablePath.split("/")[-1])
Пример #11
0
    def importBtn(self, file: str = ""):
        """
        Imports table files, currently working are csv and tsv
        """
        options = QFileDialog.Options()
        if not file:
            file, _ = QFileDialog.getOpenFileName(
                self,
                "QFileDialog.getOpenFileName()",
                "",
                "All Files (*);;tsv (*.tsv);; csv (*.csv)",
                options=options)

        if file:
            df = fh.importTable(self, file)
            Tdf.setTable(self, df)
            self.drawTable()
            self.tablefile_loaded = True
            file = file.split("/")[-1]
            self.loaded_table = file
 def filterTable(self):
     """
     get changes from textbox and update table when
     more than 3 characters are given.
     then update table with the rows that
     contain the input in the give column.
     """
     tb = self.textbox
     givencolumn = "Spectra_Filepath"
     tbinput = tb.text()
     ft = Tdf.getTable(self)
     validDf = not (ft.empty or ft.dropna().empty)
     # print(validDf)  # for debugging
     # print(type(ft))  # for debugging
     if len(tbinput) >= 2:
         rowstoshow = ft[ft[givencolumn].str.contains(tbinput)]
         self.updateTableView(rowstoshow.index)
     else:
         self.updateTableView(ft.index)
    def drawTable(self):
        """
        draws a table with the dataframe table model in tableDataFrame
        """
        self.drawtableactive = True

        tabledf = Tdf.getTable(self)
        # print(tabledf)  # For debugging
        rowcount = len(tabledf.index)
        colcount = len(tabledf.columns)
        self.table.setRowCount(rowcount)
        for r in range(rowcount):
            row = tabledf.index[r]
            for c in range(colcount):
                col = tabledf.columns[c]
                if col == 'Spectra_Filepath':
                    path = tabledf.at[row, col].split("/")
                    name = path[len(path) - 1]
                    self.table.setItem(r, c, QTableWidgetItem(name))
                else:
                    item = str(tabledf.at[row, col])
                    self.table.setItem(r, c, QTableWidgetItem(item))

        self.drawtableactive = False
Пример #14
0
    def loadFunction(self, filePath: str = ""):
        """
        loads all files (.tsv .ini, .fasta) from a given
        directory.
        If .tsv file is not present the experimental design is
        filled with mzMl files

        If no .ini file is present default ini file is written
        and is loaded automatically
        """
        if not filePath:
            dlg = QFileDialog(self)
            filePath = dlg.getExistingDirectory()
        self.loaded_dir = filePath
        self.sview.fillTable(filePath)
        if filePath:
            try:
                self.tsvfiles = glob.glob('*.tsv')
                if len(self.tsvfiles) > 1:
                    QMessageBox.about(
                        self, "Sorry!", "There are multiple '.tsv-'"
                        "files in the specified folder. "
                        "Please choose the one you intent "
                        "to use.")
                    dial = QFileDialog(self)
                    newFilePath = dial.getOpenFileName(self, "Choose .tsv",
                                                       filePath,
                                                       "Tables (*.tsv)")
                    if newFilePath[0] != '':
                        newFile = newFilePath[0].split("/")[-1]
                        self.tsvfiles = [newFile]
                    else:
                        QMessageBox.about(
                            self, "Sorry!", "Nothing was choosen. "
                            "Therefore no '.tsv'-file was "
                            "loaded. ")
                        self.tsvfiles = []
                for file in self.tsvfiles:
                    df = fh.importTable(self.tview, file)
                    Tdf.setTable(self.tview, df)
                    self.tview.drawTable()
                    self.loaded_table = file
                    self.tablefile_loaded = True

            except TypeError:
                "No '.tsv' or '.csv'-file could be loaded."

            if self.tablefile_loaded is False:
                try:
                    self.tview.loadDir(filePath)
                    self.tablefile_loaded = True
                except TypeError:
                    print("Could not load '.mzMl'-files.")

            try:
                self.iniFiles = glob.glob('*.ini')
                if len(self.iniFiles) > 1:
                    QMessageBox.about(
                        self, "Sorry!", "There are multiple '.ini'-"
                        "files in the specified folder. "
                        "Please choose the one you intent "
                        "to use.")
                    dial = QFileDialog(self)
                    newFilePath = dial.getOpenFileName(self, "Choose .ini",
                                                       filePath,
                                                       "Config (*.ini)")
                    if newFilePath[0] != '':
                        newFile = newFilePath[0].split("/")[-1]
                        self.iniFiles = [newFile]
                    else:
                        QMessageBox.about(
                            self, "Sorry!", "Nothing was choosen. "
                            "Therefore no '.ini'-file was "
                            "loaded. ")
                        self.iniFiles = []
                for file in self.iniFiles:
                    self.cview.generateTreeModel(file)
                    self.loaded_ini = file
                    self.ini_loaded = True
            except TypeError:
                print("Could not load .ini file.")

            if self.ini_loaded is False:
                try:
                    runcall = "ProteomicsLFQ "
                    writeIniFile = "-write_ini "
                    out = "Config.ini"
                    command = (runcall + writeIniFile + out)
                    os.chdir(filePath)
                    os.system(command)
                    iniFiles = glob.glob('*.ini')
                    for file in iniFiles:
                        self.cview.generateTreeModel(file)
                        self.loaded_ini = file
                        self.ini_loaded = True
                except TypeError:
                    print("Could not write and load default '.ini'-file.")

            try:
                self.fastafiles = glob.glob('*fasta')
                if len(self.fastafiles) > 1:
                    QMessageBox.about(
                        self, "Sorry!", "There are multiple '.fasta'-"
                        "files in the specified folder. "
                        "Please choose the one you intent "
                        "to use.")
                    dial = QFileDialog(self)
                    newFilePath = dial.getOpenFileName(
                        self, "Choose .fasta", filePath,
                        "Proteindata (*.fasta)")
                    if newFilePath[0] != '':
                        newFile = newFilePath[0].split("/")[-1]
                        self.fastafiles = [newFile]
                    else:
                        QMessageBox.about(
                            self, "Sorry!", "Nothing was choosen. "
                            "Therefore, no '.fasta'-file "
                            "was loaded. ")
                        self.fastafiles = []
                for file in self.fastafiles:
                    self.fview.loadFile(file)
                    self.loaded_fasta = file
                    self.fasta_loaded = True
            except TypeError:
                print("Could not load '.fasta'-file.")