List of usage examples for java.lang Float isNaN
public static boolean isNaN(float v)
From source file:nl.umcg.westrah.binarymetaanalyzer.BinaryMetaAnalysis.java
private void writeBuffer(String outdir, int permutation) throws IOException { // sort the finalbuffer for a last time if (locationToStoreResult != 0) { Arrays.parallelSort(finalEQTLs, 0, locationToStoreResult); }//from ww w. j av a2s .co m String outfilename = outdir + "eQTLs.txt.gz"; FileFormat outformat = FileFormat.LARGE; if (permutation > 0) { outfilename = outdir + "PermutedEQTLsPermutationRound" + permutation + ".txt.gz"; if (!fullpermutationoutput) { outformat = FileFormat.REDUCED; } } String tab = "\t"; String newline = "\n"; TextFile output = new TextFile(outfilename, TextFile.W, 10 * 1048576); String header = "PValue\t" + "SNPName\t" + "SNPChr\t" + "SNPChrPos\t" + "ProbeName\t" + "ProbeChr\t" + "ProbeCenterChrPos\t" + "CisTrans\t" + "SNPType\t" + "AlleleAssessed\t" + "OverallZScore\t" + "DatasetsWhereSNPProbePairIsAvailableAndPassesQC\t" + "DatasetsZScores\t" + "DatasetsNrSamples\t" + "IncludedDatasetsMeanProbeExpression\t" + "IncludedDatasetsProbeExpressionVariance\t" + "HGNCName\t" + "IncludedDatasetsCorrelationCoefficient\t" + "Meta-Beta (SE)\t" + "Beta (SE)\t" + "FoldChange"; if (outformat.equals(FileFormat.REDUCED)) { header = "PValue\tSNP\tProbe\tGene\tAlleles\tAlleleAssessed\tZScore"; } output.writeln(header); // PValue SNPName SNPChr SNPChrPos ProbeName ProbeChr ProbeCenterChrPos CisTrans SNPType AlleleAssessed OverallZScore DatasetsWhereSNPProbePairIsAvailableAndPassesQC DatasetsZScores DatasetsNrSamples IncludedDatasetsMeanProbeExpression IncludedDatasetsProbeExpressionVariance HGNCName IncludedDatasetsCorrelationCoefficient Meta-Beta (SE) Beta (SE) FoldChange FDR DecimalFormat dformat = new DecimalFormat("###.####", new DecimalFormatSymbols(Locale.US)); DecimalFormat pformat = new DecimalFormat("###.########", new DecimalFormatSymbols(Locale.US)); DecimalFormat smallpFormat = new DecimalFormat("0.####E0", new DecimalFormatSymbols(Locale.US)); int ctr = 0; for (int i = 0; i < settings.getFinalEQTLBufferMaxLength(); i++) { if (finalEQTLs[i] != null) { ctr++; } } int totalctr = 0; for (int i = 0; i < finalEQTLs.length; i++) { if (finalEQTLs[i] != null) { totalctr++; } } System.out.println("There are " + ctr + " results in the buffer to write. " + totalctr + " QTLs are in memory at the moment."); ProgressBar pb = new ProgressBar(ctr, "Writing: " + outfilename); String cistr = "Cis"; String transtr = "Trans"; String greyz = "Greyzone"; for (int i = 0; i < settings.getFinalEQTLBufferMaxLength(); i++) { QTL q = finalEQTLs[i]; if (q != null) { // StringBuilder sb = new StringBuilder(4096); if (outformat.equals(FileFormat.LARGE)) { if (q.getPvalue() < 1E-4) { output.append(smallpFormat.format(q.getPvalue())); } else { output.append(pformat.format(q.getPvalue())); } output.append(tab); int snpId = q.getSNPId(); output.append(snpList[snpId]); output.append(tab); output.append(snpChr[snpId]); output.append(tab); output.append("" + snpPositions[snpId]); output.append(tab); MetaQTL4MetaTrait t = q.getMetaTrait(); output.append(t.getMetaTraitName()); output.append(tab); output.append(t.getChr()); output.append(tab); output.append("" + t.getChrMidpoint()); output.append(tab); int dist = Math.abs(t.getChrMidpoint() - snpPositions[snpId]); boolean sameChr = t.getChr().equals(snpChr[snpId]); if (sameChr && dist < settings.getCisdistance()) { output.append(cistr); } else if (sameChr && dist < settings.getTransdistance()) { output.append(greyz); } else { output.append(transtr); } output.append(tab); output.append(q.getAlleles()); output.append(tab); output.append(q.getAlleleAssessed()); output.append(tab); output.append(dformat.format(q.getZscore())); float[] datasetZScores = q.getDatasetZScores(); String[] dsBuilder = new String[datasets.length]; String[] dsNBuilder = new String[datasets.length]; String[] dsZBuilder = new String[datasets.length]; for (int d = 0; d < datasetZScores.length; d++) { if (!Float.isNaN(datasetZScores[d])) { String str = dformat.format(datasetZScores[d]); dsBuilder[d] = settings.getDatasetnames().get(d); dsNBuilder[d] = "" + q.getDatasetSampleSizes()[d]; dsZBuilder[d] = str; } else { dsBuilder[d] = "-"; dsNBuilder[d] = "-"; dsZBuilder[d] = "-"; } } output.append(tab); output.append(Strings.concat(dsBuilder, Strings.semicolon)); output.append(tab); output.append(Strings.concat(dsZBuilder, Strings.semicolon)); output.append(tab); output.append(Strings.concat(dsNBuilder, Strings.semicolon)); output.append("\t-\t-\t"); output.append(t.getAnnotation()); output.append("\t-\t-\t-\t-"); output.append(newline); } else { // header = "PValue\tSNP\tProbe\tGene\tAlleles\tAlleleAssessed\tZScore"; int snpId = q.getSNPId(); MetaQTL4MetaTrait t = q.getMetaTrait(); if (q.getPvalue() < 1E-4) { output.append(smallpFormat.format(q.getPvalue())); } else { output.append(pformat.format(q.getPvalue())); } output.append(tab); output.append(snpList[snpId]); output.append(tab); output.append(t.getMetaTraitName()); output.append(tab); output.append(t.getAnnotation()); output.append(tab); output.append(q.getAlleles()); output.append(tab); output.append(q.getAlleleAssessed()); output.append(tab); output.append(dformat.format(q.getZscore())); output.append(newline); } pb.iterate(); } finalEQTLs[i] = null; // trash it immediately } pb.close(); output.close(); finalEQTLs = null; // ditch the whole resultset if (usetmp) { String filename = "eQTLs.txt.gz"; if (permutation > 0) { filename = "PermutedEQTLsPermutationRound" + permutation + ".txt.gz"; } File source = new File(tempDir + filename); File dest = new File(settings.getOutput() + filename); if (dest.exists()) { System.out.println("Destination file: " + dest.getAbsolutePath() + " exists already.. Deleting!"); dest.delete(); } System.out.println("Moving file: " + tempDir + filename + " --> " + settings.getOutput() + filename); FileUtils.moveFile(source, dest); } System.out.println("Done."); }
From source file:org.eclipse.dataset.Stats.java
/** * @param a//from w w w . j a v a 2s . co m * @param ignoreNaNs if true, skip NaNs * @param axis * @return cumulative product of items along axis in dataset */ public static Dataset cumulativeProduct(final Dataset a, boolean ignoreNaNs, int axis) { axis = a.checkAxis(axis); int dtype = a.getDtype(); int[] oshape = a.getShape(); int alen = oshape[axis]; oshape[axis] = 1; Dataset result = DatasetFactory.zeros(a); PositionIterator pi = result.getPositionIterator(axis); int[] pos = pi.getPos(); while (pi.hasNext()) { if (a.isComplex()) { double rv = 1, iv = 0; switch (dtype) { case Dataset.COMPLEX64: ComplexFloatDataset af = (ComplexFloatDataset) a; if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final float r1 = af.getReal(pos); final float i1 = af.getImag(pos); if (Float.isNaN(r1) || Float.isNaN(i1)) continue; final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; af.set((float) rv, (float) iv, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; final float r1 = af.getReal(pos); final float i1 = af.getImag(pos); final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; af.set((float) rv, (float) iv, pos); } } break; case Dataset.COMPLEX128: ComplexDoubleDataset ad = (ComplexDoubleDataset) a; if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final double r1 = ad.getReal(pos); final double i1 = ad.getImag(pos); if (Double.isNaN(r1) || Double.isNaN(i1)) continue; final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; ad.set(rv, iv, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; final double r1 = ad.getReal(pos); final double i1 = ad.getImag(pos); final double tv = r1 * rv - i1 * iv; iv = r1 * iv + i1 * rv; rv = tv; ad.set(rv, iv, pos); } } break; } result.set(new Complex(rv, iv), pos); } else { final int is; final long[] lresults; final double[] dresults; switch (dtype) { case Dataset.BOOL: case Dataset.INT8: case Dataset.INT16: case Dataset.INT32: case Dataset.INT64: long lresult = 1; for (int j = 0; j < alen; j++) { pos[axis] = j; lresult *= a.getInt(pos); result.set(lresult, pos); } break; case Dataset.ARRAYINT8: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final byte[] va = (byte[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT16: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final short[] va = (short[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT32: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final int[] va = (int[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.ARRAYINT64: is = a.getElementsPerItem(); lresults = new long[is]; for (int k = 0; k < is; k++) { lresults[k] = 1; } for (int j = 0; j < alen; j++) { pos[axis] = j; final long[] va = (long[]) a.getObject(pos); for (int k = 0; k < is; k++) { lresults[k] *= va[k]; } result.set(lresults, pos); } break; case Dataset.FLOAT32: case Dataset.FLOAT64: double dresult = 1.; if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final double x = a.getDouble(pos); if (Double.isNaN(x)) continue; dresult *= x; result.set(dresult, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; dresult *= a.getDouble(pos); result.set(dresult, pos); } } break; case Dataset.ARRAYFLOAT32: is = a.getElementsPerItem(); dresults = new double[is]; for (int k = 0; k < is; k++) { dresults[k] = 1.; } if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final float[] va = (float[]) a.getObject(pos); boolean skip = false; for (int k = 0; k < is; k++) { if (Float.isNaN(va[k])) { skip = true; break; } } if (!skip) for (int k = 0; k < is; k++) { dresults[k] *= va[k]; } result.set(dresults, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; final float[] va = (float[]) a.getObject(pos); for (int k = 0; k < is; k++) { dresults[k] *= va[k]; } result.set(dresults, pos); } } break; case Dataset.ARRAYFLOAT64: is = a.getElementsPerItem(); dresults = new double[is]; for (int k = 0; k < is; k++) { dresults[k] = 1.; } if (ignoreNaNs) { for (int j = 0; j < alen; j++) { pos[axis] = j; final double[] va = (double[]) a.getObject(pos); boolean skip = false; for (int k = 0; k < is; k++) { if (Double.isNaN(va[k])) { skip = true; break; } } if (!skip) for (int k = 0; k < is; k++) { dresults[k] *= va[k]; } result.set(dresults, pos); } } else { for (int j = 0; j < alen; j++) { pos[axis] = j; final double[] va = (double[]) a.getObject(pos); for (int k = 0; k < is; k++) { dresults[k] *= va[k]; } result.set(dresults, pos); } } break; } } } return result; }
From source file:com.actelion.research.table.view.JVisualization.java
public boolean isMarkerSizeZoomAdapted() { return !Float.isNaN(mMarkerSizeZoomAdaption); }
From source file:org.alfresco.solr.SolrInformationServer.java
private NamedList<Object> fixStats(NamedList<Object> namedList) { int sz = namedList.size(); for (int i = 0; i < sz; i++) { Object value = namedList.getVal(i); if (value instanceof Number) { Number number = (Number) value; if (Float.isInfinite(number.floatValue()) || Float.isNaN(number.floatValue()) || Double.isInfinite(number.doubleValue()) || Double.isNaN(number.doubleValue())) { namedList.setVal(i, null); }// ww w. j a v a2 s . co m } } return namedList; }
From source file:org.eclipse.dataset.CompoundFloatDataset.java
@Override public boolean containsNans() { final IndexIterator iter = getIterator(); // REAL_ONLY while (iter.hasNext()) { // REAL_ONLY for (int i = 0; i < isize; i++) { // REAL_ONLY if (Float.isNaN(data[iter.index + i])) // CLASS_TYPE // REAL_ONLY return true; // REAL_ONLY } // REAL_ONLY } // REAL_ONLY return false; }
From source file:com.actelion.research.table.view.JVisualization.java
/** * Calculates the absolute marker size of the visualization point, which depends * on a view size specific base value (mAbsoluteMarkerSize), a user changeable factor * (mRelativeMarkerSize) and optionally another factor derived from a column value * defined to influence the marker size. * @param vp/*w w w . j ava 2s . c o m*/ * @return */ protected float getMarkerSize(VisualizationPoint vp) { if (mMarkerSizeColumn == cColumnUnassigned) { float size = Float.isNaN(mMarkerSizeZoomAdaption) ? mAbsoluteMarkerSize : mAbsoluteMarkerSize * mMarkerSizeZoomAdaption; return validateSizeWithConnections(size); } if (mTableModel.isDescriptorColumn(mMarkerSizeColumn)) { return getMarkerSizeFromDescriptorSimilarity( mSimilarityMarkerSize == null ? 0.2f : mSimilarityMarkerSize[vp.record.getID()]); } if (CompoundTableHitlistHandler.isHitlistColumn(mMarkerSizeColumn)) return getMarkerSizeFromHitlistMembership(vp.record.isFlagSet(mTableModel.getHitlistHandler() .getHitlistFlagNo(CompoundTableHitlistHandler.getHitlistFromColumn(mMarkerSizeColumn)))); return getMarkerSizeFromValue(vp.record.getDouble(mMarkerSizeColumn)); }
From source file:org.eclipse.dataset.CompoundFloatDataset.java
@Override public boolean containsInvalidNumbers() { IndexIterator iter = getIterator(); // REAL_ONLY while (iter.hasNext()) { // REAL_ONLY for (int i = 0; i < isize; i++) { // REAL_ONLY float x = data[iter.index + i]; // PRIM_TYPE // REAL_ONLY if (Float.isNaN(x) || Float.isInfinite(x)) // CLASS_TYPE // REAL_ONLY return true; // REAL_ONLY } // REAL_ONLY } // REAL_ONLY return false; }
From source file:com.actelion.research.table.view.JVisualization.java
protected float getMarkerSizeFromHitlistMembership(boolean isMember) { float size = (isMember ^ mMarkerSizeInversion) ? mAbsoluteMarkerSize * 1.2f : mAbsoluteMarkerSize * 0.6f; if (!Float.isNaN(mMarkerSizeZoomAdaption)) size *= mMarkerSizeZoomAdaption; return validateSizeWithConnections(size); }
From source file:com.actelion.research.table.view.JVisualization.java
protected float getMarkerSizeFromDescriptorSimilarity(float similarity) { float size = 2f * mAbsoluteMarkerSize * similarity; if (!Float.isNaN(mMarkerSizeZoomAdaption)) size *= mMarkerSizeZoomAdaption; return validateSizeWithConnections(size); }
From source file:com.actelion.research.table.view.JVisualization.java
protected float getMarkerSizeFromValue(float value) { float factor = getMarkerSizeVPFactor(value, mMarkerSizeColumn); if (!Float.isNaN(mMarkerSizeZoomAdaption)) factor *= mMarkerSizeZoomAdaption; float size = (int) (factor * mAbsoluteMarkerSize); return validateSizeWithConnections(size); }