List of usage examples for org.apache.commons.io FilenameUtils getFullPath
public static String getFullPath(String filename)
From source file:MSUmpire.DIA.TargetMatchScoring.java
public void MixtureModelingSemiSupervised() throws IOException { if (libTargetMatches.isEmpty() || Terminate) { return;//from w w w . ja v a 2 s . com } Logger.getRootLogger().info("Semi-parametric mixture modeling"); int IDNo = 0; int decoyNo = 0; int modelNo = 0; for (UmpireSpecLibMatch match : libIDMatches) { if (match.BestHit != null) { IDNo++; } } decoyNo = decoyModelingList.size(); for (UmpireSpecLibMatch match : libTargetMatches) { //modelNo+= match.TargetHits.size(); if (match.BestMS1Hit != null) { modelNo++; } if (match.BestMS2Hit != null) { modelNo++; } } double[] IDObs = new double[IDNo]; double[] DecoyObs = new double[decoyNo]; double[] ModelObs = new double[modelNo]; int idx = 0; int didx = 0; int midx = 0; for (UmpireSpecLibMatch match : libIDMatches) { if (match.BestHit != null) { IDObs[idx++] = match.BestHit.UmpireScore; } } for (PeakGroupScore peakGroupScore : decoyModelingList) { DecoyObs[didx++] = peakGroupScore.UmpireScore; } for (UmpireSpecLibMatch match : libTargetMatches) { if (match.BestMS1Hit != null) { ModelObs[midx++] = match.BestMS1Hit.UmpireScore; } if (match.BestMS2Hit != null) { ModelObs[midx++] = match.BestMS2Hit.UmpireScore; } } MixtureModelKDESemiParametric mixkde = new MixtureModelKDESemiParametric(); mixkde.NoBinPoints = NoBinPoints; mixkde.SetData(ModelObs, DecoyObs, IDObs); mixkde.Modeling(); mixkde.GeneratePlot(FilenameUtils.getFullPath(Filename) + "/" + FilenameUtils.getBaseName(Filename) + "_" + LibID + "_LibMatchModel.png"); MixtureModelProb = mixkde.MixtureModelProb; }
From source file:edu.cornell.med.icb.goby.modes.FastaToCompactMode.java
private void convert(final int loopIndex, final int length, final String inputFilename, final String outputFilename, Properties keyValueProps) throws IOException { System.out.printf("Converting [%d/%d] %s to %s%n", loopIndex + 1, length, inputFilename, outputFilename); // Create directory for output file if it doesn't already exist final String outputPath = FilenameUtils.getFullPath(outputFilename); if (StringUtils.isNotBlank(outputPath)) { FileUtils.forceMkdir(new File(outputPath)); }// ww w . j a v a2 s.c om final ReadsWriter writer = new ReadsWriterImpl( new FastBufferedOutputStream(new FileOutputStream(outputFilename))); if (codec != null) { writer.setCodec(codec); } try { writer.setNumEntriesPerChunk(sequencePerChunk); FastXReader pairReader = null; if (processPairs) { final String pairInputFilename = pairFilename(inputFilename); LOG.info(String.format("Located paired-end input files (%s,%s)", inputFilename, pairInputFilename)); pairReader = new FastXReader(pairInputFilename); } FastXEntry pairEntry = null; int entryIndex = 0; writer.setMetaData(keyValueProps); for (final FastXEntry entry : new FastXReader(inputFilename)) { if (pairReader != null) { pairEntry = pairReader.next(); if (pairEntry == null) { System.err.println("Cannot find matching sequence for " + entry.getEntryHeader()); } } if (includeDescriptions) { writer.setDescription(entry.getEntryHeader()); } if (includeIdentifiers) { final MutableString description = entry.getEntryHeader(); final String identifier = description.toString().split("[\\s]")[0]; writer.setIdentifier(identifier); } if (!excludeSequences) { writer.setSequence(entry.getSequence()); if (pairEntry != null) { writer.setPairSequence(pairEntry.getSequence()); } } else { writer.setSequence(""); } if (!excludeQuality) { writer.setQualityScores(convertQualityScores(qualityEncoding, entry.getQuality(), verboseQualityScores, apiMode)); if (pairEntry != null) { writer.setQualityScoresPair(convertQualityScores(qualityEncoding, pairEntry.getQuality(), verboseQualityScores, apiMode)); } } writer.appendEntry(); entryIndex++; } } finally { writer.close(); writer.printStats(System.out); } }
From source file:MSUmpire.PSMDataStructure.LCMSID.java
private void ExportPepFragmentCSV() throws IOException { Logger.getRootLogger().info("Writing PepFragment result to file:" + FilenameUtils.getFullPath(mzXMLFileName) + FilenameUtils.getBaseName(mzXMLFileName) + "_PepFragments.csv..."); FileWriter writer = new FileWriter(FilenameUtils.getFullPath(mzXMLFileName) + FilenameUtils.getBaseName(mzXMLFileName) + "_PepFragments.csv"); writer.write("PepIndex,IonType,fragMZ,ObservedMZ,Charge,Intensity,Correlation,PPM,ApexDelta,RTOverlapP\n"); for (PepIonID pepion : PepIonList.values()) { for (FragmentPeak frag : pepion.FragmentPeaks) { writer.write(pepion.Index + "," + frag.IonType + "," + frag.FragMZ + "," + frag.ObservedMZ + "," + frag.Charge + "," + frag.intensity + "," + frag.corr + "," + frag.ppm + "," + frag.ApexDelta + "," + frag.RTOverlapP + "\n"); }/* www . j a v a 2 s . c o m*/ } writer.close(); }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
private Array<File> getAtlasPages(FileHandle fileHandle) { Array<File> imgs = new Array<>(); try {//from w w w .j a va 2 s .c om BufferedReader reader = new BufferedReader(new InputStreamReader(fileHandle.read()), 64); while (true) { String line = reader.readLine(); if (line == null) break; if (line.trim().length() == 0) { line = reader.readLine(); imgs.add(new File(FilenameUtils.getFullPath(fileHandle.path()) + line)); } } } catch (IOException e) { e.printStackTrace(); } return imgs; }
From source file:it.drwolf.ridire.session.async.Mapper.java
private void moveResourceInAttic(CrawledResource cr, File f) throws IOException { File atticDir = new File( FilenameUtils.getFullPath(f.getCanonicalPath().replaceAll("__\\d+", "")) + Mapper.ATTICDIR); File resourceDir = new File(FilenameUtils.getFullPath(f.getCanonicalPath().replaceAll("__\\d+", "")) + JobMapperMonitor.RESOURCESDIR); File toBeMoved = new File(resourceDir, cr.getDigest() + ".gz"); FileUtils.moveFileToDirectory(toBeMoved, atticDir, true); toBeMoved = new File(resourceDir, cr.getDigest() + ".txt"); if (toBeMoved != null) { FileUtils.moveFileToDirectory(toBeMoved, atticDir, true); }/*from www. ja v a 2s.c o m*/ // System.out.println("Resource moved in attic: " + cr.getUrl()); }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
private boolean addParticleEffectImages(FileHandle fileHandle, Array<FileHandle> imgs) { try {//www . ja v a 2 s . c o m BufferedReader reader = new BufferedReader(new InputStreamReader(fileHandle.read()), 64); while (true) { String line = reader.readLine(); if (line == null) break; if (line.trim().equals("- Image Path -")) { line = reader.readLine(); if (line.contains("\\") || line.contains("/")) { // then it's a path let's see if exists. File tmp = new File(line); if (tmp.exists()) { imgs.add(new FileHandle(tmp)); } else { line = FilenameUtils.getBaseName(line) + ".png"; File file = new File(FilenameUtils.getFullPath(fileHandle.path()) + line); if (file.exists()) { imgs.add(new FileHandle(file)); } else { return false; } } } else { File file = new File(FilenameUtils.getFullPath(fileHandle.path()) + line); if (file.exists()) { imgs.add(new FileHandle(file)); } else { return false; } } } } } catch (IOException e) { e.printStackTrace(); } return true; }
From source file:it.drwolf.ridire.session.async.Mapper.java
private void removeResource(File f, String oldDigest, boolean attic, EntityManager entityManager) throws IOException { File resourceDir = null;//from w w w. j a v a 2 s . c om if (attic) { resourceDir = new File( FilenameUtils.getFullPath(f.getCanonicalPath().replaceAll("__\\d+", "")) + Mapper.ATTICDIR); } else { resourceDir = new File(FilenameUtils.getFullPath(f.getCanonicalPath().replaceAll("__\\d+", "")) + JobMapperMonitor.RESOURCESDIR); } String resourceFile = oldDigest + ".gz"; File toBeDeleted = new File(resourceDir, resourceFile); if (toBeDeleted.exists() && toBeDeleted.canWrite()) { toBeDeleted.delete(); } String txtResourceFile = oldDigest + ".txt"; toBeDeleted = new File(resourceDir, txtResourceFile); if (toBeDeleted.exists() && toBeDeleted.canWrite()) { toBeDeleted.delete(); } }
From source file:edu.cornell.med.icb.goby.modes.FastaToCompactMode.java
/** * Get the filename including path WITHOUT fastx extensions (including .gz if it is there). * * @param name the full path to the file in question * @return the full path to file without the fastx/gz extensions or the same name if * those extensions weren't found. * @see edu.cornell.med.icb.goby.util.FileExtensionHelper#FASTX_FILE_EXTS *///w w w .ja v a2 s.c om private static String stripFastxExtensions(final String name) { final String filename = FilenameUtils.getName(name); for (final String ext : FileExtensionHelper.FASTX_FILE_EXTS) { if (filename.endsWith(ext)) { return FilenameUtils.getFullPath(name) + filename.substring(0, filename.lastIndexOf(ext)); } } return name; }
From source file:com.impetus.ankush2.ganglia.GangliaDeployer.java
/** * installing and configuring Ganglia//w w w . j av a 2 s .c o m * * @param host * {@link String} * @return <code>true</code> , if successful */ private boolean createNode(String host) { boolean isGmetad = host.equals(gmetadHost); try { // Setting the start progress message for activity startup. String message = "Deploying " + getComponentName() + " on host : " + host; logger.info(message, getComponentName(), host); // getting connection SSHExec connection = getConnection(host); if (connection == null) { throw new AnkushException("Issue while connecting to node : " + host); } // Gmond conf folder directory String gmondConfFolderPath = FilenameUtils .getFullPath((String) advanceConf.get(GangliaConstants.ClusterProperties.GMOND_CONF_PATH)); // Gmetad conf folder directory String gmetadConfFolderPath = FilenameUtils .getFullPath((String) advanceConf.get(GangliaConstants.ClusterProperties.GMETAD_CONF_PATH)); if (gmondConfFolderPath == null || gmondConfFolderPath.isEmpty() || gmetadConfFolderPath == null || gmetadConfFolderPath.isEmpty()) { return addClusterError( getComponentName() + " configuration path provided from UI is either null or empty.", host); } // Make gmond conf directory if not exists AnkushTask mkGmondConfFolderPath = new MakeDirectory(gmondConfFolderPath); if (connection.exec(mkGmondConfFolderPath).rc != 0) { throw new AnkushException( "Could not create " + gmondConfFolderPath + " directory on $TYPE node " + host + "."); } // make gmetad conf directory on node AnkushTask mkGmetadConfFolderPath = new MakeDirectory(gmetadConfFolderPath); // if gmetad parent directory is different than the gmond parent // directory if (!mkGmondConfFolderPath.equals(mkGmetadConfFolderPath)) { if (connection.exec(mkGmetadConfFolderPath).rc != 0) { throw new AnkushException( "Could not create " + gmetadConfFolderPath + " directory on $TYPE node " + host + "."); } } // TODO: gmetad conf path creation if (!installGanglia(host, connection, isGmetad) || !createConfigurationFiles(host, connection, isGmetad) || !createRRDDirectories(host, connection, isGmetad) || !configureServiceMonitoring(host)) { return false; } // setting installed ganglia version in ganglia // conf. setInstalledGangliaVersion(host, isGmetad); return true; } catch (AnkushException e) { logger.warn(e.getMessage(), getComponentName(), host, e); return false; } catch (Exception e) { return addClusterError("There is some exception while installing " + getComponentName() + " on node: " + host + ". " + GangliaConstants.EXCEPTION_STRING, host, e); } }
From source file:MSUmpire.DIA.TargetMatchScoring.java
public void MixtureModeling() throws IOException { if (libTargetMatches.isEmpty()) { return;// w ww.j a v a 2 s.c o m } int IDNo = 0; int decoyNo = 0; int modelNo = 0; double IDmean = 0d; double Decoymean = 0d; for (UmpireSpecLibMatch match : libIDMatches) { if (match.BestHit != null) { IDNo++; IDmean += match.BestHit.UmpireScore; } } decoyNo = decoyModelingList.size(); for (PeakGroupScore peakGroupScore : decoyModelingList) { Decoymean += peakGroupScore.UmpireScore; } for (UmpireSpecLibMatch match : libTargetMatches) { //modelNo+= match.TargetHits.size(); if (match.BestMS1Hit != null) { modelNo++; } if (match.BestMS2Hit != null) { modelNo++; } } Decoymean /= decoyNo; IDmean /= IDNo; PVector[] points = new PVector[modelNo]; PVector[] centroids = new PVector[2]; int idx = 0; for (UmpireSpecLibMatch match : libTargetMatches) { if (match.BestMS1Hit != null) { points[idx] = new PVector(1); points[idx].array[0] = match.BestMS1Hit.UmpireScore; idx++; } if (match.BestMS2Hit != null) { points[idx] = new PVector(1); points[idx].array[0] = match.BestMS2Hit.UmpireScore; idx++; } // for(PeakGroupScore peakGroupScore : match.TargetHits){ // points[idx] = new PVector(1); // points[idx].array[0] = match.BestMS2Hit.UmpireScore; // idx++; // } } MixtureModel mmc; centroids[0] = new PVector(1); centroids[0].array[0] = Decoymean; centroids[1] = new PVector(1); centroids[1].array[0] = IDmean; Vector<PVector>[] clusters = KMeans.run(points, 2, centroids); MixtureModel mm = ExpectationMaximization1D.initialize(clusters); mmc = ExpectationMaximization1D.run(points, mm); DecimalFormat df = new DecimalFormat("#.####"); Logger.getRootLogger() .debug("----------------------------------------------------------------------------------------"); Logger.getRootLogger().debug("No. of modeling points=" + modelNo); Logger.getRootLogger().debug("ID hits mean=" + df.format(IDmean)); Logger.getRootLogger().debug("Decoy hits mean=" + df.format(Decoymean)); //System.out.print("T-test: p-value=" + df.format(model.ttest.pValue).toString() + "\n"); Logger.getRootLogger() .debug("Incorrect hits model mean=" + df.format(((PVector) mmc.param[0]).array[0]) + " variance=" + df.format(((PVector) mmc.param[0]).array[1]) + " weight=" + df.format(mmc.weight[0])); Logger.getRootLogger() .debug("Correct hits model mean=" + df.format(((PVector) mmc.param[1]).array[0]) + " variance=" + df.format(((PVector) mmc.param[1]).array[1]) + " weight=" + df.format(mmc.weight[1])); if (((PVector) mmc.param[0]).array[0] > ((PVector) mmc.param[1]).array[0]) { return; } float max = (float) (((PVector) mmc.param[1]).array[0] + 4 * Math.sqrt(((PVector) mmc.param[1]).array[1])); float min = (float) (((PVector) mmc.param[0]).array[0] - 4 * Math.sqrt(((PVector) mmc.param[0]).array[1])); IDNo = 0; decoyNo = 0; modelNo = 0; for (PeakGroupScore peakGroupScore : decoyModelingList) { if (peakGroupScore.UmpireScore > min && peakGroupScore.UmpireScore < max) { decoyNo++; } } for (UmpireSpecLibMatch match : libIDMatches) { if (match.BestHit != null && match.BestHit.UmpireScore > min && match.BestHit.UmpireScore < max) { IDNo++; } } for (UmpireSpecLibMatch match : libTargetMatches) { //targetNo += match.TargetHits.size(); //decoyNo += match.DecoyHits.size(); if (match.BestMS1Hit != null && match.BestMS1Hit.UmpireScore > min && match.BestMS1Hit.UmpireScore < max) { modelNo++; } if (match.BestMS2Hit != null && match.BestMS2Hit.UmpireScore > min && match.BestMS2Hit.UmpireScore < max) { modelNo++; } //modelNo += match.TargetHits.size(); } double[] IDObs = new double[IDNo]; double[] DecoyObs = new double[decoyNo]; double[] ModelObs = new double[modelNo]; idx = 0; int didx = 0; int midx = 0; for (UmpireSpecLibMatch match : libIDMatches) { if (match.BestHit != null && match.BestHit.UmpireScore > min && match.BestHit.UmpireScore < max) { IDObs[idx++] = match.BestHit.UmpireScore; } } for (PeakGroupScore peakGroupScore : decoyModelingList) { if (peakGroupScore.UmpireScore > min && peakGroupScore.UmpireScore < max) { DecoyObs[didx++] = peakGroupScore.UmpireScore; } } for (UmpireSpecLibMatch match : libTargetMatches) { // for(PeakGroupScore peak : match.TargetHits){ // ModelObs[midx++]=peak.UmpireScore; // } if (match.BestMS1Hit != null && match.BestMS1Hit.UmpireScore > min && match.BestMS1Hit.UmpireScore < max) { ModelObs[midx++] = match.BestMS1Hit.UmpireScore; } if (match.BestMS2Hit != null && match.BestMS2Hit.UmpireScore > min && match.BestMS2Hit.UmpireScore < max) { ModelObs[midx++] = match.BestMS2Hit.UmpireScore; } } String pngfile = FilenameUtils.getFullPath(Filename) + "/" + FilenameUtils.getBaseName(Filename) + "_" + LibID + "_LibMatchModel.png"; XYSeries model1 = new XYSeries("Incorrect matches"); XYSeries model2 = new XYSeries("Correct matches"); XYSeries model3 = new XYSeries("All target hits"); String modelfile = FilenameUtils.getFullPath(pngfile) + "/" + FilenameUtils.getBaseName(pngfile) + "_ModelPoints.txt"; FileWriter writer = new FileWriter(modelfile); writer.write("UScore\tModel\tCorrect\tDecoy\n"); int NoPoints = 1000; double[] model_kde_x = new double[NoPoints]; float intv = (max - min) / NoPoints; PVector point = new PVector(2); for (int i = 0; i < NoPoints; i++) { point.array[0] = max - i * intv; model_kde_x[i] = point.array[0]; point.array[1] = mmc.EF.density(point, mmc.param[0]) * mmc.weight[0]; model1.add(point.array[0], point.array[1]); point.array[1] = mmc.EF.density(point, mmc.param[1]) * mmc.weight[1]; model2.add(point.array[0], point.array[1]); } KernelDensityEstimator kde = new KernelDensityEstimator(); kde.SetData(ModelObs); double[] model_kde_y = kde.Density(model_kde_x); for (int i = 0; i < NoPoints; i++) { if (model_kde_x[i] > min && model_kde_x[i] < max) { point.array[0] = max - i * intv; model_kde_x[i] = point.array[0]; model3.add(model_kde_x[i], model_kde_y[i]); writer.write(point.array[0] + "\t" + mmc.EF.density(point, mmc.param[0]) * mmc.weight[0] + "\t" + mmc.EF.density(point, mmc.param[1]) * mmc.weight[1] + "\t" + model_kde_y[i] + "\n"); } } writer.close(); MixtureModelProb = new float[NoPoints + 1][3]; float positiveaccu = 0f; float negativeaccu = 0f; MixtureModelProb[0][0] = (float) model2.getMaxX() + Float.MIN_VALUE; MixtureModelProb[0][1] = 1f; MixtureModelProb[0][2] = 1f; for (int i = 1; i < NoPoints + 1; i++) { float positiveNumber = model2.getY(NoPoints - i).floatValue(); float negativeNumber = model1.getY(NoPoints - i).floatValue(); MixtureModelProb[i][0] = model2.getX(NoPoints - i).floatValue(); positiveaccu += positiveNumber; negativeaccu += negativeNumber; MixtureModelProb[i][2] = positiveNumber / (negativeNumber + positiveNumber); MixtureModelProb[i][1] = positiveaccu / (negativeaccu + positiveaccu); } XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(model1); dataset.addSeries(model2); dataset.addSeries(model3); HistogramDataset histogramDataset = new HistogramDataset(); histogramDataset.setType(HistogramType.SCALE_AREA_TO_1); histogramDataset.addSeries("ID hits", IDObs, 100); histogramDataset.addSeries("Decoy hits", DecoyObs, 100); //histogramDataset.addSeries("Model hits", ModelObs, 100); JFreeChart chart = ChartFactory.createHistogram(FilenameUtils.getBaseName(pngfile), "Score", "Hits", histogramDataset, PlotOrientation.VERTICAL, true, false, false); XYPlot plot = chart.getXYPlot(); NumberAxis domain = (NumberAxis) plot.getDomainAxis(); domain.setRange(min, max); plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setForegroundAlpha(0.8f); chart.setBackgroundPaint(Color.white); XYLineAndShapeRenderer render = new XYLineAndShapeRenderer(); // render.setSeriesPaint(0, Color.DARK_GRAY); // render.setSeriesPaint(1, Color.DARK_GRAY); // render.setSeriesPaint(2, Color.GREEN); // render.setSeriesShape(0, new Ellipse2D.Double(0, 0, 2, 2)); // render.setSeriesShape(1, new Ellipse2D.Double(0, 0, 2, 2)); // render.setSeriesShape(2, new Ellipse2D.Double(0, 0, 2.5f, 2.5f)); // render.setSeriesStroke(1, new BasicStroke(1.0f)); // render.setSeriesStroke(0, new BasicStroke(1.0f)); // render.setSeriesStroke(2, new BasicStroke(2.0f)); plot.setDataset(1, dataset); plot.setRenderer(1, render); plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD); try { ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600); } catch (IOException e) { } }