List of usage examples for org.apache.commons.io FilenameUtils getFullPath
public static String getFullPath(String filename)
From source file:nl.mpi.lamus.archive.implementation.LamusCorpusStructureBridgeTest.java
@Test public void getCorpusNamePathToClosestTopNode_TopNodeChild_Session() { final URI nodeArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String localPath = "/archive/root/TopNode/Metadata/session.cmdi"; final File localFile = new File(localPath); final URI parentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String parentLocalPath = "/archive/root/TopNode/Corpusstructure/topnode.cmdi"; final File parentLocalFile = new File(parentLocalPath); final String parentNodeName = "TopNode"; final URI grandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String grandParentLocalPath = "/archive/root/Corpusstructure/root.cmdi"; final File grandParentLocalFile = new File(grandParentLocalPath); final String expectedPath = "TopNode"; context.checking(new Expectations() { {/*from ww w .j av a 2s .c om*/ allowing(mockNode).getArchiveURI(); will(returnValue(nodeArchiveURI)); allowing(mockParentCorpusNode).getNodeURI(); will(returnValue(parentArchiveURI)); allowing(mockParentCorpusNode).getName(); will(returnValue(parentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(parentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(parentNodeName)); oneOf(mockCorpusStructureProvider).getNode(nodeArchiveURI); will(returnValue(mockCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockCorpusNode); will(returnValue(localFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(nodeArchiveURI); will(returnValue(parentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(parentArchiveURI); will(returnValue(mockParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockParentCorpusNode); will(returnValue(parentLocalFile)); oneOf(mockArchiveFileLocationProvider).getFolderNameBeforeCorpusstructure( FilenameUtils.getFullPath(parentLocalFile.getAbsolutePath())); will(returnValue(expectedPath)); oneOf(mockCorpusStructureProvider).getCanonicalParent(parentArchiveURI); will(returnValue(grandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(grandParentArchiveURI); will(returnValue(mockGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGrandParentCorpusNode); will(returnValue(grandParentLocalFile)); } }); String result = corpusStructureBridge.getCorpusNamePathToClosestTopNode(mockNode); assertEquals("Result different from expected", expectedPath, result); }
From source file:nl.mpi.lamus.archive.implementation.LamusCorpusStructureBridgeTest.java
@Test public void getCorpusNamePathToClosestTopNode_OtherDescendant_Session() { final URI nodeArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String localPath = "/archive/root/TopNode/OtherNode/Metadata/session.cmdi"; final File localFile = new File(localPath); final URI parentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String parentLocalPath = "/archive/root/TopNode/Corpusstructure/othernode.cmdi"; final File parentLocalFile = new File(parentLocalPath); final String parentNodeName = "OtherNode"; final URI grandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String grandParentLocalPath = "/archive/root/TopNode/Corpusstructure/topnode.cmdi"; final File grandParentLocalFile = new File(grandParentLocalPath); final String grandParentNodeName = "TopNode"; final URI greatGrandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String greatGrandParentLocalPath = "/archive/root/Corpusstructure/root.cmdi"; final File greatGrandParentLocalFile = new File(greatGrandParentLocalPath); final String expectedPath = "TopNode/OtherNode"; context.checking(new Expectations() { {/* w w w.ja v a 2s. c o m*/ allowing(mockNode).getArchiveURI(); will(returnValue(nodeArchiveURI)); allowing(mockParentCorpusNode).getNodeURI(); will(returnValue(parentArchiveURI)); allowing(mockParentCorpusNode).getName(); will(returnValue(parentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(parentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(parentNodeName)); allowing(mockGrandParentCorpusNode).getName(); will(returnValue(grandParentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(grandParentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(grandParentNodeName)); allowing(mockGrandParentCorpusNode).getNodeURI(); will(returnValue(grandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(nodeArchiveURI); will(returnValue(mockCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockCorpusNode); will(returnValue(localFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(nodeArchiveURI); will(returnValue(parentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(parentArchiveURI); will(returnValue(mockParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockParentCorpusNode); will(returnValue(parentLocalFile)); oneOf(mockArchiveFileLocationProvider).getFolderNameBeforeCorpusstructure( FilenameUtils.getFullPath(parentLocalFile.getAbsolutePath())); will(returnValue(grandParentNodeName)); oneOf(mockCorpusStructureProvider).getCanonicalParent(parentArchiveURI); will(returnValue(grandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(grandParentArchiveURI); will(returnValue(mockGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGrandParentCorpusNode); will(returnValue(grandParentLocalFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(grandParentArchiveURI); will(returnValue(greatGrandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(greatGrandParentArchiveURI); will(returnValue(mockGreatGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGreatGrandParentCorpusNode); will(returnValue(greatGrandParentLocalFile)); } }); String result = corpusStructureBridge.getCorpusNamePathToClosestTopNode(mockNode); assertEquals("Result different from expected", expectedPath, result); }
From source file:nl.mpi.lamus.archive.implementation.LamusCorpusStructureBridgeTest.java
@Test public void getCorpusNamePathToClosestTopNode_Resource() { final URI nodeArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String localPath = "/archive/root/TopNode/OtherNode/Media/stuff.jpg"; final File localFile = new File(localPath); final URI parentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String parentLocalPath = "/archive/root/TopNode/OtherNode/Metadata/session.cmdi"; final File parentLocalFile = new File(parentLocalPath); final URI grandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String grandParentLocalPath = "/archive/root/TopNode/Corpusstructure/othernode.cmdi"; final File grandParentLocalFile = new File(grandParentLocalPath); final String grandParentNodeName = "OtherNode"; final URI greatGrandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String greatGrandParentLocalPath = "/archive/root/TopNode/Corpusstructure/topnode.cmdi"; final File greatGrandParentLocalFile = new File(greatGrandParentLocalPath); final String greatGrandParentNodeName = "TopNode"; final URI greatestGrandParentArchiveURI = URI.create("hdl:11142/" + UUID.randomUUID().toString()); final String greatestGrandParentLocalPath = "/archive/root/Corpusstructure/root.cmdi"; final File greatestGrandParentLocalFile = new File(greatestGrandParentLocalPath); final String expectedPath = "TopNode/OtherNode"; context.checking(new Expectations() { {//from www .j a v a 2s. co m allowing(mockNode).getArchiveURI(); will(returnValue(nodeArchiveURI)); allowing(mockParentCorpusNode).getNodeURI(); will(returnValue(parentArchiveURI)); allowing(mockGrandParentCorpusNode).getNodeURI(); will(returnValue(grandParentArchiveURI)); allowing(mockGreatGrandParentCorpusNode).getNodeURI(); will(returnValue(greatGrandParentArchiveURI)); allowing(mockGrandParentCorpusNode).getName(); will(returnValue(grandParentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(grandParentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(grandParentNodeName)); allowing(mockGreatGrandParentCorpusNode).getName(); will(returnValue(greatGrandParentNodeName)); allowing(mockArchiveFileHelper).correctPathElement(greatGrandParentNodeName, "getCorpusNamePathToClosestTopNode"); will(returnValue(greatGrandParentNodeName)); oneOf(mockCorpusStructureProvider).getNode(nodeArchiveURI); will(returnValue(mockCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockCorpusNode); will(returnValue(localFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(nodeArchiveURI); will(returnValue(parentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(parentArchiveURI); will(returnValue(mockParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockParentCorpusNode); will(returnValue(parentLocalFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(parentArchiveURI); will(returnValue(grandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(grandParentArchiveURI); will(returnValue(mockGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGrandParentCorpusNode); will(returnValue(grandParentLocalFile)); oneOf(mockArchiveFileLocationProvider).getFolderNameBeforeCorpusstructure( FilenameUtils.getFullPath(grandParentLocalFile.getAbsolutePath())); will(returnValue(greatGrandParentNodeName)); oneOf(mockCorpusStructureProvider).getCanonicalParent(grandParentArchiveURI); will(returnValue(greatGrandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(greatGrandParentArchiveURI); will(returnValue(mockGreatGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGreatGrandParentCorpusNode); will(returnValue(greatGrandParentLocalFile)); oneOf(mockCorpusStructureProvider).getCanonicalParent(greatGrandParentArchiveURI); will(returnValue(greatestGrandParentArchiveURI)); oneOf(mockCorpusStructureProvider).getNode(greatestGrandParentArchiveURI); will(returnValue(mockGreatestGrandParentCorpusNode)); oneOf(mockNodeResolver).getLocalFile(mockGreatestGrandParentCorpusNode); will(returnValue(greatestGrandParentLocalFile)); } }); String result = corpusStructureBridge.getCorpusNamePathToClosestTopNode(mockNode); assertEquals("Result different from expected", expectedPath, result); }
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)); }/*from ww w . j a va2 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:nl.systemsgenetics.cellTypeSpecificAlleleSpecificExpression.PhasedEntry.java
public PhasedEntry(String asLocations, String couplingLoc, String outputLocation, String cellPropLoc, String phasingLocation, String regionLocation) throws IOException, Exception { /**//from ww w . java 2s .co m * 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:ome.services.blitz.impl.ScriptI.java
/** * Make the file, this is a temporary file which will be changed when the * script is validated./*from www . j a v a2 s . com*/ * * @param script * script. * @return OriginalFile tempfile.. * @throws ServerError */ private OriginalFile makeFile(final String path, final String script) throws ServerError { OriginalFile file = new OriginalFile(); file.setName(FilenameUtils.getName(path)); file.setPath(FilenameUtils.getFullPath(path)); file.setMimetype(ParamsHelper.PYTHONSCRIPT); file.setSize((long) script.getBytes().length); file.setSha1(Utils.bufferToSha1(script.getBytes())); return updateFile(file); }
From source file:ome.services.scripts.RepoFile.java
public String dirname() { return FilenameUtils.getFullPath(rel); }
From source file:org.abstracthorizon.proximity.storage.remote.CommonsNetFtpRemotePeer.java
/** * Construct item properties from get response. * //from w w w .j a v a2 s .c om * @param path the path * @param originatingUrlString the originating url string * @param remoteFile the remote file * * @return the item properties * * @throws MalformedURLException the malformed URL exception */ protected ItemProperties constructItemPropertiesFromGetResponse(String path, String originatingUrlString, FTPFile remoteFile) throws MalformedURLException { URL originatingUrl = new URL(originatingUrlString); ItemProperties result = new HashMapItemPropertiesImpl(); result.setDirectoryPath( FilenameUtils.separatorsToUnix(FilenameUtils.getPath(FilenameUtils.getFullPath(path)))); result.setDirectory(remoteFile.isDirectory()); result.setFile(remoteFile.isFile()); result.setLastModified(remoteFile.getTimestamp().getTime()); result.setName(FilenameUtils.getName(originatingUrl.getPath())); if (result.isFile()) { result.setSize(remoteFile.getSize()); } else { result.setSize(0); } result.setRemoteUrl(originatingUrl.toString()); return result; }
From source file:org.ado.musicdroid.service.MediaConverterService.java
@Override protected Task<File> createTask() { return new Task<File>() { private final List<String> albumCoverProcessedList = new ArrayList<>(); @Override/*from w ww . j a va 2s . c o m*/ protected File call() throws Exception { for (final File songFile : songFiles) { updateValue(songFile); copyAlbumCoverIfNeeded(songFile); jadbDevice.push(convertSong(songFile), new RemoteFile(getRemoteLocation(songFile))); } return null; } private void copyAlbumCoverIfNeeded(File songFile) throws JadbException, IOException { final String albumName = getAlbumRelativePath(songFile); if (!albumCoverProcessedList.contains(albumName)) { final InputStream inputStream = Mp3Utils.getAlbumCover(songFile); if (inputStream != null) { final File tempFile = File.createTempFile("cover", "image"); FileUtils.copyInputStreamToFile(inputStream, tempFile); jadbDevice.push(tempFile, new RemoteFile(getAlbumCoverRemoteLocation(songFile, MimeTypeMapping.getFileExtension(Mp3Utils.getAlbumCoverMimeType(songFile))))); } albumCoverProcessedList.add(albumName); } } private String getAlbumCoverRemoteLocation(File songFile, String fileExtension) { return ANDROID_MUSIC_BASE_DIRECTORY + getAlbumRelativePath(songFile) + "cover." + fileExtension; } private String getAlbumRelativePath(File songFile) { final String s = songFile.getAbsolutePath() .substring(AppConfiguration.getConfigurationProperty("music.dir").length()); return s.substring(0, s.lastIndexOf("/") + 1); } private File convertSong(final File songFile) throws Exception { final AVRootOptions options = AVRootOptions .create(songFile.getAbsolutePath(), getExportDirectory(songFile)) .builders(AVAudioOptions.create().audioBitRate(128)); final AVCommand command = new AVCommand().setDebug(true).setTimeout(10 * 60 * 60 * 1000L); LOGGER.info("Convert song [{}]", songFile.getAbsolutePath()); final ProcessInfo processInfo = command.run(options); final String outputFile = options.getOutputFile(); LOGGER.info("Output file: {}, return code: {}", outputFile, processInfo.getStatusCode()); if (processInfo.getStatusCode() != 0) { LOGGER.error(processInfo.toString()); } return new File(outputFile); } private String getExportDirectory(File songFile) { final File exportFile = new File(EXPORT_DIRECTORY, songFile.getAbsolutePath() .substring(AppConfiguration.getConfigurationProperty("music.dir").length())); final File exportDirectory = new File(FilenameUtils.getFullPath(exportFile.getAbsolutePath())); if (!exportDirectory.exists()) { try { FileUtils.forceMkdir(exportDirectory); } catch (IOException e) { // ignore } } return exportFile.getAbsolutePath(); } private String getRemoteLocation(File file) { return ANDROID_MUSIC_BASE_DIRECTORY + file.getAbsolutePath() .substring(AppConfiguration.getConfigurationProperty("music.dir").length()); } }; }
From source file:org.apache.flex.compiler.clients.ASC.java
/** * Compile one source file. Each source file has its own symbol table. * /*from w w w . java 2s . com*/ * @param workspace workspace * @param sourceFilename source filename * @throws InterruptedException compiler thread error * @return true compiled without problem */ private boolean compileSourceFiles(final Workspace workspace, final List<String> sourceFilenames) throws InterruptedException { boolean success = true; long startTime = System.nanoTime(); int problemCount = 0; // Set up a problem query object to check the result of the compilation. // Some problems found aren't ever relevant to ASC, and some depend on // the switches passed on the command line. problemQuery = new ProblemQuery(); problemQuery.setShowProblemByClass(MultipleExternallyVisibleDefinitionsProblem.class, false); problemQuery.setShowProblemByClass(UnfoundPropertyProblem.class, false); problemQuery.setShowStrictSemantics(useStaticSemantics()); problemQuery.setShowWarnings(getShowWarnings()); // process source AS3 files Set<ICompilationUnit> mainUnits = new LinkedHashSet<ICompilationUnit>(getSourceFilenames().size()); final HashMap<ICompilationUnit, Integer> unitOrdering = new HashMap<ICompilationUnit, Integer>(); ASCProject applicationProject = createProject(workspace, problemQuery); // Add any problems from parsing config vars supplied on the command line List<ICompilerProblem> configProblems = new ArrayList<ICompilerProblem>(); applicationProject.collectProblems(configProblems); problemQuery.addAll(configProblems); int i = 0; for (final String sourceFilename : sourceFilenames) { // If we are not merging then create a new project // and set the compilation units. if (i > 0 && !getMergeABCs()) { applicationProject = createProject(workspace, problemQuery); mainUnits.clear(); unitOrdering.clear(); problemQuery.clear(); } final IFileSpecification sourceFileSpec = new FileSpecification(sourceFilename); workspace.fileAdded(sourceFileSpec); final ICompilationUnit cu = ASCompilationUnit.createMainCompilationUnitForASC(applicationProject, sourceFileSpec, this); mainUnits.add(cu); unitOrdering.put(cu, unitOrdering.size()); // add compilation unit to project applicationProject.addCompilationUnit(cu); applicationProject.updatePublicAndInternalDefinitions(Collections.singletonList(cu)); // The logic that re-parses a garbage collected syntax tree, does not // know about the files included with the -in option, so we'll pin // the syntax tree here so we know we will never need to re-parse the // the synax tree for the root compilation unit. rootedSyntaxTrees.add(cu.getSyntaxTreeRequest().get().getAST()); // syntax errors for (final ICompilationUnit compilationUnit : applicationProject.getCompilationUnits()) { final ICompilerProblem[] problems = compilationUnit.getSyntaxTreeRequest().get().getProblems(); problemQuery.addAll(problems); } // Parse trees if (getShowParseTrees()) { final String outputSyntaxFilename = FilenameUtils.removeExtension(sourceFilename).concat(".p"); try { PrintWriter syntaxFile = new PrintWriter(outputSyntaxFilename); final IASNode ast = cu.getSyntaxTreeRequest().get().getAST(); if (ast instanceof FileNode) { // Parse the full tree and add the new problems found in the // function bodies into the problem collection. final FileNode fileNode = (FileNode) ast; final ImmutableSet<ICompilerProblem> skeletonProblems = ImmutableSet .copyOf(fileNode.getProblems()); fileNode.populateFunctionNodes(); final ImmutableSet<ICompilerProblem> allProblems = ImmutableSet .copyOf(fileNode.getProblems()); // Only add newly found problems. Otherwise, there will be // duplicates in "problemQuery". final SetView<ICompilerProblem> difference = Sets.difference(skeletonProblems, allProblems); problemQuery.addAll(difference); } syntaxFile.println(ast); syntaxFile.flush(); syntaxFile.close(); } catch (FileNotFoundException e) { problemQuery.add(new FileWriteProblem(e)); } } // output // For the merged case, wait until the last source file. // For the non-merged case, make each source file individually if (!getMergeABCs() || (getMergeABCs() && (i == sourceFilenames.size() - 1))) { // Let's start up all the compilation units to try and get more threads generating code // at the same time. for (final ICompilationUnit compilationUnit : applicationProject.getCompilationUnits()) { compilationUnit.startBuildAsync(TargetType.SWF); } // Run the resolveRefs() logic for as long as it's relevant. for (final ICompilationUnit compilationUnit : applicationProject.getCompilationUnits()) { final ICompilerProblem[] problems = compilationUnit.getOutgoingDependenciesRequest().get() .getProblems(); problemQuery.addAll(problems); } String outputFileBaseName = FilenameUtils.getBaseName(sourceFilename); String outputDirectoryName = FilenameUtils.getFullPath(sourceFilename); // Apply user specified basename and output directory. The // basename is only changed ABCs are merged since each abc // needs a unique filename. if (getMergeABCs() && getOutputBasename() != null) outputFileBaseName = getOutputBasename(); final String specifiedOutputDirectory = getOutputDirectory(); if (!Strings.isNullOrEmpty(specifiedOutputDirectory)) outputDirectoryName = normalizeDirectoryName(specifiedOutputDirectory); // Output to either a SWF or ABC file. if (isGenerateSWF()) { final boolean swfBuilt = generateSWF(outputDirectoryName, outputFileBaseName, applicationProject, mainUnits, sourceFilename, problemQuery, startTime); if (!swfBuilt) success = false; } else { Collection<ICompilationUnit> units = mainUnits; if (getMergeABCs()) { // Run the topological sort to figure out which order to output the ABCs in // Resorts to using commandline order rather than a filename based lexical sort in // cases where there are no real dependencies between the scripts units = applicationProject.getDependencyGraph().topologicalSort(mainUnits, new Comparator<ICompilationUnit>() { @Override public int compare(ICompilationUnit o1, ICompilationUnit o2) { return (unitOrdering.containsKey(o2) ? unitOrdering.get(o2) : 0) - (unitOrdering.containsKey(o1) ? unitOrdering.get(o1) : 0); } }); Collection<ICompilationUnit> sourceUnits = new ArrayList<ICompilationUnit>( mainUnits.size()); for (ICompilationUnit unit : units) { // The dependency graph will put all CompilationUnits in the results, but // we only want the CUs for the source files, since the imports should not be merged // into the resulting ABC if (mainUnits.contains(unit)) { sourceUnits.add(unit); } } units = sourceUnits; } final boolean abcBuilt = generateABCFile(outputDirectoryName, outputFileBaseName, applicationProject, units, sourceFilename, problemQuery, startTime); if (!abcBuilt) success = false; } //************************************* // Report problems. // // let's make a categorizer, so we can differentiate errors and warnings CompilerProblemCategorizer compilerProblemCategorizer = new CompilerProblemCategorizer(); problemFormatter = new WorkspaceProblemFormatter(workspace, compilerProblemCategorizer); ProblemPrinter printer = new ProblemPrinter(problemFormatter, err); problemCount += printer.printProblems(problemQuery.getFilteredProblems()); startTime = System.nanoTime(); } i++; } // If there were problems, print out the summary if (problemCount > 0) { Collection<ICompilerProblem> errors = new ArrayList<ICompilerProblem>(); Collection<ICompilerProblem> warnings = new ArrayList<ICompilerProblem>(); problemQuery.getErrorsAndWarnings(errors, warnings); int errorCount = errors.size(); int warningCount = warnings.size(); if (errorCount == 1) { err.println(); err.println("1 error found"); } else if (errorCount > 1) { err.println(); err.println(errorCount + " errors found"); } if (warningCount == 1) { err.println(); err.println("1 warning found"); } else if (warningCount > 1) { err.println(); err.println(warningCount + " warnings found"); } if (success && (errorCount > 0)) { success = false; } } return success; }