示例#1
0
def setworks(Arguments):
    '''
    Write a csv file of your setworks, plus a ton of potentially relevant stats. Suggested for viewing in MS excel (cross OS), 
    number (os x), or the freely available OpenOffice Calc program (cross OS).
    '''

    Barcodes, PValues, QValues, Performances, Interactions, \
        UnionFeatures, IntersectionFeatures, DifferenceFeatures, \
        FeatureVectors, SampleCounts, CaseCounts, EffectSizes, Report, Labels = load_setworks(Arguments)

    CSVfile = open(Arguments.Filename + ".csv", "wb")
    CSVwriter = csv.writer(CSVfile, dialect='excel')

    #Right the excel header
    CSVwriter.writerow(["Union","Intersection","Difference","Interaction","Phenotype","P-value",
                        "FDR",  "Odds Ratio", "Effect Size", "Sensitivity", "95% CI", "Specificity",
                        "95% CI", "PPV", "95% CI", "NPV", "95% CI", "Accuracy", "MCC", "Sample Count", "Case Count"])
    
    for Barcode in Barcodes:
        p = Performances[Barcode]
        Sens, Spec, PPV, NPV, Accuracy, MCC = p.sensitivity, p.specificity, p.PPV, p.NPV, p.accuracy, p.MCC
        CSVwriter.writerow([", ".join(UnionFeatures[Barcode]), ", ".join(IntersectionFeatures[Barcode]),
                            ", ".join(DifferenceFeatures[Barcode]), Interactions[Barcode], Report["Phenotype"],
                            "%0.2e" %PValues[Barcode], ["NA" if QValues[Barcode] == "NA" else "%0.2e" %QValues[Barcode]][0],
                            "%0.2f" %EffectSizes[Barcode].odds_ratio, "%0.2f" %EffectSizes[Barcode].difference_of_proportions,
                            "%0.2f" %Sens, "-".join(["%0.2f" %CI for CI in confidence_interval(Sens, SampleCounts[Barcode])]),
                            "%0.2f" %Spec, "-".join(["%0.2f" %CI for CI in confidence_interval(Spec, SampleCounts[Barcode])]),
                            "%0.2f" %PPV, "-".join(["%0.2f" %CI for CI in confidence_interval(PPV, SampleCounts[Barcode])]),
                            "%0.2f" %NPV, "-".join(["%0.2f" %CI for CI in confidence_interval(NPV, SampleCounts[Barcode])]),
                            "%0.2f" %Accuracy, "%0.2f" %MCC, SampleCounts[Barcode], CaseCounts[Barcode]])

    CSVfile.close()

    return
示例#2
0
def supervised(Results, Arguments):
    '''
    Write a csv file of your unsupervised pairwise interactions and a few related states. Suggested for viewing in 
    MS excel (cross OS), number (os x), or the freely available OpenOffice Calc program (cross OS).
    '''

    PValues, FDRs, Interactions, Performances, SampleCounts, CaseCounts, EffectSizes = load_pairwise_results(Results)

    Report = Results["Report"] #Need to get the phenotype name because this is 'supervised'
    Phenotype = Report["Supervised"][1].replace("(","").replace(")", "")

    CSVfile = open(Arguments.Filename + ".csv", "wb")
    CSVwriter = csv.writer(CSVfile, dialect='excel')
    
    #Right the excel header
    CSVwriter.writerow(["Feature", "Interaction", "Phenotype", "P-value", "FDR", "Odds Ratio", "Effect Size",
                        "Sensitivity", "95% CI", "Specificity", "95% CI", "PPV", "95% CI", "NPV", "95% CI",
                        "Accuracy", "MCC", "Sample Count", "Case Count"])
    
    #just sort by p-value
    for Feature in rank(Performances, Arguments.RankMethod, Arguments.TopInteractions):
        p = Performances[Feature]
        Sens, Spec, PPV, NPV, Accuracy, MCC = p.sensitivity, p.specificity, p.PPV, p.NPV, p.accuracy, p.MCC
        if minimum_performance(Performances[Feature], Arguments):
            CSVwriter.writerow([Feature, Interactions[Feature], Phenotype, "%0.2e" %PValues[Feature], "%0.2e" %FDRs[PValues[Feature]],
                                "%0.2f" %EffectSizes[Feature].odds_ratio, "%0.2f" %EffectSizes[Feature].difference_of_proportions,
                                "%0.2f" %Sens, "-".join(["%0.2f" %CI for CI in confidence_interval(Sens, SampleCounts[Feature])]),
                                "%0.2f" %Spec, "-".join(["%0.2f" %CI for CI in confidence_interval(Spec, SampleCounts[Feature])]),
                                "%0.2f" %PPV, "-".join(["%0.2f" %CI for CI in confidence_interval(PPV, SampleCounts[Feature])]),
                                "%0.2f" %NPV, "-".join(["%0.2f" %CI for CI in confidence_interval(NPV, SampleCounts[Feature])]),
                                "%0.2f" %Accuracy, "%0.2f" %MCC, SampleCounts[Feature], CaseCounts[Feature]])

    CSVfile.close()
    
    return 
示例#3
0
def supervised(Results, Arguments):
    '''
    Write a csv file of your unsupervised pairwise interactions and a few related states. Suggested for viewing in 
    MS excel (cross OS), number (os x), or the freely available OpenOffice Calc program (cross OS).
    '''

    PValues, FDRs, Interactions, Performances, SampleCounts, CaseCounts, EffectSizes = load_pairwise_results(
        Results)

    Report = Results[
        "Report"]  #Need to get the phenotype name because this is 'supervised'
    Phenotype = Report["Supervised"][1].replace("(", "").replace(")", "")

    CSVfile = open(Arguments.Filename + ".csv", "wb")
    CSVwriter = csv.writer(CSVfile, dialect='excel')

    #Right the excel header
    CSVwriter.writerow([
        "Feature", "Interaction", "Phenotype", "P-value", "FDR", "Odds Ratio",
        "Effect Size", "Sensitivity", "95% CI", "Specificity", "95% CI", "PPV",
        "95% CI", "NPV", "95% CI", "Accuracy", "MCC", "Sample Count",
        "Case Count"
    ])

    #just sort by p-value
    for Feature in rank(Performances, Arguments.RankMethod,
                        Arguments.TopInteractions):
        p = Performances[Feature]
        Sens, Spec, PPV, NPV, Accuracy, MCC = p.sensitivity, p.specificity, p.PPV, p.NPV, p.accuracy, p.MCC
        if minimum_performance(Performances[Feature], Arguments):
            CSVwriter.writerow([
                Feature, Interactions[Feature], Phenotype,
                "%0.2e" % PValues[Feature],
                "%0.2e" % FDRs[PValues[Feature]],
                "%0.2f" % EffectSizes[Feature].odds_ratio,
                "%0.2f" % EffectSizes[Feature].difference_of_proportions,
                "%0.2f" % Sens, "-".join([
                    "%0.2f" % CI
                    for CI in confidence_interval(Sens, SampleCounts[Feature])
                ]),
                "%0.2f" % Spec, "-".join([
                    "%0.2f" % CI
                    for CI in confidence_interval(Spec, SampleCounts[Feature])
                ]),
                "%0.2f" % PPV, "-".join([
                    "%0.2f" % CI
                    for CI in confidence_interval(PPV, SampleCounts[Feature])
                ]),
                "%0.2f" % NPV, "-".join([
                    "%0.2f" % CI
                    for CI in confidence_interval(NPV, SampleCounts[Feature])
                ]),
                "%0.2f" % Accuracy,
                "%0.2f" % MCC, SampleCounts[Feature], CaseCounts[Feature]
            ])

    CSVfile.close()

    return
示例#4
0
def setworks(Arguments):
    '''
    Write a csv file of your setworks, plus a ton of potentially relevant stats. Suggested for viewing in MS excel (cross OS), 
    number (os x), or the freely available OpenOffice Calc program (cross OS).
    '''

    Barcodes, PValues, QValues, Performances, Interactions, \
        UnionFeatures, IntersectionFeatures, DifferenceFeatures, \
        FeatureVectors, SampleCounts, CaseCounts, EffectSizes, Report, Labels = load_setworks(Arguments)

    CSVfile = open(Arguments.Filename + ".csv", "wb")
    CSVwriter = csv.writer(CSVfile, dialect='excel')

    #Right the excel header
    CSVwriter.writerow([
        "Union", "Intersection", "Difference", "Interaction", "Phenotype",
        "P-value", "FDR", "Odds Ratio", "Effect Size", "Sensitivity", "95% CI",
        "Specificity", "95% CI", "PPV", "95% CI", "NPV", "95% CI", "Accuracy",
        "MCC", "Sample Count", "Case Count"
    ])

    for Barcode in Barcodes:
        p = Performances[Barcode]
        Sens, Spec, PPV, NPV, Accuracy, MCC = p.sensitivity, p.specificity, p.PPV, p.NPV, p.accuracy, p.MCC
        CSVwriter.writerow([
            ", ".join(UnionFeatures[Barcode]),
            ", ".join(IntersectionFeatures[Barcode]),
            ", ".join(DifferenceFeatures[Barcode]), Interactions[Barcode],
            Report["Phenotype"],
            "%0.2e" % PValues[Barcode],
            ["NA" if QValues[Barcode] == "NA" else "%0.2e" % QValues[Barcode]
             ][0],
            "%0.2f" % EffectSizes[Barcode].odds_ratio,
            "%0.2f" % EffectSizes[Barcode].difference_of_proportions,
            "%0.2f" % Sens, "-".join([
                "%0.2f" % CI
                for CI in confidence_interval(Sens, SampleCounts[Barcode])
            ]),
            "%0.2f" % Spec, "-".join([
                "%0.2f" % CI
                for CI in confidence_interval(Spec, SampleCounts[Barcode])
            ]),
            "%0.2f" % PPV, "-".join([
                "%0.2f" % CI
                for CI in confidence_interval(PPV, SampleCounts[Barcode])
            ]),
            "%0.2f" % NPV, "-".join([
                "%0.2f" % CI
                for CI in confidence_interval(NPV, SampleCounts[Barcode])
            ]),
            "%0.2f" % Accuracy,
            "%0.2f" % MCC, SampleCounts[Barcode], CaseCounts[Barcode]
        ])

    CSVfile.close()

    return