List of usage examples for java.io PrintWriter printf
public PrintWriter printf(Locale l, String format, Object... args)
From source file:org.apache.sling.testing.tools.junit.RemoteLogDumper.java
@Override protected void failed(Throwable e, Description description) { final String baseUrl = getServerBaseUrl(); final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); if (baseUrl != null) { try {/*from www . j a v a2s . c om*/ warnIfNopMDCAdapterBeingUsed(); DefaultHttpClient httpClient = new DefaultHttpClient(); RequestExecutor executor = new RequestExecutor(httpClient); RequestBuilder rb = new RequestBuilder(baseUrl); Request r = rb.buildGetRequest(SERVLET_PATH, TEST_CLASS, description.getClassName(), TEST_NAME, description.getMethodName()); executor.execute(r); int statusCode = executor.getResponse().getStatusLine().getStatusCode(); String msg = e.getMessage(); if (msg != null) { pw.println(msg); } if (statusCode == 200) { pw.printf("=============== Logs from server [%s] for [%s]===================%n", baseUrl, description.getMethodName()); pw.print(executor.getContent()); pw.println("========================================================"); } else { pw.printf("Not able to fetch logs from [%s%s]. " + "TestLogServer probably not configured %n", baseUrl, SERVLET_PATH); } } catch (Throwable t) { System.err.printf("Error occurred while fetching test logs from server [%s] %n", baseUrl); t.printStackTrace(System.err); } System.err.print(sw.toString()); } }
From source file:com.redhat.rcm.version.Cli.java
private static void printKVLine(final String key, final String value, final String fmt, final int valMax, final PrintWriter pw) { final List<String> lines = new ArrayList<String>(); final BreakIterator iter = BreakIterator.getLineInstance(); iter.setText(value);//from w w w. j a v a 2 s . c o m int start = iter.first(); int end = BreakIterator.DONE; final StringBuilder currentLine = new StringBuilder(); String seg; while (start != BreakIterator.DONE && (end = iter.next()) != BreakIterator.DONE) { seg = value.substring(start, end); if (currentLine.length() + seg.length() > valMax) { lines.add(currentLine.toString()); currentLine.setLength(0); } currentLine.append(seg); start = end; } if (currentLine.length() > 0) { lines.add(currentLine.toString()); } pw.printf(fmt, key, lines.isEmpty() ? "" : lines.get(0)); if (lines.size() > 1) { for (int i = 1; i < lines.size(); i++) { // blank string to serve for indentation in format with two fields. pw.printf(fmt, "", lines.get(i)); } } }
From source file:nl.systemsgenetics.cellTypeSpecificAlleleSpecificExpression.NonPhasedEntry.java
public NonPhasedEntry(String asLocations, String phenoTypeLocation, String outputLocation) throws IOException, Exception { //This is the entry used for non-phased tests. //PART 1: read all individuals names from the files. ArrayList<String> allFiles = UtilityMethods.readFileIntoStringArrayList(asLocations); //PART 2: determine the per sample overdispersion in the file. ArrayList<BetaBinomOverdispInSample> dispersionParameters = new ArrayList<BetaBinomOverdispInSample>(); for (String sampleName : allFiles) { dispersionParameters.add(new BetaBinomOverdispInSample(sampleName)); }/*ww w .j a va 2 s . c o m*/ // use this to save the dispersionvalues String dispersionOutput = FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_dispersionFile.txt"; String binomialOutput = FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_BinomialResults.txt"; String betaBinomialOutput = FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_BetaBinomialResults.txt"; //for ease of use initializing here. String CTSbinomialOutput = FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_CTSBinomialResults.txt"; String CTSbetaBinomialOutput = FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_CTSBetaBinomialResults.txt"; PrintWriter writer = new PrintWriter(dispersionOutput, "UTF-8"); //header for dispersion writer.write("Filename\tdispersion"); double[] dispersionVals = new double[dispersionParameters.size()]; int i = 0; for (BetaBinomOverdispInSample sampleDispersion : dispersionParameters) { dispersionVals[i] = sampleDispersion.getOverdispersion()[0]; //do a check to make sure ordering is correct. if (!(sampleDispersion.getSampleName().equals(allFiles.get(i)))) { System.out.println(sampleDispersion.getSampleName()); throw new IllegalDataException("ERROR! ordering is not correct filenames for overdispersion"); } writer.printf("%s\t%.6f\n", sampleDispersion.getSampleName(), sampleDispersion.getOverdispersion()[0]); i++; } writer.close(); //This is only done when there is a correct location of the pheno file double[] cellProp = new double[] { -1.0 }; if (phenoTypeLocation != null) { ArrayList<String> phenoString = UtilityMethods.readFileIntoStringArrayList(phenoTypeLocation); /* Right now just assuming this is a file that is ordered in the same way as the asLocation file. With per line the cell proportion that we can determine. This is a requirement of the input! */ i = 0; cellProp = new double[phenoString.size()]; for (String samplePheno : phenoString) { cellProp[i] = Double.parseDouble(samplePheno); i++; } } //PART 4. Read the as files one line at a time. //Will create three types of PrintWriter binomWriter = new PrintWriter(binomialOutput, "UTF8"); PrintWriter betaBinomWriter = new PrintWriter(betaBinomialOutput, "UTF8"); //CTS stuff. PrintWriter CTSBinomWriter = null; PrintWriter CTSBetaBinomWriter = null; if (phenoTypeLocation != null) { CTSBinomWriter = new PrintWriter(CTSbinomialOutput, "UTF8"); CTSBetaBinomWriter = new PrintWriter(CTSbetaBinomialOutput, "UTF-8"); } //open all the files we want to open. ReadAsLinesIntoIndividualSNPdata asReader = new ReadAsLinesIntoIndividualSNPdata(asLocations); while (true) { //read some the next line from the files. ArrayList<IndividualSnpData> allSnpData; allSnpData = asReader.getIndividualsFromNextLine(); //BREAKPOINT OF THE LOOP. if (allSnpData.isEmpty()) break; // Add the dispersion data assuming the same ordering // Which was checked previously. for (int j = 0; j < dispersionVals.length; j++) { allSnpData.get(j).setDispersion(dispersionVals[j]); } // add the cellProp to the snp if (phenoTypeLocation != null) { for (int j = 0; j < cellProp.length; j++) { allSnpData.get(j).setCellTypeProp(cellProp[j]); } } ArrayList<IndividualSnpData> het_individuals; het_individuals = UtilityMethods.isolateHeterozygotesFromIndividualSnpData(allSnpData); int numberOfHets = het_individuals.size(); int totalOverlap = 0; //Data to determine If we're going to test: ArrayList<Integer> asRef = new ArrayList<Integer>(); ArrayList<Integer> asAlt = new ArrayList<Integer>(); ArrayList<Double> HetDisp = new ArrayList<Double>(); ArrayList<Double> HetCellProp = new ArrayList<Double>(); for (IndividualSnpData temp_het : het_individuals) { //Do nothing if there is no data in het_individuals asRef.add(temp_het.getRefNum()); asAlt.add(temp_het.getAltNum()); HetDisp.add(temp_het.getDispersion()); if (phenoTypeLocation != null) { HetCellProp.add(temp_het.getCellTypeProp()); } //this is used to check if we will continue with calculations. totalOverlap += temp_het.getRefNum() + temp_het.getAltNum(); } //Print the header for the tests. if ((totalOverlap >= GlobalVariables.minReads) && (numberOfHets >= GlobalVariables.minHets)) { if (GlobalVariables.verbosity >= 10) { System.out.println("\n--- STARTING AS TESTS FOR: ---"); System.out.println("SNP name: " + allSnpData.get(0).snpName); System.out.println("at: position " + allSnpData.get(0).chromosome + ":" + allSnpData.get(0).position + "\n"); System.out.println("Num of hets: " + Integer.toString(numberOfHets)); StringBuilder a = new StringBuilder(); for (Integer num : asRef) { a.append(String.format("% 7d ", num)); } System.out.println("asRef: " + a.toString()); a = new StringBuilder(); for (Integer num : asAlt) { a.append(String.format("% 7d ", num)); } System.out.println("asAlt: " + a.toString()); a = new StringBuilder(); for (Double num : HetDisp) { a.append(String.format("% 5.4f ", num)); } System.out.println("dispersion: " + a.toString()); if (phenoTypeLocation != null) { a = new StringBuilder(); for (Double num : HetCellProp) { a.append(String.format("% 5.4f ", num)); } System.out.println("cellProp: " + a.toString()); } } BinomialTest binomialResults = new BinomialTest(allSnpData); BetaBinomialTest betaBinomialResults = new BetaBinomialTest(allSnpData); if (binomialResults.isTestPerformed()) { binomWriter.println(binomialResults.writeTestStatistics(false)); betaBinomWriter.println(betaBinomialResults.writeTestStatistics(false)); GlobalVariables.numberOfTestPerformed++; } // do the CTS tests if data is available. if (phenoTypeLocation != null) { //do the CTS beta binomial test: CTSbinomialTest CTSbinomialResults = new CTSbinomialTest(allSnpData); CTSBetaBinomialTest CTSbetaBinomResults = new CTSBetaBinomialTest(allSnpData); // Write the results to the out_file, assuming both of them were done. if (CTSbetaBinomResults.isTestPerformed()) { CTSBinomWriter.println(CTSbinomialResults.writeTestStatistics(true)); CTSBetaBinomWriter.println(CTSbetaBinomResults.writeTestStatistics(true)); } } System.out.println("\n---- Finished SNP " + allSnpData.get(0).snpName); } } binomWriter.close(); betaBinomWriter.close(); if (phenoTypeLocation != null) { CTSBinomWriter.close(); CTSBetaBinomWriter.close(); } UtilityMethods.printFinalTestStats(); }
From source file:de.tudarmstadt.ukp.dkpro.core.io.conll.Conll2002Writer.java
private void convert(JCas aJCas, PrintWriter aOut) { Type neType = JCasUtil.getType(aJCas, NamedEntity.class); Feature neValue = neType.getFeatureByBaseName("value"); for (Sentence sentence : select(aJCas, Sentence.class)) { HashMap<Token, Row> ctokens = new LinkedHashMap<Token, Row>(); // Tokens List<Token> tokens = selectCovered(Token.class, sentence); // Chunks IobEncoder encoder = new IobEncoder(aJCas.getCas(), neType, neValue); for (int i = 0; i < tokens.size(); i++) { Row row = new Row(); row.id = i + 1;//from w w w .j a va 2s .c o m row.token = tokens.get(i); row.ne = encoder.encode(tokens.get(i)); ctokens.put(row.token, row); } // Write sentence in CONLL 2006 format for (Row row : ctokens.values()) { String chunk = UNUSED; if (writeNamedEntity && (row.ne != null)) { chunk = encoder.encode(row.token); } aOut.printf("%s %s\n", row.token.getCoveredText(), chunk); } aOut.println(); } }
From source file:net.solarnetwork.node.io.yasdi4j.YasdiMasterDeviceFactory.java
private void setupConfigIniFile() { Set<String> drivers = new LinkedHashSet<String>(2); List<YasdiMasterDeviceFactory> comDevices = new ArrayList<YasdiMasterDeviceFactory>(2); List<YasdiMasterDeviceFactory> ipDevices = new ArrayList<YasdiMasterDeviceFactory>(2); for (YasdiMasterDeviceFactory factory : FACTORIES.keySet()) { drivers.add(factory.driver);//from w w w . j a va 2 s . co m if ("libyasdi_drv_serial".equals(factory.driver)) { comDevices.add(factory); } else { ipDevices.add(factory); } } PrintWriter writer = null; try { if (INI_FILE == null) { String filePath = System.getProperty("sn.home", ""); if (filePath.length() > 0) { filePath += '/'; } filePath += "var/yasdi.ini"; INI_FILE = new File(filePath); INI_FILE.deleteOnExit(); } writer = new PrintWriter(new BufferedWriter(new FileWriter(INI_FILE)), false); } catch (IOException e) { throw new RuntimeException("Unable to create YASDI ini file", e); } log.debug("Generating YASDI configuration file {}", INI_FILE.getAbsolutePath()); int i = 0; try { writer.println("[DriverModules]"); for (String driver : drivers) { writer.printf("Driver%d=%s\n", i++, driver); } writer.println(); if (comDevices.size() > 0) { i = 1; for (YasdiMasterDeviceFactory factory : comDevices) { writer.printf("[COM%d]\n", i++); writer.printf("Device=%s\n", factory.device); writer.printf("Media=%s\n", factory.media); writer.printf("Baudrate=%d\n", factory.baud); writer.printf("Protocol=%s\n", factory.protocol); } writer.println(); } if (ipDevices.size() > 0) { i = 1; for (YasdiMasterDeviceFactory factory : ipDevices) { writer.printf("[IP%d]\n", i++); writer.printf("Device=%s\n", factory.device); writer.printf("Protocol=%s\n", factory.protocol); } writer.println(); } if (debugYasdi) { writer.println("[Misc]"); writer.println("DebugOutput=/dev/stderr"); } } finally { writer.flush(); writer.close(); } }
From source file:com.redhat.rcm.version.Cli.java
private static void printTextLine(final String line, final String indent, final int max, final PrintWriter pw) { final String fmt = "%s%-" + max + "s\n"; final List<String> lines = new ArrayList<String>(); final BreakIterator iter = BreakIterator.getLineInstance(); iter.setText(line);//from www. j a v a2s .c o m int start = iter.first(); int end = BreakIterator.DONE; final StringBuilder currentLine = new StringBuilder(); String seg; while (start != BreakIterator.DONE && (end = iter.next()) != BreakIterator.DONE) { seg = line.substring(start, end); if (currentLine.length() + seg.length() > max) { lines.add(currentLine.toString()); currentLine.setLength(0); } currentLine.append(seg); start = end; } if (currentLine.length() > 0) { lines.add(currentLine.toString()); } for (final String ln : lines) { pw.printf(fmt, indent, ln); } }
From source file:nl.systemsgenetics.cellTypeSpecificAlleleSpecificExpression.PhasedEntry.java
public PhasedEntry(String asLocations, String couplingLoc, String outputLocation, String cellPropLoc, String phasingLocation, String regionLocation) throws IOException, Exception { /**/*from w w w . ja v a 2 s.c om*/ * This method will perform a binomial test for some test region. * later additional features will be add. * * currently the flow of the program: * 1. read all SNPs from AS files and add overdispersion and cellprop to the files * 2. read phasing and assign alleles for these snps * 3. load test regions and determine test snps. * 5. determine log likelihood for test-snps. (with some deduplication) */ // 1. Read all SNPs from AS files ArrayList<String> allFiles = UtilityMethods.readFileIntoStringArrayList(asLocations); ReadAsLinesIntoIndividualSNPdata asReader = new ReadAsLinesIntoIndividualSNPdata(asLocations); HashMap<String, ArrayList<IndividualSnpData>> snpHashMap = new HashMap<String, ArrayList<IndividualSnpData>>(); HashMap<String, String> posNameMap = new HashMap<String, String>(); //first determine overdispersion values per SNP. ArrayList<BetaBinomOverdispInSample> dispersionParameters = new ArrayList<BetaBinomOverdispInSample>(); String dispersionOutput = FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_dispersionFile.txt"; PrintWriter dispersionWriter = new PrintWriter(dispersionOutput, "UTF-8"); dispersionWriter.write("Filename\tdispersion"); int i = 0; for (String asLoc : allFiles) { dispersionParameters.add(new BetaBinomOverdispInSample(asLoc)); dispersionWriter.printf("%s\t%.6f\n", dispersionParameters.get(i).getSampleName(), dispersionParameters.get(i).getOverdispersion()[0]); } dispersionWriter.close(); if (GlobalVariables.verbosity >= 10) { System.out.println("--------------------------------------------------"); System.out.println("Finished dispersion estimates for all individuals."); System.out.println("--------------------------------------------------"); } boolean hasCellProp = false; ArrayList<String> phenoString = new ArrayList<String>(); if (cellPropLoc != null) { hasCellProp = true; phenoString = UtilityMethods.readFileIntoStringArrayList(cellPropLoc); } //second reading of the ASfiles. while (true) { //read some stuff from the files. ArrayList<IndividualSnpData> tempSNPdata; tempSNPdata = asReader.getIndividualsFromNextLine(); if (tempSNPdata.isEmpty()) break; //I can safely assume all snps are the same per line, based on //checks done in the getIndividualsFromNextLine. String snpName = tempSNPdata.get(0).getSnpName(); String chr = tempSNPdata.get(0).getChromosome(); String posString = tempSNPdata.get(0).getPosition(); //add dispersionValues to the SNPs: for (int j = 0; j < tempSNPdata.size(); j++) { if (!tempSNPdata.get(j).getSampleName().equals(dispersionParameters.get(j).getSampleName())) { System.out.println(tempSNPdata.get(j).getSampleName()); System.out.println(dispersionParameters.get(j).getSampleName()); throw new IllegalDataException( "the name of the individual in the dispersion data is not the same as the individual name in the SNP"); } tempSNPdata.get(j).setDispersion(dispersionParameters.get(j).getOverdispersion()[0]); if (hasCellProp) { tempSNPdata.get(j).setCellTypeProp(Double.parseDouble(phenoString.get(j))); } } posNameMap.put(chr + ":" + posString, snpName); //take the SNP name and arraylist and put in the hashmap. snpHashMap.put(chr + ":" + posString, tempSNPdata); } if (GlobalVariables.verbosity >= 10) { System.out.println("all AS info Snps were read"); } // 2. Load test regions and determine the snps in the region. if (GlobalVariables.verbosity >= 10) { System.out.println("Starting the assignment of snps to regions."); } ArrayList<GenomicRegion> allRegions; allRegions = ReadGenomicRegions(regionLocation); // 3. Read phasing info for these snps Pair<HashMap<String, ArrayList<IndividualSnpData>>, ArrayList<GenomicRegion>> phasedPair; phasedPair = addPhasingToSNPHashMap(snpHashMap, couplingLoc, allRegions, phasingLocation); snpHashMap = phasedPair.getLeft(); allRegions = phasedPair.getRight(); phasedPair = null; if (GlobalVariables.verbosity >= 10) { System.out.println("Added phasing information to AS values of snps."); } /** * 4. Start testing, per region.: * * 4.1 Detemine the test snp in the region, this will be the reference value * 4.2 Determine the heterozygotes for the test snp. * 4.3 switch alt and ref values of the heterozygotes in the test region * respective of the test snp. add the new list to a binomial test. * 4.4 do the test in the BinomialTest.java and others in the future. * * */ //write output to these files. PrintWriter writerBinom = new PrintWriter(FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_Binomial_results.txt", "UTF-8"); PrintWriter writerBetaBinom = new PrintWriter(FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_BetaBinomial_results.txt", "UTF-8"); PrintWriter writerCTSBinom = new PrintWriter(FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_CellTypeSpecificBinomial_results.txt", "UTF-8"); PrintWriter writerCTSBetaBinom = new PrintWriter(FilenameUtils.getFullPath(outputLocation) + FilenameUtils.getBaseName(outputLocation) + "_CellTypeSpecificBetaBinomial_results.txt", "UTF-8"); for (GenomicRegion iRegion : allRegions) { System.out.println(iRegion.getAnnotation()); // I may want to change this into all test SNPS needs to be implemented still. // compared to all snps in the region. ArrayList<String> snpsInRegion = iRegion.getSnpInRegions(); ArrayList<IndividualSnpData> allHetsInRegion = new ArrayList<IndividualSnpData>(); //Don't want to do this in every iteration in the next loop. for (String regionSnp : snpsInRegion) { allHetsInRegion.addAll( UtilityMethods.isolateHeterozygotesFromIndividualSnpData(snpHashMap.get(regionSnp))); } HashSet<String> combinationsDone = new HashSet<String>(); HashMap<String, BinomialTest> storedBinomTests = new HashMap<String, BinomialTest>(); HashMap<String, BetaBinomialTest> storedBetaBinomTests = new HashMap<String, BetaBinomialTest>(); ///PLEASE NOTE, CELL TYPE SPECIFIC FUNCTIONALITY HAS NOT YET BEEN IMPLEMENTED. //Plan is to use this in the future but keeping them in HashMap<String, CTSbinomialTest> storedCTSBinomTests = new HashMap<String, CTSbinomialTest>(); HashMap<String, CTSBetaBinomialTest> storedCTSBetaBinomTests = new HashMap<String, CTSBetaBinomialTest>(); for (String testSnp : snpsInRegion) { ArrayList<IndividualSnpData> hetTestSnps = UtilityMethods .isolateHeterozygotesFromIndividualSnpData(snpHashMap.get(testSnp)); //Check if the snpp has phasing, but also see if there are heterozygous SNPs in the region. try { if (!hetTestSnps.get(0).hasPhasing()) { System.out.println("\tno phasing"); continue; } } catch (Exception e) { continue; } StringBuilder inputIdA = new StringBuilder(); StringBuilder inputIdB = new StringBuilder(); ArrayList<String> hetTestNames = new ArrayList<String>(); for (IndividualSnpData hetSample : hetTestSnps) { inputIdA.append(hetSample.sampleName); inputIdA.append(hetSample.getPhasingFirst()); inputIdB.append(hetSample.sampleName); inputIdB.append(hetSample.getPhasingSecond()); hetTestNames.add(hetSample.sampleName); } String refStringA = inputIdA.toString(); String refStringB = inputIdB.toString(); if (hetTestSnps.size() >= GlobalVariables.minHets) { //make sure I don't have to do two tests double. if (combinationsDone.contains(refStringA)) { BinomialTest binomForAddition = storedBinomTests.get(refStringA); BetaBinomialTest betaBinomForAddition = storedBetaBinomTests.get(refStringA); //there is duplication here to make sure it is stored under the correct name. if (binomForAddition == null) { binomForAddition = storedBinomTests.get(refStringB); binomForAddition.addAdditionalSNP(hetTestSnps.get(0).snpName, hetTestSnps.get(0).position); betaBinomForAddition = storedBetaBinomTests.get(refStringB); betaBinomForAddition.addAdditionalSNP(hetTestSnps.get(0).snpName, hetTestSnps.get(0).position); storedBinomTests.put(refStringB, binomForAddition); storedBetaBinomTests.put(refStringB, betaBinomForAddition); } else { binomForAddition.addAdditionalSNP(hetTestSnps.get(0).snpName, hetTestSnps.get(0).position); storedBinomTests.put(refStringA, binomForAddition); betaBinomForAddition.addAdditionalSNP(hetTestSnps.get(0).snpName, hetTestSnps.get(0).position); storedBetaBinomTests.put(refStringA, betaBinomForAddition); } continue; } ArrayList<IndividualSnpData> phasedSNPsForTest = new ArrayList<IndividualSnpData>(); Set<String> uniqueGeneSNPnames = new HashSet<String>(); // The following loop determines which SNPs will be used for // test data. for (int j = 0; j < allHetsInRegion.size(); j++) { IndividualSnpData thisHet = allHetsInRegion.get(j); int snpPos = Integer.parseInt(thisHet.position); //First check if the Heterozygote is in the test region if (snpPos < iRegion.getStartPosition() || snpPos > iRegion.getEndPosition()) { continue; } String sampleName = thisHet.sampleName; uniqueGeneSNPnames.add(thisHet.snpName); if (!hetTestNames.contains(thisHet.sampleName) || !thisHet.hasPhasing()) { continue; } //this is the heterozygote to compare to. IndividualSnpData hetToCompareTo = hetTestSnps.get(hetTestNames.indexOf(sampleName)); if (hetToCompareTo.getPhasingFirst() != thisHet.getPhasingFirst()) { // because it is a heterozygote, we can assume that // first is 0 and second is 1, or the other way around. // if the first in this snp doesn't match the // first in test, we will have to switch the ref, alt // alleles int temp = thisHet.refNum; thisHet.refNum = thisHet.altNum; thisHet.altNum = temp; } phasedSNPsForTest.add(thisHet); } if (GlobalVariables.verbosity >= 10) { System.out.println("\n----------------------------------------"); System.out.println("Testing Region: " + iRegion.getAnnotation()); System.out.println("With the following test SNP: " + hetTestSnps.get(0).snpName); System.out.println("Using the following gene SNPs: "); int whatSNP = 0; System.out.print("\t[ "); for (String snpName : uniqueGeneSNPnames) { System.out.print(snpName); if ((whatSNP % 4 == 3) && (whatSNP != uniqueGeneSNPnames.size() - 1)) { System.out.print(",\n\t "); } else if (whatSNP != uniqueGeneSNPnames.size() - 1) { System.out.print(", "); } whatSNP += 1; } System.out.println(" ]"); System.out.println("----------------------------------------\n"); } BinomialTest thisBinomTest; thisBinomTest = BinomialTest.phasedBinomialTest(phasedSNPsForTest, iRegion, hetTestSnps.size()); thisBinomTest.addAdditionalSNP(hetTestSnps.get(0).snpName, hetTestSnps.get(0).position); thisBinomTest.setGenotype(hetTestSnps.get(0).genotype); storedBinomTests.put(refStringA, thisBinomTest); BetaBinomialTest thisBetaBinomTest; thisBetaBinomTest = BetaBinomialTest.phasedBetaBinomialTest(phasedSNPsForTest, iRegion, hetTestSnps.size()); thisBetaBinomTest.addAdditionalSNP(hetTestSnps.get(0).snpName, hetTestSnps.get(0).position); thisBetaBinomTest.setGenotype(hetTestSnps.get(0).genotype); storedBetaBinomTests.put(refStringA, thisBetaBinomTest); //make sure we don't have to do the computationally intensive tests again. combinationsDone.add(refStringA); combinationsDone.add(refStringB); } } for (String thisTestName : storedBinomTests.keySet()) { BinomialTest thisBinomTest = storedBinomTests.get(thisTestName); BetaBinomialTest thisBetaBinomTest = storedBetaBinomTests.get(thisTestName); if (thisBinomTest.isTestPerformed()) { writerBinom.println(writeBinomialTestOutput(thisBinomTest)); writerBetaBinom.println(writeBetaBinomialTestOutput(thisBetaBinomTest)); } } } //close the files writerBinom.close(); writerBetaBinom.close(); writerCTSBinom.close(); writerCTSBetaBinom.close(); }
From source file:com.alexkli.osgi.troubleshoot.impl.TroubleshootServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final String action = WebConsoleUtil.getParameter(request, "action"); if ("startInactiveBundles".equals(action)) { startActionResponse(request, response); PrintWriter out = response.getWriter(); int bundlesTouched = 0; int bundlesActive = 0; final Bundle[] bundles = getBundleContext().getBundles(); for (Bundle bundle : bundles) { if (isFragmentBundle(bundle)) { continue; }/* w w w .ja va 2s . co m*/ if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.INSTALLED) { bundlesTouched++; try { out.printf("Trying to start %s (%s)... ", bundle.getSymbolicName(), getStatusString(bundle)); response.flushBuffer(); bundle.start(Bundle.START_TRANSIENT); bundlesActive += 1; out.printf("<span class='log-ok'>OK: %s.</span>", getStatusString(bundle)); } catch (BundleException e) { out.printf("<span class='ui-state-error-text'>Failed:</span> %s", e.getMessage()); } catch (IllegalStateException e) { out.printf("<span class='ui-state-error-text'>Failed, state changed:</span> %s", e.getMessage()); } catch (SecurityException e) { out.printf("<span class='ui-state-error-text'>Denied:</span> %s", e.getMessage()); } out.println("<br/>"); insertScrollScript(out); response.flushBuffer(); } } out.println("<br/>"); if (bundlesTouched == 0) { out.println("<span class='log-end'>No installed or resolved bundles found</span><br/>"); } else { out.printf("<span class='log-end'>Successfully started %s out of %s bundles.</span><br/>", bundlesActive, bundlesTouched); } insertScrollScript(out); endActionResponse(response); } }
From source file:org.jvnet.hudson.update_center.Main.java
/** * Build JSON for the plugin list.//from w w w . java2 s . co m * @param repository * @param redirect */ protected JSONObject buildPlugins(MavenRepository repository, PrintWriter redirect) throws Exception { ConfluencePluginList cpl = new ConfluencePluginList(); int total = 0; JSONObject plugins = new JSONObject(); for (PluginHistory hpi : repository.listHudsonPlugins()) { try { System.out.println(hpi.artifactId); Plugin plugin = new Plugin(hpi, cpl); if (plugin.isDeprecated()) { System.out.println("=> Plugin is deprecated.. skipping."); continue; } System.out.println(plugin.page != null ? "=> " + plugin.page.getTitle() : "** No wiki page found"); JSONObject json = plugin.toJSON(); System.out.println("=> " + json); plugins.put(plugin.artifactId, json); String permalink = String.format("/latest/%s.hpi", plugin.artifactId); redirect.printf("Redirect 302 %s %s\n", permalink, plugin.latest.getURL().getPath()); if (download != null) { for (HPI v : hpi.artifacts.values()) { stage(v, new File(download, "plugins/" + hpi.artifactId + "/" + v.version + "/" + hpi.artifactId + ".hpi")); } if (!hpi.artifacts.isEmpty()) createLatestSymlink(hpi, plugin.latest); } if (www != null) buildIndex(new File(www, "download/plugins/" + hpi.artifactId), hpi.artifactId, hpi.artifacts.values(), permalink); total++; } catch (IOException e) { e.printStackTrace(); // move on to the next plugin } } System.out.println("Total " + total + " plugins listed."); return plugins; }
From source file:pt.ist.fenixedu.contracts.tasks.giafsync.ImportProfessionalRelationsFromGiaf.java
@Override public void processChanges(GiafMetadata metadata, PrintWriter log, Logger logger) throws Exception { int updatedRelations = 0; int newRelations = 0; PersistentSuportGiaf oracleConnection = PersistentSuportGiaf.getInstance(); PreparedStatement preparedStatement = oracleConnection.prepareStatement(getQuery()); ResultSet result = preparedStatement.executeQuery(); while (result.next()) { String giafId = result.getString("tab_cod"); String nameString = result.getString("tab_cod_alg"); if (StringUtils.isEmpty(nameString)) { nameString = result.getString("tab_cod_dsc"); }/*w ww.ja v a 2 s . c o m*/ Boolean fullTimeEquivalent = getBoolean(result.getString("eti")); ProfessionalRelation professionalRelation = metadata.relation(giafId); MultiLanguageString name = new MultiLanguageString(MultiLanguageString.pt, nameString); if (professionalRelation != null) { if (!professionalRelation.getName().equalInAnyLanguage(name)) { professionalRelation.edit(name, fullTimeEquivalent); updatedRelations++; } } else { metadata.registerRelation(giafId, fullTimeEquivalent, name); newRelations++; } } result.close(); preparedStatement.close(); oracleConnection.closeConnection(); log.printf("Relations: %d updated, %d new\n", updatedRelations, newRelations); }