nix.util.gen
Class Num

java.lang.Object
  extended bynix.util.gen.Num

public class Num
extends java.lang.Object

Math and statistical static methods.


Constructor Summary
Num()
           
 
Method Summary
static double[] arrayListOfDoubleToArray(java.util.ArrayList dbl)
          ArrayList of Double to double[]
static float[] arrayListOfFloatToArray(java.util.ArrayList flt)
          ArrayList of Float to float[]
static double[] arrayListToDoubles(java.util.ArrayList doubles)
          ArrayList of Double to double[]
static int[] arrayListToInts(java.util.ArrayList integers)
          ArrayList of Integer to int[]
static double aveFoldDiffCombine(int[] t, int[] c)
          Calculates the average fold difference between two int[]s of the same length.
static double aveFoldDiffIndividual(int[] t, int[] c)
          Calculates the average fold difference between two int[]s of the same length.
static double averageFloatArray(float[] f)
          Averages a float[]
static double[] averageFloatArrays(float[][] ints)
          Average float[][] values to double[], averages repeats [values][numRepeats]
static double[] averageFloatArraysFlipped(float[][] ints)
          Average float[][] values to double[], averages repeats [numChips][OligoValues].
static double averageIntArray(int[] f)
          Averages a int[]
static double[] averageIntIntArray(int[][] ints)
          Average int[][] values to double[], averages repeats [numRepeats][values]
static double[] averageIntIntArray2(int[][] ints)
          Average int[][] values to double[], averages values [numRepeats][values]
static double calcMaxMedianAbsoluteDifference(float[][] oligosValues)
          Calculates the maximum median absolute difference between arrays of float where int[oligo index number][oligo intensity measurements]
static double calcMeanMedianAbsoluteDifference(float[][] oligosValues)
          Calculates the mean of the median absolute differences between arrays of float where float[oligo index number][oligo intensity measurements]
static float[] collapseFloatArray(float[][] fs)
          Assumes equal lengths of the float[]s
static int[] collapseIntArray(int[][] ints)
          Assumes equal lengths of the int[]s
static float[] convertToFloat(int[] d)
          Convert to float[]
static int[] convertToInt(double[] d)
          Convert to Int[]
static int[] convertToInt(float[] d)
          Convert to Int[]
static double correlationCoefficient(double[] x, double[] y)
          Calculates Pearson correlation coefficient, r, from two double[]s
static double correlationCoefficient(float[] x, float[] y)
          Calculates Pearson correlation coefficient, r, from two float[]s.
static double correlationCoefficient(int[] x, int[] y)
          Calculates Pearson correlation coefficient, r, from two int[]s.
static double[] difference(double[] t, double[] c)
          Returns the difference of each pair.
static double[] difference(int[] t, int[] c)
          Returns the difference of each pair.
static float findHighestFloat(float[] ints)
          Finds and returns the biggest int in an float[].
static int findHighestInt(int[] ints)
          Finds and returns the biggest int in an int[].
static double[] findMinMaxDoubleValues(double[] f)
          Finds min and max values of a float array.
static float[] findMinMaxFloatArrays(float[][] f)
          Finds min and max values of a float array.
static float[] findMinMaxFloatValues(float[] f)
          Finds min and max values of a float array.
static int[] findMinMaxIntInt(int[][] f)
          Finds min and max values of a int array.
static int[] findMinMaxIntValues(int[] f)
          Finds min and max values of a int array.
static int[] findStartStopIndexes(int[] positions, int startValue, int stopValue)
          Finds the start and stop indexes given a sorted int[] of values and two values, one after the other, close together, otherwise just use Arrays.binarySearch.
static java.lang.String formatNumber(double num, int numberOfDecimalPlaces)
          Converts a double ddd.dddddddd to a user determined number of decimal places right of the .
static java.lang.String formatNumberOneFraction(double num)
          Converts a double ddd.dddddddd to sss.s
static java.lang.String formatPercentOneFraction(double num)
          Converts 0.345543 to 34.6%
static float getAverageInts(int start, int end)
          Gets the average of the integers bracketed and including the start and end.
static double[] loadDoubles(java.io.File f)
          Loads a column of double from a file into an array.
static int[] loadInts(java.io.File f)
          Loads a column of ints from a file into an array.
static double log10(double number)
          Returns the LOG base 10 of the number.
static double log2(double number)
          Returns the LOG base 2 of the number.
static double[] logRatios(double[] t, double[] c)
          Calculates log base 2 ratios
static double[] logRatios(float[] t, float[] c)
          Calculates log base 2 ratios
static double mean(double[] t)
          Averages a double array.
static float mean(float[] t)
          Averages a float array.
static double mean(int[] t)
          Averages a int array.
static java.lang.String meanDoubles(java.util.ArrayList Doubles)
          Averages an ArrayList of Double objects.
static int meanIntegers(java.util.ArrayList Integers)
          Averages an ArrayList of Integer objects.
static double median(double[] sorted)
          Calculates Median of a sorted double[].
static double median(float[] m)
          Calculates Median of a sorted float[].
static double median(int[] m)
          Calculates Median of a sorted int[].
static double median(short[] m)
          Calculates Median of a sorted short[].
static double medianAbsoluteDifference(float[] x, float[] y)
          Calculates the median absolute difference.
static void medianNormalize(float[][] f, float targetMedian, boolean skipZeros)
          Median normalizes original array to a given number.
static float[] medianNormalize(float[] f, float targetMedian)
          Median normalize array to a given number.
static int[] modeOfHistogram(int[] ints)
          Finds mode of a int[] histogram array, assumes one peak, returns the index position, value/frequency.
static int parseInt(java.lang.String stringInt, int failNumber)
          Attemps to parse an int, returns failNumber if it fails.
static double[] ratio(double[] t, double[] c)
          Returns the ratio of each pair.
static double[] ratio(float[] t, float[] c)
          Returns the ratio of each pair.
static double[] ratio(int[] t, double[] c)
          Returns the ratio of each pair.
static double[] ratio(int[] t, int[] c)
          Returns the ratio of each pair.
static double relativeDifference(double t, double c)
          Calculates relative difference.
static double[] relativeDifferences(float[] t, float[] c)
          Calculates relative differences.
static double[] removeNaNInfinite(double[] d)
          Removes any NaN or Infinite
static float[] removeZeroValues(float[] f)
          Remove zero values from float array.
static float[][] removeZeroValues(float[][] f)
          Provide a float[2][0], will remove zeros from both and there matched pair.
static float[][][] removeZeroValues(float[][] t, float[][] c)
          Removes zero values and their assoicated values from all arrays.
static double[] round(double[] d, int numDecimals)
          Rounds a double[] based on number of desired decimals, ie 1 = x.x, 2 = x.xx limited to 6
static double round(double d, int numDecimals)
          Rounds a double based on number of desired decimals, ie 1 = x.x, 2 = x.xx limited to 6
static double[] smoothScores(double[] scores, int[] positions, int windowSize)
          Uses a sliding window to smooth the scores applying a trimmed mean (drop 1 from ends) to the scores found within the window.
static double standardDeviation(double[] x)
          Calculates standard deviation of an double[]
static double standardDeviation(double[] x, double mean)
          Calculates standard deviation of a double[] and mean.
static double standardDeviation(float[] x)
          Calculates standard deviation of an float[]
static double standardDeviation(float[] x, double mean)
          Calculates standard deviation of an float[] and mean.
static double standardDeviation(int[] x)
          Calculates standard deviation of an int[]
static double standardDeviation(int[] x, double mean)
          Calculates standard deviation of an int[] and mean.
static double standardDeviationOfDifference(int[] t, int[] c)
          Calculates the standard deviation of the difference between two int[]s of the same length.
static double standardError(double[] x, double mean)
          Calculates standard error of a double[] given it's mean.
static void statFloatArray(float[] f)
          Calculates Min, Max, Mean, Median, Mode, and Histogram/10 for a Float[]
static int sumIntArray(int[] ints)
          Sums an int array
static double trimmedMean(double[] sortedDouble, int trimNumber)
          Makes a trimmed mean, note the trim number is not a % but the number of values to drop from the beginning and end of the ordered set.
static int trimOutliers(float[][] f, double cutoff, float replacement)
          Sets values exceeding the cutoff to the default.
static int trimOutliers(float[] f, double cutoff, float replacement)
          Sets values exceeding the cutoff to the default.
static double[] windowAverageScores(double[] scores, int windowSize)
          Slides a window along an array, one index at a time, averaging the contents.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Num

public Num()
Method Detail

removeZeroValues

public static float[][][] removeZeroValues(float[][] t,
                                           float[][] c)
Removes zero values and their assoicated values from all arrays. Pass two float[numChips][oligoValues] representing treatment and control chips. The num oligoValues should be the same, the numChips can vary between t and c. Returns float[2][][] representing t[][] and c[][].


trimOutliers

public static int trimOutliers(float[] f,
                               double cutoff,
                               float replacement)
Sets values exceeding the cutoff to the default. Returns the number of changes.


trimOutliers

public static int trimOutliers(float[][] f,
                               double cutoff,
                               float replacement)
Sets values exceeding the cutoff to the default. Returns the number of changes.


medianNormalize

public static float[] medianNormalize(float[] f,
                                      float targetMedian)
Median normalize array to a given number.


medianNormalize

public static void medianNormalize(float[][] f,
                                   float targetMedian,
                                   boolean skipZeros)
Median normalizes original array to a given number.


convertToInt

public static int[] convertToInt(double[] d)
Convert to Int[]


convertToInt

public static int[] convertToInt(float[] d)
Convert to Int[]


convertToFloat

public static float[] convertToFloat(int[] d)
Convert to float[]


relativeDifferences

public static double[] relativeDifferences(float[] t,
                                           float[] c)
Calculates relative differences. 2 * ( (t-c)/(t+c) )


relativeDifference

public static double relativeDifference(double t,
                                        double c)
Calculates relative difference. 2 * ( (t-c)/(t+c) )


logRatios

public static double[] logRatios(double[] t,
                                 double[] c)
Calculates log base 2 ratios


logRatios

public static double[] logRatios(float[] t,
                                 float[] c)
Calculates log base 2 ratios


round

public static double[] round(double[] d,
                             int numDecimals)
Rounds a double[] based on number of desired decimals, ie 1 = x.x, 2 = x.xx limited to 6


round

public static double round(double d,
                           int numDecimals)
Rounds a double based on number of desired decimals, ie 1 = x.x, 2 = x.xx limited to 6


removeNaNInfinite

public static double[] removeNaNInfinite(double[] d)
Removes any NaN or Infinite


log10

public static double log10(double number)
Returns the LOG base 10 of the number.


log2

public static double log2(double number)
Returns the LOG base 2 of the number.


loadInts

public static int[] loadInts(java.io.File f)
Loads a column of ints from a file into an array. Returns null if nothing found. Skips blank lines.


loadDoubles

public static double[] loadDoubles(java.io.File f)
Loads a column of double from a file into an array. Returns null if nothing found. Skips blank lines.


arrayListToInts

public static int[] arrayListToInts(java.util.ArrayList integers)
ArrayList of Integer to int[]


arrayListToDoubles

public static double[] arrayListToDoubles(java.util.ArrayList doubles)
ArrayList of Double to double[]


parseInt

public static int parseInt(java.lang.String stringInt,
                           int failNumber)
Attemps to parse an int, returns failNumber if it fails.


statFloatArray

public static void statFloatArray(float[] f)
Calculates Min, Max, Mean, Median, Mode, and Histogram/10 for a Float[]


removeZeroValues

public static float[] removeZeroValues(float[] f)
Remove zero values from float array.


getAverageInts

public static float getAverageInts(int start,
                                   int end)
Gets the average of the integers bracketed and including the start and end. (ie 3,6 returns the average of 3+4+5+6/4= 4.5)


collapseIntArray

public static int[] collapseIntArray(int[][] ints)
Assumes equal lengths of the int[]s


collapseFloatArray

public static float[] collapseFloatArray(float[][] fs)
Assumes equal lengths of the float[]s


averageIntArray

public static double averageIntArray(int[] f)
Averages a int[]


averageFloatArray

public static double averageFloatArray(float[] f)
Averages a float[]


findMinMaxIntValues

public static int[] findMinMaxIntValues(int[] f)
Finds min and max values of a int array.


findMinMaxFloatValues

public static float[] findMinMaxFloatValues(float[] f)
Finds min and max values of a float array.


findMinMaxDoubleValues

public static double[] findMinMaxDoubleValues(double[] f)
Finds min and max values of a float array.


findMinMaxIntInt

public static int[] findMinMaxIntInt(int[][] f)
Finds min and max values of a int array.


findMinMaxFloatArrays

public static float[] findMinMaxFloatArrays(float[][] f)
Finds min and max values of a float array.


findStartStopIndexes

public static int[] findStartStopIndexes(int[] positions,
                                         int startValue,
                                         int stopValue)
Finds the start and stop indexes given a sorted int[] of values and two values, one after the other, close together, otherwise just use Arrays.binarySearch. Good for huge int[] arrays.


standardDeviationOfDifference

public static double standardDeviationOfDifference(int[] t,
                                                   int[] c)
Calculates the standard deviation of the difference between two int[]s of the same length.


averageIntIntArray

public static double[] averageIntIntArray(int[][] ints)
Average int[][] values to double[], averages repeats [numRepeats][values]


averageFloatArrays

public static double[] averageFloatArrays(float[][] ints)
Average float[][] values to double[], averages repeats [values][numRepeats]


averageFloatArraysFlipped

public static double[] averageFloatArraysFlipped(float[][] ints)
Average float[][] values to double[], averages repeats [numChips][OligoValues]. Assumes equal number of oligos.


averageIntIntArray2

public static double[] averageIntIntArray2(int[][] ints)
Average int[][] values to double[], averages values [numRepeats][values]


smoothScores

public static double[] smoothScores(double[] scores,
                                    int[] positions,
                                    int windowSize)
Uses a sliding window to smooth the scores applying a trimmed mean (drop 1 from ends) to the scores found within the window. The collection of values within the window is only an attempt to look windowSize/2 upstream and windowSize/2 downstream, not a requirement. Thus at either end of the scores possibly only 1/2 of the scores are used in making the calculation that is associated with the original score.


windowAverageScores

public static double[] windowAverageScores(double[] scores,
                                           int windowSize)
Slides a window along an array, one index at a time, averaging the contents.


trimmedMean

public static double trimmedMean(double[] sortedDouble,
                                 int trimNumber)
Makes a trimmed mean, note the trim number is not a % but the number of values to drop from the beginning and end of the ordered set. Set appropriately. Be sure to submit an ordered array!


arrayListOfDoubleToArray

public static double[] arrayListOfDoubleToArray(java.util.ArrayList dbl)
ArrayList of Double to double[]


arrayListOfFloatToArray

public static float[] arrayListOfFloatToArray(java.util.ArrayList flt)
ArrayList of Float to float[]


aveFoldDiffCombine

public static double aveFoldDiffCombine(int[] t,
                                        int[] c)
Calculates the average fold difference between two int[]s of the same length. Takes the mean of both arrays returns the ratio.


aveFoldDiffIndividual

public static double aveFoldDiffIndividual(int[] t,
                                           int[] c)
Calculates the average fold difference between two int[]s of the same length. Calculates the ratio of each individually, then returns their average.


ratio

public static double[] ratio(double[] t,
                             double[] c)
Returns the ratio of each pair.


ratio

public static double[] ratio(float[] t,
                             float[] c)
Returns the ratio of each pair.


ratio

public static double[] ratio(int[] t,
                             double[] c)
Returns the ratio of each pair.


ratio

public static double[] ratio(int[] t,
                             int[] c)
Returns the ratio of each pair.


difference

public static double[] difference(int[] t,
                                  int[] c)
Returns the difference of each pair.


difference

public static double[] difference(double[] t,
                                  double[] c)
Returns the difference of each pair.


standardDeviation

public static double standardDeviation(int[] x)
Calculates standard deviation of an int[]


standardDeviation

public static double standardDeviation(int[] x,
                                       double mean)
Calculates standard deviation of an int[] and mean.


standardDeviation

public static double standardDeviation(float[] x)
Calculates standard deviation of an float[]


standardDeviation

public static double standardDeviation(float[] x,
                                       double mean)
Calculates standard deviation of an float[] and mean.


standardDeviation

public static double standardDeviation(double[] x)
Calculates standard deviation of an double[]


standardDeviation

public static double standardDeviation(double[] x,
                                       double mean)
Calculates standard deviation of a double[] and mean.


standardError

public static double standardError(double[] x,
                                   double mean)
Calculates standard error of a double[] given it's mean. Spead savings


medianAbsoluteDifference

public static double medianAbsoluteDifference(float[] x,
                                              float[] y)
Calculates the median absolute difference.


calcMaxMedianAbsoluteDifference

public static double calcMaxMedianAbsoluteDifference(float[][] oligosValues)
Calculates the maximum median absolute difference between arrays of float where int[oligo index number][oligo intensity measurements]


calcMeanMedianAbsoluteDifference

public static double calcMeanMedianAbsoluteDifference(float[][] oligosValues)
Calculates the mean of the median absolute differences between arrays of float where float[oligo index number][oligo intensity measurements]


correlationCoefficient

public static double correlationCoefficient(int[] x,
                                            int[] y)
Calculates Pearson correlation coefficient, r, from two int[]s. Cannot have one int[] be uniform values, returns -2 if error.


removeZeroValues

public static float[][] removeZeroValues(float[][] f)
Provide a float[2][0], will remove zeros from both and there matched pair. Does a pairwise zero removal, if either of the float arrays are zero both values are removed.


correlationCoefficient

public static double correlationCoefficient(float[] x,
                                            float[] y)
Calculates Pearson correlation coefficient, r, from two float[]s. Cannot have one float[] be uniform values, returns -2 if error.


correlationCoefficient

public static double correlationCoefficient(double[] x,
                                            double[] y)
Calculates Pearson correlation coefficient, r, from two double[]s


formatPercentOneFraction

public static java.lang.String formatPercentOneFraction(double num)
Converts 0.345543 to 34.6%


formatNumberOneFraction

public static java.lang.String formatNumberOneFraction(double num)
Converts a double ddd.dddddddd to sss.s


formatNumber

public static java.lang.String formatNumber(double num,
                                            int numberOfDecimalPlaces)
Converts a double ddd.dddddddd to a user determined number of decimal places right of the .


median

public static double median(double[] sorted)
Calculates Median of a sorted double[]. Copied code from WWW.


median

public static double median(int[] m)
Calculates Median of a sorted int[].


median

public static double median(short[] m)
Calculates Median of a sorted short[]. Copied code from WWW.


median

public static double median(float[] m)
Calculates Median of a sorted float[]. Copied code from WWW.


mean

public static float mean(float[] t)
Averages a float array.


mean

public static double mean(int[] t)
Averages a int array.


mean

public static double mean(double[] t)
Averages a double array.


meanIntegers

public static int meanIntegers(java.util.ArrayList Integers)
Averages an ArrayList of Integer objects.


meanDoubles

public static java.lang.String meanDoubles(java.util.ArrayList Doubles)
Averages an ArrayList of Double objects.


findHighestInt

public static int findHighestInt(int[] ints)
Finds and returns the biggest int in an int[].


findHighestFloat

public static float findHighestFloat(float[] ints)
Finds and returns the biggest int in an float[].


sumIntArray

public static int sumIntArray(int[] ints)
Sums an int array


modeOfHistogram

public static int[] modeOfHistogram(int[] ints)
Finds mode of a int[] histogram array, assumes one peak, returns the index position, value/frequency.