From 457d643477bad31adfca65dd48cff664e86560f4 Mon Sep 17 00:00:00 2001 From: eugenefischer <66030419+eugenefischer@users.noreply.github.com> Date: Fri, 30 Sep 2022 03:17:58 -0500 Subject: [PATCH] Make calculation of p-values optional, defaulting to off --- src/main/java/BiGpairSEQ.java | 5 +++++ src/main/java/CommandLineInterface.java | 12 ++++++++++-- src/main/java/InteractiveInterface.java | 8 +++++--- src/main/java/Simulator.java | 12 +++++++----- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/main/java/BiGpairSEQ.java b/src/main/java/BiGpairSEQ.java index cdde624..a4d6907 100644 --- a/src/main/java/BiGpairSEQ.java +++ b/src/main/java/BiGpairSEQ.java @@ -16,6 +16,7 @@ public class BiGpairSEQ { private static HeapType priorityQueueHeapType = HeapType.FIBONACCI; private static boolean outputBinary = true; private static boolean outputGraphML = false; + private static boolean calculatePValue = false; private static final String version = "version 4.1"; public static void main(String[] args) { @@ -173,5 +174,9 @@ public class BiGpairSEQ { public static boolean outputGraphML() {return outputGraphML;} public static void setOutputGraphML(boolean b) {outputGraphML = b;} + + public static boolean calculatePValue() {return calculatePValue; } + public static void setCalculatePValue(boolean b) {calculatePValue = b; } + public static String getVersion() { return version; } } diff --git a/src/main/java/CommandLineInterface.java b/src/main/java/CommandLineInterface.java index add4116..6d2dfb5 100644 --- a/src/main/java/CommandLineInterface.java +++ b/src/main/java/CommandLineInterface.java @@ -202,9 +202,12 @@ public class CommandLineInterface { else { maxOccupancyDiff = Integer.MAX_VALUE; } + if (line.hasOption("pv")) { + BiGpairSEQ.setCalculatePValue(true); + } GraphWithMapData graph = getGraph(graphFilename); MatchingResult result = Simulator.matchCDR3s(graph, graphFilename, minThreshold, maxThreshold, - maxOccupancyDiff, minOverlapPct, false); + maxOccupancyDiff, minOverlapPct, false, BiGpairSEQ.calculatePValue()); if(outputFilename != null){ MatchingFileWriter writer = new MatchingFileWriter(outputFilename, result); writer.writeResultsToFile(); @@ -479,12 +482,17 @@ public class CommandLineInterface { .argName("filename") .desc("(Optional) Name of output the output file. If not present, no file will be written.") .build(); + Option pValue = Option.builder("pv") //can't call the method this time, because this one's optional + .longOpt("p-value") + .desc("(Optional) Calculate p-values for sequence pairs.") + .build(); matchCDR3options.addOption(graphFilename) .addOption(minOccupancyOverlap) .addOption(maxOccupancyOverlap) .addOption(minOverlapPercent) .addOption(maxOccupancyDifference) - .addOption(outputFile); + .addOption(outputFile) + .addOption(pValue); //options for output to System.out Option printAlphaCount = Option.builder().longOpt("print-alphas") diff --git a/src/main/java/InteractiveInterface.java b/src/main/java/InteractiveInterface.java index 4c568c4..3849f13 100644 --- a/src/main/java/InteractiveInterface.java +++ b/src/main/java/InteractiveInterface.java @@ -422,7 +422,7 @@ public class InteractiveInterface { } //simulate matching MatchingResult results = Simulator.matchCDR3s(data, graphFilename, lowThreshold, highThreshold, maxOccupancyDiff, - minOverlapPercent, true); + minOverlapPercent, true, BiGpairSEQ.calculatePValue()); //write results to file assert filename != null; MatchingFileWriter writer = new MatchingFileWriter(filename, results); @@ -544,7 +544,8 @@ public class InteractiveInterface { System.out.println("3) Turn " + getOnOff(!BiGpairSEQ.cacheGraph()) + " graph/data file caching"); System.out.println("4) Turn " + getOnOff(!BiGpairSEQ.outputBinary()) + " serialized binary graph output"); System.out.println("5) Turn " + getOnOff(!BiGpairSEQ.outputGraphML()) + " GraphML graph output (for data portability to other programs)"); - System.out.println("6) Maximum weight matching algorithm options"); + System.out.println("6) Turn " + getOnOff(!BiGpairSEQ.calculatePValue()) + " calculation of p-values"); + System.out.println("7) Maximum weight matching algorithm options"); System.out.println("0) Return to main menu"); try { input = sc.nextInt(); @@ -554,7 +555,8 @@ public class InteractiveInterface { case 3 -> BiGpairSEQ.setCacheGraph(!BiGpairSEQ.cacheGraph()); case 4 -> BiGpairSEQ.setOutputBinary(!BiGpairSEQ.outputBinary()); case 5 -> BiGpairSEQ.setOutputGraphML(!BiGpairSEQ.outputGraphML()); - case 6 -> algorithmOptions(); + case 6 -> BiGpairSEQ.setCalculatePValue(!BiGpairSEQ.calculatePValue()); + case 7 -> algorithmOptions(); case 0 -> backToMain = true; default -> System.out.println("Invalid input"); } diff --git a/src/main/java/Simulator.java b/src/main/java/Simulator.java index 8a0702e..5e03b57 100644 --- a/src/main/java/Simulator.java +++ b/src/main/java/Simulator.java @@ -150,7 +150,7 @@ public class Simulator implements GraphModificationFunctions { //match CDR3s. public static MatchingResult matchCDR3s(GraphWithMapData data, String dataFilename, Integer lowThreshold, Integer highThreshold, Integer maxOccupancyDifference, - Integer minOverlapPercent, boolean verbose) { + Integer minOverlapPercent, boolean verbose, boolean calculatePValue) { Instant start = Instant.now(); SimpleWeightedGraph graph = data.getGraph(); Map removedEdges = new HashMap<>(); @@ -228,7 +228,7 @@ public class Simulator implements GraphModificationFunctions { header.add("Beta well count"); header.add("Overlap well count"); header.add("Matched correctly?"); - header.add("P-value"); + if(calculatePValue) { header.add("P-value"); } //Results for csv file List> allResults = new ArrayList<>(); @@ -265,10 +265,12 @@ public class Simulator implements GraphModificationFunctions { //overlap count result.add(Double.toString(graph.getEdgeWeight(e))); result.add(Boolean.toString(check)); - double pValue = Equations.pValue(numWells, source.getOccupancy(), + if (calculatePValue) { + double pValue = Equations.pValue(numWells, source.getOccupancy(), target.getOccupancy(), graph.getEdgeWeight(e)); - BigDecimal pValueTrunc = new BigDecimal(pValue, mc); - result.add(pValueTrunc.toString()); + BigDecimal pValueTrunc = new BigDecimal(pValue, mc); + result.add(pValueTrunc.toString()); + } allResults.add(result); }