/** * Retrieve a new window series, but only using those sites in the specified partition. This is * trickier than it should be. We only add a new value if TWO conditions are met: 1. The central * site is in the specified partition. 2. At least windowSize / 10 sites in the range are in the * partition * * @param windowSize The breadth of the window (in sites) over which to calculate a single value * @param stepSize The amount the window is moved each step * @param partitionIndex The partition to calculate the value for * @return */ public ArrayList<Point2D> getWindowPointSeries(int windowSize, int stepSize, int partitionIndex) { ArrayList<Point2D> points = new ArrayList<Point2D>(); for (int i = 0; i + windowSize < sg.getMaxSeqLength(); i += stepSize) { double xValue = i; double yValue = Double.NaN; int startSite = Math.max(0, i - windowSize / 2); if (sg.getPartitionNumForSite(i) == partitionIndex || sg.getPartitionNumForSite(i + 1) == partitionIndex || sg.getPartitionNumForSite(i + 2) == partitionIndex) { Double[] sumCount = getSumAndCount(startSite, windowSize, partitionIndex); if (sumCount[1] > ((double) windowSize / 10.0)) yValue = sumCount[0] / sumCount[1]; else yValue = Double.NaN; } points.add(new Point2D.Double(xValue, yValue)); } return points; }
/** * This works just like getValueRange, in that it computes the sum of the values in the * frequencies array over a the given range. But instead of returning sum / number counted, this * returns the two values separately in the array (sum first, then number counted). * * @param begin * @param length * @param partitionIndex * @return */ public Double[] getSumAndCount(int begin, int length, double partitionIndex) { if (freqs == null || freqs.length == 0) { // ErrorWindow.showErrorWindow(new NullPointerException("BaseCounter " + getName() + " was not // properly initialized"), null); System.out.println("Value is NaN, freqs is : " + freqs); return new Double[] {0.0, Double.NaN}; } double sum = 0; double counted = 0; for (int i = begin; i < (begin + length); i++) { if (partitionIndex < 0 || sg.getPartitionNumForSite(i) == partitionIndex) { if (!Double.isNaN(freqs[i])) { sum += freqs[i]; counted++; } } } return new Double[] {sum, counted}; }