Example #1
0
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Custom bed Input Files:", 0,
                                      "custom_input.bed",
                                      ("bed files", ".bed"))
    dialog.createFileSelector("Genome Fasta File:", 1, ("Fasta Files", ".fa"))
    dialog.createCheckbox("Stratify data by microsatellite stability?", 2, 0)
    dialog.createCheckbox("Stratify by mutation signature?", 2, 1)
    dialog.createCheckbox("Separate individual cohorts?", 3, 0)
    dialog.createCheckbox("Only use single nucleotide substitutions?", 4, 0)
    dialog.createCheckbox("Include indels in output?", 4, 1)

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    bedInputFilePaths = selections.getFilePathGroups()[0]
    genomeFilePath = selections.getIndividualFilePaths()[0]
    stratifyByMS = selections.getToggleStates()[0]
    stratifyByMutSig = selections.getToggleStates()[1]
    separateIndividualCohorts = selections.getToggleStates()[2]
    onlySingleBaseSubs = selections.getToggleStates()[3]
    includeIndels = selections.getToggleStates()[4]

    parseCustomBed(bedInputFilePaths, genomeFilePath, stratifyByMS,
                   stratifyByMutSig, separateIndividualCohorts,
                   onlySingleBaseSubs, includeIndels)
Example #2
0
def main():

    # Create the Tkinter dialog.
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector(
        "Bed Mutation File:", 0, "singlenuc_" + DataTypeStr.mutations + ".bed",
        ("Bed Files", ".bed"))
    dialog.createDropdown("Expansion Context", 1, 0,
                          ("Trinuc/Quadrunuc", "Pentanuc/Hexanuc"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    inputBedFilePaths = list(selections.getFilePathGroups())[
        0]  # A list of paths to original bed mutation files
    expansionContext = list(selections.getDropdownSelections())[
        0]  # What context the file should be expanded to.

    if expansionContext == "Trinuc/Quadrunuc":
        expansionContextNum = 3
    elif expansionContext == "Pentanuc/Hexanuc":
        expansionContextNum = 5
    else:
        raise ValueError("Matching strings is hard.")

    expandContext(inputBedFilePaths, expansionContextNum)
Example #3
0
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Bed Mutation Files:", 0,
                                      DataTypeStr.mutations + ".bed",
                                      ("Bed Files", ".bed"))
    dialog.createDropdown(
        "Background Context", 1, 0,
        ("Singlenuc/Dinuc", "Trinuc/Quadrunuc", "Pentanuc/Hexanuc"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    mutationFilePaths = list(selections.getFilePathGroups())[
        0]  # A list of paths to the bed mutation files
    backgroundContext: str = list(selections.getDropdownSelections())[
        0]  # What context should be used to generate the background.

    # Convert background context to int
    if backgroundContext == "Singlenuc/Dinuc":
        backgroundContextNum = 1
    elif backgroundContext == "Trinuc/Quadrunuc":
        backgroundContextNum = 3
    elif backgroundContext == "Pentanuc/Hexanuc":
        backgroundContextNum = 5
    else:
        raise ValueError("Matching strings is hard.")

    generateMutationBackground(mutationFilePaths, backgroundContextNum)
def main():

    # Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Feature Files (e.g. mutations):", 0,
                                      "bin_me.bed", ("Bed Files", ".bed"))
    dialog.createFileSelector("Gene Designations:", 1, ("Bed Files", ".bed"))
    dialog.createCheckbox("Color Domain is present in 7th (index=6) column", 2,
                          0)

    flankDialog = dialog.createDynamicSelector(3, 0)
    flankDialog.initCheckboxController(
        "Gene designations include flanking regions")
    flankSizeDialog = flankDialog.initDisplay(True, "FlankSize")
    flankSizeDialog.createTextField("Flanking bin size:",
                                    0,
                                    0,
                                    defaultText="0")
    flankSizeDialog.createTextField("Flanking bin number:",
                                    1,
                                    0,
                                    defaultText="0")
    flankDialog.initDisplayState()

    fileSuffixDialog = dialog.createDynamicSelector(4, 0)
    fileSuffixDialog.initCheckboxController("Custom file suffix")
    suffixDialog = fileSuffixDialog.initDisplay(True, "Suffix")
    suffixDialog.createTextField("File Suffix:", 0, 0, defaultText="all_genes")
    fileSuffixDialog.initDisplayState()

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    if dialog.selections.getToggleStates()[0]: colorColIndex = 6
    else: colorColIndex = None

    if flankDialog.getControllerVar():
        flankBinSize = int(dialog.selections.getTextEntries("FlankSize")[0])
        flankBinNum = int(dialog.selections.getTextEntries("FlankSize")[1])
    else:
        flankBinSize = 0
        flankBinNum = 0

    if fileSuffixDialog.getControllerVar():
        fileSuffix = dialog.selections.getTextEntries("Suffix")[0]
    else:
        fileSuffix = ""

    binInGenes(dialog.selections.getFilePathGroups()[0],
               dialog.selections.getIndividualFilePaths()[0], flankBinSize,
               flankBinNum, fileSuffix, colorColIndex)
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Mutation Background Files:", 0,
                                      DataTypeStr.mutBackground + ".tsv",
                                      ("Tab Seperated Values Files", ".tsv"))
    dialog.createMultipleFileSelector("Nucleosome Map Files:", 1,
                                      "nucleosome_map.bed",
                                      ("Bed Files", ".bed"))

    selectSingleNuc = dialog.createDynamicSelector(2, 0)
    selectSingleNuc.initCheckboxController(
        "Generate background with a single nucleosome radius (73 bp)")
    linkerSelectionDialog = selectSingleNuc.initDisplay(1, "singleNuc")
    linkerSelectionDialog.createCheckbox(
        "Include 30 bp linker DNA on either side of single nucleosome radius.",
        0, 0)
    selectSingleNuc.initDisplay(0)
    selectSingleNuc.initDisplayState()

    dialog.createCheckbox(
        "Generate background with a nucleosome group radius (1000 bp)", 3, 0)

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    mutationBackgroundFilePaths = selections.getFilePathGroups()[
        0]  # A list of mutation file paths
    nucleosomeMapNames = [
        getIsolatedParentDir(nucleosomeMapFile)
        for nucleosomeMapFile in selections.getFilePathGroups()[1]
    ]
    if selectSingleNuc.getControllerVar():
        useSingleNucRadius = True
        includeLinker = selections.getToggleStates("singleNuc")[0]
    else:
        useSingleNucRadius = False
        includeLinker = False
    useNucGroupRadius = selections.getToggleStates()[0]

    if includeLinker: linkerOffset = 30
    else: linkerOffset = 0

    generateNucleosomeMutationBackground(mutationBackgroundFilePaths,
                                         nucleosomeMapNames,
                                         useSingleNucRadius, useNucGroupRadius,
                                         linkerOffset)
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector(
        "Background Nucleosome Mutation Counts Files:", 0,
        DataTypeStr.nucMutBackground + ".tsv",
        ("Tab Seperated Values Files", ".tsv"))

    customBackgroundSelector = dialog.createDynamicSelector(1, 0)
    customBackgroundSelector.initCheckboxController(
        "Include files with another data set as custom background.")
    customBackgroundFileSelector = customBackgroundSelector.initDisplay(
        True, "customBackground")
    customBackgroundFileSelector.createMultipleFileSelector(
        "Raw nucleosome counts to be normalized", 0,
        DataTypeStr.rawNucCounts + ".tsv", ("TSV Files", ".tsv"))
    customBackgroundFileSelector.createFileSelector(
        "Data Directory for nucleosome counts to be used as background",
        1,
        directory=True)
    customBackgroundSelector.initDisplayState()

    dialog.createCheckbox(
        "Include alternative scaling factor indepedent of nucleosome map.", 2,
        0)

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    backgroundCountsFilePaths = selections.getFilePathGroups()[
        0]  # A list of background mutation counts file paths

    if customBackgroundSelector.getControllerVar():
        customRawCountsFilePaths = selections.getFilePathGroups(
            "customBackground")[0]
        customBackgroundCountsDir = selections.getIndividualFilePaths(
            "customBackground")[0]
    else:
        customRawCountsFilePaths = None
        customBackgroundCountsDir = None

    includeAlternativeScaling = selections.getToggleStates()[0]

    normalizeCounts(backgroundCountsFilePaths, customRawCountsFilePaths,
                    customBackgroundCountsDir, includeAlternativeScaling)
Example #7
0
def main():

    # Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Bed Files:",0,"I_have_bad_chromosomes.bed",("Bed Files",".bed"))    
    dialog.createFileSelector("Genome Fasta File:",1,("Fasta Files",".fa"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    removeUnacceptableChromosomes(dialog.selections.getFilePathGroups()[0], dialog.selections.getIndividualFilePaths()[0])
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Prepared Input Files:",0,DataTypeStr.mutations + ".bed",("bed files",".bed"))
    dialog.createFileSelector("Genome Fasta File:",1,("Fasta Files",".fa"))
    dialog.createCheckbox("Skip formatting checks for all but the first line",2,0)

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    parsePreparedInput(dialog.selections.getFilePathGroups()[0], dialog.selections.getIndividualFilePaths()[0],
                       not dialog.selections.getToggleStates()[0])
Example #9
0
def main():

    # Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Genome Feature Positions Files:", 0,
                                      "context_mutations.bed",
                                      ("Bed Files", ".bed"))
    dialog.createFileSelector("Gene Ranges File (merged):", 1,
                              ("Bed Files", ".bed"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    splitGenicAndIntergenic(dialog.selections.getFilePathGroups()[0],
                            dialog.selections.getIndividualFilePaths()[0])
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Mutation Files:", 0,
                                      DataTypeStr.mutations + ".bed",
                                      ("Bed Files", ".bed"))
    dialog.createMultipleFileSelector("Binding Motifs Files:", 1,
                                      "binding_motifs.bed",
                                      ("Bed Files", ".bed"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    countInBindingMotifs(dialog.selections.getFilePathGroups()[0],
                         dialog.selections.getFilePathGroups()[1])
Example #11
0
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Tab-Separated Nucleosome Counts Files:",0,
                                      DataTypeStr.generalNucCounts + ".tsv",("tsv files",".tsv"))
    dialog.createMultipleFileSelector("R Nucleosome Mutation Analysis Files:",1,
                                      ".rda",("rda files",".rda"))

    fileNumSelector = dialog.createDynamicSelector(2,0)
    fileNumSelector.initCheckboxController("Export to one file (as opposed to one file for each graph)")
    oneFileDialog = fileNumSelector.initDisplay(1, "oneFile")
    oneFileDialog.createFileSelector("Export File", 0, ("pdf file",".pdf"), newFile = True)
    manyFilesDialog = fileNumSelector.initDisplay(0, "manyFiles")
    manyFilesDialog.createFileSelector("Export Directory", 0, directory = True)
    fileNumSelector.initDisplayState()

    dialog.createCheckbox("Omit Outliers", 3, 0)
    dialog.createCheckbox("Smooth Nuc Group results", 3, 1)
    dialog.createCheckbox("Strand align results", 4, 0)
    #dialog.createCheckbox("Use normalized values from rda input", 5, 0)
    #dialog.createCheckbox("Use raw values from rda input", 5, 1)

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections = dialog.selections
    tsvFilePaths = selections.getFilePathGroups()[0]
    rdaFilePaths = selections.getFilePathGroups()[1]
    if fileNumSelector.getControllerVar(): exportPath = selections.getIndividualFilePaths("oneFile")[0]
    else: exportPath = selections.getIndividualFilePaths("manyFiles")[0]

    omitOutliers = bool(selections.getToggleStates()[0])
    smoothNucGroup = bool(selections.getToggleStates()[1])
    strandAlign = bool(selections.getToggleStates()[2])

    generateFigures(tsvFilePaths, rdaFilePaths, exportPath, omitOutliers, smoothNucGroup, 
                    strandAlign)
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("CPD Files:", 0, "CPD_data.bed",
                                      ("Bed Files", ".bed"))
    dialog.createMultipleFileSelector("Deamination Files:", 1,
                                      "deamination_data.bed",
                                      ("Bed Files", ".bed"))
    dialog.createFileSelector("Genome Fasta File:", 2, ("Fasta File", ".fa"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    parseDeaminationData(dialog.selections.getFilePathGroups()[0],
                         dialog.selections.getFilePathGroups()[1],
                         dialog.selections.getIndividualFilePaths()[0])
def main():

    # Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Genome Feature Positions Files:", 0,
                                      "context_mutations.bed",
                                      ("Bed Files", ".bed"))
    dialog.createFileSelector("Nucleosome Dyad Center Positions:", 1,
                              ("Bed Files", ".bed"))
    dialog.createCheckbox("Only Count Linker", 2, 0)

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    countFeaturesAboutNucleosomes(
        dialog.selections.getFilePathGroups()[0],
        dialog.selections.getIndividualFilePaths()[0],
        dialog.selections.getToggleStates()[0])
def main():

    # Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Quartile Files:", 0, "quartile.tsv",
                                      ("Tab Separated Files", ".tsv"))
    dialog.createFileSelector("Nucleosome Directory:", 1, directory=True)
    dialog.createDropdown("Stratification Type", 2, 0, ["h1 density", "other"])
    dialog.createCheckbox("Sloppy Copy?", 3, 0)

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    getQuartileNucleosomePositions(
        dialog.selections.getFilePathGroups()[0],
        dialog.selections.getIndividualFilePaths()[0],
        dialog.selections.getDropdownSelections()[0].replace(' ', '_'),
        dialog.selections.getToggleStates()[0])
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=os.path.dirname(__file__))
    dialog.createMultipleFileSelector("Genome Feature Files:", 0,
                                      DataTypeStr.mutations + ".bed",
                                      ("Bed Files", ".bed"))
    dialog.createFileSelector("Chromosome Sizes File:", 1,
                              ("Text File", ".txt"))
    dialog.createDropdown("Bin Size (bp):", 2, 0,
                          ("1000", "10000", "100000", "1000000"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    binAcrossGenome(dialog.selections.getFilePathGroups()[0],
                    dialog.selections.getIndividualFilePaths()[0],
                    int(dialog.selections.getDropdownSelections()[0]))
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Mutation Files:", 0,
                                      DataTypeStr.mutations + ".bed",
                                      ("Bed Files", ".bed"))
    dialog.createFileSelector("Domain Range File:", 1, ("Bed File", ".bed"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    mutationFilePaths = selections.getFilePathGroups()[
        0]  # A list of mutation file paths
    domainRangesFilePath = selections.getIndividualFilePaths()[
        0]  # The gene positions file path

    separateByChromatinRegions(mutationFilePaths, domainRangesFilePath)
                        (chromosome, startPos0Base, startPos1Base,
                         trinucContext, mutation, strand)) + '\n')

        # Sort the output file.
        print("Sorting output file...")
        subprocess.run(("sort", "-k1,1", "-k2,2n", outputTrinucBedFilePath,
                        "-o", outputTrinucBedFilePath),
                       check=True)


if __name__ == "__main__":

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector(
        "Kucab Substitutions File Paths:", 0, "final.txt",
        ("text files", ".txt"))  #NOTE: Weird file ending?
    dialog.createFileSelector("Genome Fasta File:", 1, ("Fasta Files", ".fa"))
    dialog.createFileSelector("Strongly Positioned Nucleosome File:", 2,
                              ("Bed Files", ".bed"))
    dialog.createCheckbox("Include all PAH Designations", 3, 0)

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    kucabSubstitutionsFilePaths = list(selections.getFilePathGroups())[0]
                             choppedUpLine[0])) + '\n')

        # Add the output file to the list.
        outputBedFilePaths.append(outputBedFilePath)

    # Pass the data to the custome bed parser.
    print("\nPassing data to custom bed parser.\n")
    parseCustomBed(outputBedFilePaths, genomeFilePath, nucPosFilePath, False,
                   False, False)


if __name__ == "__main__":

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Input Files:", 0, "alexandrov.txt",
                                      ("text files", ".txt"))
    dialog.createFileSelector("Genome Fasta File:", 1, ("Fasta Files", ".fa"))
    dialog.createFileSelector("Strongly Positioned Nucleosome File:", 2,
                              ("Bed Files", ".bed"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    bedInputFilePaths = list(selections.getFilePathGroups())[0]
    genomeFilePath = list(selections.getIndividualFilePaths())[0]
    nucPosFilePath = list(selections.getIndividualFilePaths())[1]
def main():

    #Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory(),
                           scrollable=True)
    dialog.createMultipleFileSelector(
        "Nucleosome Mutation Counts files:",
        0,
        DataTypeStr.normNucCounts + ".tsv",
        ("Tab Seperated Values Files", ".tsv"),
        additionalFileEndings=(DataTypeStr.rawNucCounts + ".tsv", ))
    dialog.createFileSelector("Output File",
                              1, ("R Data File", ".rda"),
                              ("Tab Separated Values File", ".tsv"),
                              newFile=True)

    dialog.createCheckbox(
        "Use expected periodicity from nucleosome maps instead of peak periodicity",
        2, 0)
    dialog.createCheckbox(
        "Align both DNA strands to run 5' to 3' before running the analysis",
        3, 0)
    dialog.createLabel('', 4, 0)

    mainGroupSearchRefine = dialog.createDynamicSelector(5, 0)
    mainGroupSearchRefine.initCheckboxController("Filter counts files")
    mainGroupSearchRefine.initDisplay(True).createNucMutGroupSubDialog(
        "MainGroup", 0)
    mainGroupSearchRefine.initDisplayState()

    periodicityComparison = dialog.createDynamicSelector(6, 0)
    periodicityComparison.initCheckboxController(
        "Compare periodicities between two groups")
    periodicityGroupType = periodicityComparison.initDisplay(
        True, "periodicityGroupType")

    periodicityGroupTypeSelector = periodicityGroupType.createDynamicSelector(
        0, 0)
    periodicityGroupTypeSelector.initDropdownController(
        "Compare periodicities...",
        ("Within original selection", "Against a newly selected group"))
    periodicityGroupsWithin = periodicityGroupTypeSelector.initDisplay(
        "Within original selection", "withinGroup")
    secondaryPeriodicityGroup = periodicityGroupTypeSelector.initDisplay(
        "Against a newly selected group", "secondaryGroupFilePaths")

    # Create two "sub-dialogs" for each of the groups, allowing the user to specify the make-up of that group for the "withinGroup" dialog.
    for i, dialogID in enumerate(("Sub-Group 1", "Sub-Group 2")):
        periodicityGroupsWithin.createNucMutGroupSubDialog(dialogID, i + 1)

    # Create one multiple file selector and one sub-dialog for the "secondaryGroup" dialog
    secondaryPeriodicityGroup.createMultipleFileSelector(
        "Nucleosome Mutation Counts files:",
        0,
        DataTypeStr.normNucCounts + ".tsv",
        ("Tab Seperated Values Files", ".tsv"),
        additionalFileEndings=(DataTypeStr.rawNucCounts + ".tsv", ))

    secondaryPeriodicityGroupSearchRefine = secondaryPeriodicityGroup.createDynamicSelector(
        2, 0)
    secondaryPeriodicityGroupSearchRefine.initCheckboxController(
        "Filter counts files")
    secondaryPeriodicityGroupSearchRefine.initDisplay(
        True).createNucMutGroupSubDialog("Secondary Group", 0)
    secondaryPeriodicityGroupSearchRefine.initDisplayState()

    periodicityGroupTypeSelector.initDisplayState()
    periodicityComparison.initDisplayState()

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    nucleosomeMutationCountsFilePaths = selections.getFilePathGroups()[0]
    if periodicityGroupTypeSelector.getControllerVar(
    ) == "Against a newly selected group":
        secondaryNucMutCountsFilePaths = selections.getFilePathGroups(
            "secondaryGroupFilePaths")[0]
    outputFilePath = list(selections.getIndividualFilePaths())[0]

    # Get the default periodicity value, testing the string to see if it is a valid float, if necessary.
    overridePeakPeriodWithExpected = bool(selections.getToggleStates()[0])
    alignStrands = bool(selections.getToggleStates()[1])

    # If group comparisons were requested, get the respective groups.
    filePathGroups: List[list] = list()
    for i in range(3):
        filePathGroups.append(list())

    groups = ["MainGroup"]
    if periodicityComparison.getControllerVar():
        if periodicityGroupTypeSelector.getControllerVar(
        ) == "Within original selection":
            groups += ("Sub-Group 1", "Sub-Group 2")
        else:
            groups.append("Secondary Group")

    for i, dialogID in enumerate(groups):

        # Was filtering even requested for the main group?
        if i == 0 and not mainGroupSearchRefine.getControllerVar():
            filePathGroups[0] = nucleosomeMutationCountsFilePaths
            continue

        # If we are examining the secondary group, check to see if filtering was even requested.
        if dialogID == "Secondary Group" and not secondaryPeriodicityGroupSearchRefine.getControllerVar(
        ):
            assert i == 1, "Secondary group encountered on unexpected iteration of for loop: " + str(
                i)
            filePathGroups[2] = secondaryNucMutCountsFilePaths
            filePathGroups[1] = filePathGroups[0].copy()
            filePathGroups[0] += filePathGroups[2]
            continue

        # Determine what normalization methods were requested
        normalizationMethods = list()
        normalizationSelections = selections.getToggleStates(dialogID)[:5]
        if normalizationSelections[0]: normalizationMethods += (1, 2)
        if normalizationSelections[1]: normalizationMethods += (3, 4)
        if normalizationSelections[2]: normalizationMethods += (5, 6)
        if normalizationSelections[3]: normalizationMethods.append(-1)
        if normalizationSelections[4]: normalizationMethods.append(0)

        # Determine what microsatellite stability states were requested.
        acceptableMSCohorts = dict()
        if selections.getToggleStates(dialogID)[7]:
            MSSelection = selections.getDropdownSelections(dialogID + "MS")[0]
            if MSSelection == "MSS": acceptableMSCohorts["MSS"] = None
            elif MSSelection == "MSI": acceptableMSCohorts["MSI"] = None
            else:
                acceptableMSCohorts["MSS"] = None
                acceptableMSCohorts["MSI"] = None

        # Determine what mutation signature states were requested.
        acceptableMutSigCohorts = dict()
        if selections.getToggleStates(dialogID)[8]:
            with open(
                    selections.getIndividualFilePaths(dialogID + "MutSig")[0],
                    'r') as mutSigsFile:
                for line in mutSigsFile:
                    acceptableMutSigCohorts["mut_sig_" + line.strip()] = None

        # Check for custom cohort input
        acceptableCustomCohorts = dict()
        if selections.getToggleStates(dialogID)[9]:

            customCohortsFilePath = selections.getIndividualFilePaths(
                dialogID + "CustomCohorts")[0]
            with open(customCohortsFilePath, 'r') as customCohortsFile:

                for line in customCohortsFile:
                    acceptableCustomCohorts[line.strip()] = None

        # Check for nucleosome map input
        acceptableNucleosomeMaps = dict()
        if selections.getToggleStates(dialogID)[10]:

            acceptableNucMapsFilePath = selections.getIndividualFilePaths(
                dialogID + "NucleosomeMaps")[0]
            with open(acceptableNucMapsFilePath, 'r') as acceptableNucMapsFile:

                for line in acceptableNucMapsFile:
                    acceptableNucleosomeMaps[line.strip()] = None

        # Get the file paths associated with the given parameters.
        if dialogID != "Secondary Group":
            filePathGroups[i] += getFilePathGroup(
                nucleosomeMutationCountsFilePaths, normalizationMethods,
                selections.getToggleStates(dialogID)[5],
                selections.getToggleStates(dialogID)[6], acceptableMSCohorts,
                acceptableMutSigCohorts, acceptableCustomCohorts,
                acceptableNucleosomeMaps)
        else:
            assert i == 1, "Secondary group encountered on unexpected iteration of for loop: " + str(
                i)
            filePathGroups[2] += getFilePathGroup(
                secondaryNucMutCountsFilePaths, normalizationMethods,
                selections.getToggleStates(dialogID)[5],
                selections.getToggleStates(dialogID)[6], acceptableMSCohorts,
                acceptableMutSigCohorts, acceptableCustomCohorts,
                acceptableNucleosomeMaps)
            filePathGroups[1] = filePathGroups[0].copy()
            filePathGroups[0] += filePathGroups[2]

        #If this is the first pass through the loop, set the file paths list to the newly filtered list.
        if i == 0: nucleosomeMutationCountsFilePaths = filePathGroups[0]

    runNucleosomeMutationAnalysis(filePathGroups[0], outputFilePath,
                                  overridePeakPeriodWithExpected, alignStrands,
                                  filePathGroups[1], filePathGroups[2])
Example #20
0
                    choppedUpLine[4] = "OTHER"

                    customBedOutputFile.write('\t'.join(choppedUpLine[:6]) +
                                              '\n')

    # Pass the generated files to the custom bed parser.
    parseCustomBed(customBedOutputFilePaths, genomeFilePath, False, False,
                   False, False)


if __name__ == "__main__":

    # Create the Tkinter UI
    dialog = TkinterDialog(workingDirectory=getDataDirectory())
    dialog.createMultipleFileSelector("Standard Bed Data:",
                                      0,
                                      "dipy.bed", ("Bed Files", ".bed"),
                                      additionalFileEndings=("TA.bed", ))
    dialog.createFileSelector("Genome Fasta File:", 1, ("Fasta Files", ".fa"))

    # Run the UI
    dialog.mainloop()

    # If no input was received (i.e. the UI was terminated prematurely), then quit!
    if dialog.selections is None: quit()

    # Get the user's input from the dialog.
    selections: Selections = dialog.selections
    standardBedFilePaths = list(selections.getFilePathGroups())[0]
    genomeFilePath = list(selections.getIndividualFilePaths())[0]

    parseStandardBed(standardBedFilePaths, genomeFilePath)