Ejemplo n.º 1
0
 def createVisualisation(self):
     try:
         CirGoFileConversion.ConvertToThreeCoulmnsInput(self.inputFileName)
     except:
         self.statusBar.setMessage("File could not be converted. Please check the file format and it's content!")
         traceback.print_exc()
     else:
         try:
             ifn, ife = os.path.splitext(self.inputFileName)
             CirGOVisualGO.CircularVisualGO(ifn + "_converted.csv", int(self.nrCategories.get()), float(self.fontSize.get()), self.figureLegendEntry.get(), self.outputFileName)    ########### Propoer file naming
         except:
             self.statusBar.setMessage("File could not be visualised!")
             traceback.print_exc()
Ejemplo n.º 2
0
def main(argv):
    print(argv)
    argsparser = argparse.ArgumentParser(
        prog="CirGO",
        usage=
        'This is the command line interface for the CirGO visualisation software.\n'
        + '\n HELP: help for using the software. python CirGO.py -h\n' +
        '\n GUI: usage for the graphical user interface option of the CirGO software. python CirGO.py -gui\n'
        +
        '\n COMMAND LINE (CMD): usage for the command line option of the CirGO software. python CirGO.py - inputFile INPUTFILE [-outputFile OUTPUTFILE] [-fontSize FONTSIZE] [-numCat NRCATEGORIES] [-leg FIGURE_LEGEND]\n'
        +
        '\n INTERACTIVE MODE (INT): interactive option of the CirGO software. python CirGO.py -int\n ',
        formatter_class=RawTextHelpFormatter,
        epilog=
        "Copyright (C) 2018. This software is licensed under the terms of the GNU general public license (version 3).\nIf you use this software, please cite the following publication: ......."
    )

    arg_group_dummy = argsparser.add_argument_group(
        '',
        '--------------------------------------------------------------------------------------------------------------------'
    )

    arg_group_gui = argsparser.add_argument_group(
        'GUI',
        'Graphical User Interface (GUI) option of the CirGO software.\nExample: python CirGO.py -gui'
    )
    arg_group_gui.add_argument(
        "-gui",
        action='store_true',
        help=
        "GUI option of the CirGO software. If this option is selected, all other command line parameters will be ignored.\n"
    )
    arg_group_gui.add_argument("    ", action='store_true')

    arg_group_cmd = argsparser.add_argument_group(
        'CMD',
        'Command line option of the CirGO software. \nExample: python CirGO.py -inputFile C:\\mydir\Example_REVIGO_Input_BP.csv -outputFile C:\\mydir\\Visual_BP.svg -fontSize 6.5 -numCat 40 -legend "Name & Proportion of Biological process (inner ring)"'
    )
    arg_group_cmd.add_argument(
        "-inputFile",
        default=None,
        type=str,
        help=
        "[csv] Input path and filename of a REVIGO file. \nExample: C:\\mydir\\Example_REVIGO_Input_BP.csv"
    )
    arg_group_cmd.add_argument(
        "-outputFile",
        default=None,
        type=str,
        help=
        "[svg] Output path and filename. \nExample: C:\\mydir\\Visual_BP.svg")
    arg_group_cmd.add_argument(
        '-fontSize',
        type=float,
        default=DEFAULT_FONT_SIZE,
        help="[float] Font Size (Default: " + str(DEFAULT_FONT_SIZE) +
        "). Select one from the range 6.0 -7.5 \nExample: 6.5")
    arg_group_cmd.add_argument(
        '-numCat',
        type=int,
        default=DEFAULT_NUM_OF_CATEGORIES,
        help="[int] Number of Categories to be visualised. (Default: " +
        str(DEFAULT_NUM_OF_CATEGORIES) + "). \nExample: 60 or lower")
    arg_group_cmd.add_argument(
        '-legend',
        type=str,
        default=DEFAULT_LEGEND_NAME,
        help=
        "[str] Legend title to be displayed in the figure. Select relevant example of the legend name. \nExample:\n   (1) Name & Proportion of Biological process (inner ring)\n   (2) Name & Proportion of Cellular component (inner ring)\n   (3) Name & Proportion of Molecular function (inner ring) "
    )
    arg_group_cmd.add_argument("    ", action='store_true')

    arg_group_int = argsparser.add_argument_group(
        'INT',
        'Interactive option of the CirGO software. \nExample: python CirGO.py -int\n'
    )
    arg_group_int.add_argument(
        "-int",
        action='store_true',
        help=
        "Interactive option of the CirGO software. \nInput file from REVIGO as CSV [str]: 'C://mydir/Example_REVIGO_Input_BP.csv'    ***NOTE*** provide a file directory as a string, where a backslash '\\' has to be changed to the forward slash '/'.\n      \nFont Size (Example - 7.0) [float]: 7.0\n      \nNumber of Categories (Example - 40) [int]: 40\n     \nLegend name. Example: 'Name & Proportion of Biological process (inner ring)' [str]: 'Name & Proportion of Biological process (inner ring)'    ***NOTE*** Select relevant example of the legend name.\n        \nOutput file in svg format (Example: input filename + svg) [str]: 'C://mydir/Visual_BP.svg'    ***NOTE*** provide a file directory as a string, where a backslash '\\' has to be changed to the forward slash '/'.\n "
    )

    args = argsparser.parse_args()

    # validate arguments
    if (args.fontSize <= 1) or (args.numCat < 1):
        print(
            "Wrong command line parameters: fontSize must be a positive float value, and numCat must be an positive integer value!"
        )
        sys.exit()
    try:
        args.fontSize = float(args.fontSize)
        args.numCat = int(args.numCat)
    except:
        print(
            "Wrong command line parameters: fontSize must be a positive float value, and numCat must be an positive integer value!"
        )
        traceback.print_exc()
        sys.exit()

    if (not args.gui) and (args.inputFile == None) and (not args.int):
        print(
            "To see a help page, python CirGO.py -h. Otherwise select the GUI, command line or interactive mode of the software!"
        )
        traceback.print_exc()
        sys.exit()

    if args.gui:
        root = Tk()
        app = Application(master=root)
        app.master.title('CirGO - Circular Gene Ontology terms Visualisation')
        app.mainloop()
        root.destroy()

    elif args.int:
        # Input File --------------------------------------------------------------------------------------------------------------------
        infl = input("Input file from REVIGO as CSV [str]: ")
        if type(infl) != str:
            print(
                "Wrong command line parameters: Input File must be a string.")
            sys.exit()
        try:
            infl = str(infl)
        except:
            print(
                'Input file is not a string. Please enter a valid filename as a string.'
            )
            traceback.print_exc()
            sys.exit()
# Font Size --------------------------------------------------------------------------------------------------------------------
        insize = raw_input("Font Size (Example - 7.0) [float]: ")
        if insize == "":
            print("Default Font Size is used. [Example: 7.0]")
            insize = DEFAULT_FONT_SIZE
        elif type(float(insize)) != float:
            print(
                "Wrong command line parameters: Font Size must be a positive float value"
            )
            sys.exit()
        elif float(insize) < 0:
            print(
                "Wrong command line parameters: Font Size must be a positive float value"
            )
            sys.exit()
        try:
            insize = float(insize)
        except:
            print(
                "Font Size is not a float. Please enter Font Size as a float.")
            traceback.print_exc()
            sys.exit()
# Number of Categories--------------------------------------------------------------------------------------------------------------------
        incat = raw_input(
            "Number of Categories (Example - 40) [int]: ")  #  a string
        if incat == "":
            print("Default Number of Categories is used [Example: 40]")
            incat = DEFAULT_NUM_OF_CATEGORIES
        elif type(int(float(incat))) != int:
            print(
                "Wrong command line parameters: Number of Categories must be a positive integer value"
            )
            sys.exit()
        elif int(float(incat)) < 0:
            print(
                "Wrong command line parameters: Number of Categories must be a positive integer value"
            )
            sys.exit()
        try:
            incat = int(float(incat))
        except:
            print(
                "Number of Categories is not an integer. Please enter a valid number as an integer."
            )
            traceback.print_exc()
            sys.exit()
# Legend--------------------------------------------------------------------------------------------------------------------
        inleg = raw_input(
            'Legend name. Example: "Name & Proportion of Biological process (inner ring)" [str]: '
        )
        if inleg == "":
            print(
                'Default Legend Name is used [Example: "Name & Proportion of Biological process (inner ring)"]'
            )
            inleg = DEFAULT_LEGEND_NAME
        elif type(inleg) != str:
            print(
                "Wrong command line parameters: Legend name must be a string.")
            sys.exit()
        try:
            inleg = str(inleg)
        except:
            print(
                "Legen Name is not a string. Please enter a valid Legend Name as a string."
            )
            traceback.print_exc()
            sys.exit()


# OutputFile--------------------------------------------------------------------------------------------------------------------
        outfl = input(
            "Output file in svg format (Example: input filename + svg) [str]: "
        )
        if type(outfl) != str:
            print(
                "Wrong command line parameters: Output file must be a string.")
            sys.exit()
        try:
            outfl = str(outfl)
        except:
            print(
                "Output file is not a string. Please enter a valid filename as a string."
            )
            traceback.print_exc()
            sys.exit()

        CirGoFileConversion.ConvertToThreeCoulmnsInput(infl,
                                                       infl + "_converted.csv")
        CirGOVisualGO.CircularVisualGO(infl + "_converted.csv", int(incat),
                                       float(insize), str(inleg), str(outfl))

    else:
        try:
            if os.path.isfile(args.inputFile):
                print("Opening input file: " + args.inputFile)
                fn, fe = os.path.splitext(args.inputFile)
                if (args.outputFile == None):
                    args.outputFile = fn + ".svg"
                CirGoFileConversion.ConvertToThreeCoulmnsInput(
                    args.inputFile, fn + "_converted.csv")
            else:
                print(
                    "Input file could not be found. Please enter a valid filename."
                )
                sys.exit()
        except:
            print(
                "File could not be converted. Please check if the file exists and if the file format is correct!"
            )
            traceback.print_exc()
            sys.exit()
        try:
            fn, fe = os.path.splitext(args.inputFile)

            CirGOVisualGO.CircularVisualGO(fn + "_converted.csv",
                                           int(args.numCat),
                                           float(args.fontSize), args.legend,
                                           args.outputFile)
        except:
            traceback.print_exc()
            print("File could not be visualised!")
            sys.exit()