All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.jessemull.microflex.integerflex.stat.QuantileStatisticListInteger Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

/* -------------------------------- Package -------------------------------- */

package com.github.jessemull.microflex.integerflex.stat;

/* ----------------------------- Dependencies ------------------------------ */

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.google.common.base.Preconditions;

import com.github.jessemull.microflex.integerflex.plate.PlateInteger;
import com.github.jessemull.microflex.integerflex.plate.WellInteger;
import com.github.jessemull.microflex.integerflex.plate.WellSetInteger;

/**
 * This class calculates descriptive statistics with calculate functions that take
 * list and integer inputs and return a list of lists.
 * 
 * Statistical operations can be performed on stacks, plates, sets and wells using
 * standard or aggregated functions. Standard functions calculate the desired
 * statistic for each well in the stack, plate or set. Aggregated functions aggregate
 * the values from all the wells in the stack, plate or set and perform the statistical
 * operation on the aggregated values. Both standard and aggregated functions can
 * be performed on a subset of data within the stack, plate, set or well.
 * 
 * 

* * The methods within the MicroFlex library are meant to be flexible and the * descriptive statistic object supports operations using a single stack, plate, * set or well as well as collections and arrays of stacks, plates, sets or wells. * * * * * * * * * * * * * * * * * * *
Operation
Beginning
Index
Length of
Subset
Input/Output
* * * * *
Standard
*
* * * * *
+/-
*
* * * * *
+/-
*
* * * * * * * *
Accepts a single well, set, plate or stack as input
Calculates the statistic for each well in a well, set, plate or stack
*
* * * * *
Aggregated
*
* * * * *
+/-
*
* * * * *
+/-
*
* * * * * * * *
Accepts a single well/set/plate/stack or a collection/array of wells/sets/plates/stacks as input
Aggregates the data from all the wells in a well/set/plate/stack and calculates the statistic using the aggregated data
*
* * @author Jesse L. Mull * @update Updated Oct 18, 2016 * @address http://www.jessemull.com * @email [email protected] */ public abstract class QuantileStatisticListInteger { /* --------------- Well statistics for all plate wells ----------------- */ /** * Returns the statistic for each plate well. * @param PlateInteger the plate * @param int the integer value * @return map of wells and results */ public Map>> plate(PlateInteger plate, int p) { Preconditions.checkNotNull(plate, "The plate value cannot be null."); Map>> result = new TreeMap>>(); for (WellInteger well : plate) { WellInteger clone = new WellInteger(well); result.put(clone, well(well, p)); } return result; } /** * Returns the statistic for each plate well using the values between the * beginning and ending indices. * @param PlateInteger the plate * @param int beginning index of subset * @param int length of subset * @param int the integer value * @return map of wells and results */ public Map>> plate(PlateInteger plate, int begin, int length, int p) { Preconditions.checkNotNull(plate, "The plate value cannot be null."); Map>> result = new TreeMap>>(); for (WellInteger well : plate) { WellInteger clone = new WellInteger(well); result.put(clone, well(well, begin, length, p)); } return result; } /* --------------------- Aggregated plate statistics ------------------- */ /** * Returns the aggregated statistic for the plate. * @param PlateInteger the plate * @param int the integer value * @return the aggregated result */ public List> platesAggregated(PlateInteger plate, int p) { Preconditions.checkNotNull(plate, "The plate cannot be null."); List aggregated = new ArrayList(); for (WellInteger well : plate) { aggregated.addAll(well.toDouble()); } return calculate(aggregated, p); } /** * Returns the aggregated statistic for each plate. * @param Collection collection of plates * @param int the integer value * @return map of plates and aggregated results */ public Map>> platesAggregated(Collection collection, int p) { Preconditions.checkNotNull(collection, "The plate collection cannot be null."); Map>> results = new TreeMap>>(); for(PlateInteger plate : collection) { List aggregated = new ArrayList(); PlateInteger clone = new PlateInteger(plate); for (WellInteger well : plate) { aggregated.addAll(well.toDouble()); } results.put(clone, calculate(aggregated, p)); } return results; } /** * Returns the aggregated statistic for each plate. * @param PlateInteger[] array of plates * @param int the integer value * @return map of plates and aggregated result */ public Map>> platesAggregated(PlateInteger[] array, int p) { Preconditions.checkNotNull(array, "The plate array cannot be null."); Map>> results = new TreeMap>>(); for(PlateInteger plate : array) { List aggregated = new ArrayList(); PlateInteger clone = new PlateInteger(plate); for (WellInteger well : plate) { aggregated.addAll(well.toDouble()); } results.put(clone, calculate(aggregated, p)); } return results; } /** * Returns the aggregated statistic for each plate using the values between * the indices. * @param PlateInteger the plate * @param int beginning index of subset * @param int length of subset * @param int the integer value * @return the aggregated result */ public List> platesAggregated( PlateInteger plate, int begin, int length, int p) { Preconditions.checkNotNull(plate, "The plate cannot be null."); List aggregated = new ArrayList(); for (WellInteger well : plate) { aggregated.addAll(well.toDouble().subList(begin, begin + length)); } return calculate(aggregated, p); } /** * Returns the aggregated statistic for each plate using the values between * the indices. * @param Collection collection of plates * @param int beginning index of subset * @param int length of subset * @param int the integer value * @return map of plates and aggregated results */ public Map>> platesAggregated( Collection collection, int begin, int length, int p) { Preconditions.checkNotNull(collection, "The plate collection cannot be null."); Map>> results = new TreeMap>>(); for(PlateInteger plate : collection) { List aggregated = new ArrayList(); PlateInteger clone = new PlateInteger(plate); for (WellInteger well : plate) { aggregated.addAll(well.toDouble().subList(begin, begin + length)); } results.put(clone, calculate(aggregated, p)); } return results; } /** * Returns the aggregated statistic for each plate using the values between * the indices. * @param PlateInteger[] array of plates * @param int beginning index of subset * @param int length of subset * @param int the integer value * @return map of plates and aggregated results */ public Map>> platesAggregated( PlateInteger[] array, int begin, int length, int p) { Preconditions.checkNotNull(array, "The plate array cannot be null."); Map>> results = new TreeMap>>(); for(PlateInteger plate : array) { List aggregated = new ArrayList(); PlateInteger clone = new PlateInteger(plate); for (WellInteger well : plate) { aggregated.addAll(well.toDouble().subList(begin, begin + length)); } results.put(clone, calculate(aggregated, p)); } return results; } /* --------------- Well statistics for all wells in a set -------------- */ /** * Returns the statistic of each well in the well set. * @param WellSetInteger the well set * @param int the integer value * @return map of wells and results */ public Map>> set(WellSetInteger set, int p) { Preconditions.checkNotNull(set, "The set cannot be null."); Map>> result = new TreeMap>>(); for (WellInteger well : set) { WellInteger clone = new WellInteger(well); result.put(clone, well(well, p)); } return result; } /** * Returns the statistic of each well in the well set using the values between * the beginning and ending indices. * @param WellSetInteger the well set * @param int beginning index of subset * @param int length of subset * @param int the integer value * @return map of wells and results */ public Map>> set(WellSetInteger set, int begin, int length, int p) { Preconditions.checkNotNull(set, "The well set cannot be null."); Map>> result = new TreeMap>>(); for (WellInteger well : set) { WellInteger clone = new WellInteger(well); result.put(clone, well(well, begin, length, p)); } return result; } /* --------------------- Aggregated set statistics --------------------- */ /** * Returns the aggregated statistic for the well set. * @param WellSetInteger the well set * @param int the integer value * @return the aggregated result */ public List> setsAggregated(WellSetInteger set, int p) { Preconditions.checkNotNull(set, "The well set cannot be null."); List aggregated = new ArrayList(); for (WellInteger well : set) { aggregated.addAll(well.toDouble()); } return calculate(aggregated, p); } /** * Returns the aggregated statistic for each well set. * @param Collection collection of well sets * @param int the integer value * @return map of well sets and aggregated results */ public Map>> setsAggregated(Collection collection, int p) { Preconditions.checkNotNull(collection, "The well set collection cannot be null."); Map>> results = new TreeMap>>(); for(WellSetInteger set : collection) { List aggregated = new ArrayList(); WellSetInteger clone = new WellSetInteger(set); for (WellInteger well : set) { aggregated.addAll(well.toDouble()); } results.put(clone, calculate(aggregated, p)); } return results; } /** * Returns the aggregated statistic for each well set. * @param WellSetInteger[] array of well sets * @param int the integer value * @return map of well sets and aggregated results */ public Map>> setsAggregated(WellSetInteger[] array, int p) { Preconditions.checkNotNull(array, "The well set array cannot be null."); Map>> results = new TreeMap>>(); for(WellSetInteger set : array) { List aggregated = new ArrayList(); WellSetInteger clone = new WellSetInteger(set); for (WellInteger well : set) { aggregated.addAll(well.toDouble()); } results.put(clone, calculate(aggregated, p)); } return results; } /** * Returns the aggregated statistic for each well set using the values between the * indices. * @param WellSetInteger the well set * @param int beginning index of subset * @param int length of subset * @param int the integer value * @return the aggregated result */ public List> setsAggregated( WellSetInteger set, int begin, int length, int p) { Preconditions.checkNotNull(set, "The well set cannot be null."); List aggregated = new ArrayList(); for (WellInteger well : set) { aggregated.addAll(well.toDouble().subList(begin, begin + length)); } return calculate(aggregated, p); } /** * Returns the aggregated statistic for each well set using the values between * the indices. * @param Collection collection of well sets * @param int beginning index of subset * @param int length of subset * @param int the integer value * @return map of well sets and aggregated results */ public Map>> setsAggregated( Collection collection, int begin, int length, int p) { Preconditions.checkNotNull(collection, "The well set collection cannot be null."); Map>> results = new TreeMap>>(); for(WellSetInteger set : collection) { List aggregated = new ArrayList(); WellSetInteger clone = new WellSetInteger(set); for (WellInteger well : set) { aggregated.addAll(well.toDouble().subList(begin, begin + length)); } results.put(clone, calculate(aggregated, p)); } return results; } /** * Returns the aggregated statistic for each well set using the values between * the indices. * @param WellSetInteger[] array of well sets * @param int beginning index of subset * @param int length of subset * @param int the integer value * @return map of well sets and aggregated results */ public Map>> setsAggregated( WellSetInteger[] array, int begin, int length, int p) { Preconditions.checkNotNull(array, "The well set array cannot be null."); Map>> results = new TreeMap>>(); for(WellSetInteger set : array) { List aggregated = new ArrayList(); WellSetInteger clone = new WellSetInteger(set); for (WellInteger well : set) { aggregated.addAll(well.toDouble().subList(begin, begin + length)); } results.put(clone, calculate(aggregated, p)); } return results; } /* -------------------------- Well statistics -------------------------- */ /** * Returns the well statistic. * @param WellInteger the well * @param int the integer value * @return the result */ public List> well(WellInteger well, int p) { Preconditions.checkNotNull(well, "The well cannot be null."); return calculate(well.toDouble(), p); } /** * Returns the well statistic for the values between the beginning and ending * indices. * @param WellInteger the well * @param int beginning index of subset * @param int length of the subset * @param int the integer value * @return the result */ public List> well(WellInteger well, int begin, int length, int p) { Preconditions.checkNotNull(well, "The well cannot be null."); Preconditions.checkArgument(begin <= well.data().size() && begin >= 0 && begin + length <= well.data().size()); return calculate(well.toDouble(), begin, length, p); } /* ----------- Methods for calculating the data set statistic ---------- */ /** * Calculates the statistic. * @param List the list * @param int the integer value * @return the result */ public abstract List> calculate(List list, int p); /** * Calculates the statistic of the values between the beginning and ending * indices. * @param List the list * @param int beginning index of subset * @param int length of subset * @param int the integer value * @return the result */ public abstract List> calculate(List list, int begin, int length, int p); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy