Search in sources :

Example 11 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project sling by apache.

the class PollingTest method testCallableTwice.

@Test
public void testCallableTwice() throws Exception {
    final MutableInt callCount = new MutableInt(0);
    final MutableBoolean called = new MutableBoolean(false);
    Polling p = new Polling(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            callCount.increment();
            boolean b = called.booleanValue();
            called.setTrue();
            return b;
        }
    });
    p.poll(500, 10);
    assertEquals(2, callCount.intValue());
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 12 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project sling by apache.

the class PollingTest method testCallableTimeout.

@Test
public void testCallableTimeout() throws Exception {
    final MutableInt callCount = new MutableInt(0);
    Polling p = new Polling(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            callCount.increment();
            return false;
        }
    });
    try {
        p.poll(100, 10);
    } catch (TimeoutException e) {
        assertTrue("Expected to execute call() at least 4 times, got instead only " + callCount.intValue() + " calls", callCount.intValue() > 5);
        return;
    }
    fail("Did not reach timeout");
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) TimeoutException(java.util.concurrent.TimeoutException) TimeoutException(java.util.concurrent.TimeoutException) Test(org.junit.Test)

Example 13 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project gatk by broadinstitute.

the class AllelicPanelOfNormalsCreator method create.

/**
     * Creates an {@link AllelicPanelOfNormals} given a site-frequency threshold;
     * sites appearing in strictly less than this fraction of samples will not be included in the panel of normals.
     * @param siteFrequencyThreshold    site-frequency threshold
     * @return                          an {@link AllelicPanelOfNormals} containing sites
     *                                  above the site-frequency threshold
     */
public AllelicPanelOfNormals create(final double siteFrequencyThreshold) {
    logger.info("Creating allelic panel of normals...");
    //used to filter on frequency
    final Map<SimpleInterval, MutableInt> numberOfSamplesMap = new HashMap<>();
    //store only the total counts (smaller memory footprint)
    final Map<SimpleInterval, AllelicCount> totalCountsMap = new HashMap<>();
    int pulldownFileCounter = 1;
    final int totalNumberOfSamples = pulldownFiles.size();
    for (final File pulldownFile : pulldownFiles) {
        logger.info("Processing pulldown file " + pulldownFileCounter++ + "/" + totalNumberOfSamples + " (" + pulldownFile + ")...");
        final AllelicCountCollection pulldownCounts = new AllelicCountCollection(pulldownFile);
        for (final AllelicCount count : pulldownCounts.getCounts()) {
            //update the sum of ref and alt counts at each site
            final SimpleInterval site = count.getInterval();
            final AllelicCount currentCountAtSite = totalCountsMap.getOrDefault(site, new AllelicCount(site, 0, 0));
            final AllelicCount updatedCountAtSite = new AllelicCount(site, currentCountAtSite.getRefReadCount() + count.getRefReadCount(), currentCountAtSite.getAltReadCount() + count.getAltReadCount());
            totalCountsMap.put(site, updatedCountAtSite);
            //update the number of samples seen possessing each site
            final MutableInt numberOfSamplesAtSite = numberOfSamplesMap.get(site);
            if (numberOfSamplesAtSite == null) {
                numberOfSamplesMap.put(site, new MutableInt(1));
            } else {
                numberOfSamplesAtSite.increment();
            }
        }
    }
    logger.info("Total number of unique sites present in samples: " + totalCountsMap.size());
    //filter out sites that appear at a frequency strictly less than the provided threshold
    final AllelicCountCollection totalCounts = new AllelicCountCollection();
    numberOfSamplesMap.entrySet().stream().filter(e -> e.getValue().doubleValue() / totalNumberOfSamples >= siteFrequencyThreshold).map(e -> totalCountsMap.get(e.getKey())).forEach(totalCounts::add);
    logger.info(String.format("Number of unique sites present in samples above site frequency = %4.3f: %d", siteFrequencyThreshold, totalCounts.getCounts().size()));
    return new AllelicPanelOfNormals(totalCounts);
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) IOUtils(org.broadinstitute.hellbender.utils.io.IOUtils) AllelicCount(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount) HashMap(java.util.HashMap) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) ParamUtils(org.broadinstitute.hellbender.utils.param.ParamUtils) File(java.io.File) ArrayList(java.util.ArrayList) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Map(java.util.Map) Utils(org.broadinstitute.hellbender.utils.Utils) LogManager(org.apache.logging.log4j.LogManager) AllelicCountCollection(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountCollection) HashMap(java.util.HashMap) MutableInt(org.apache.commons.lang3.mutable.MutableInt) AllelicCountCollection(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountCollection) SimpleInterval(org.broadinstitute.hellbender.utils.SimpleInterval) File(java.io.File) AllelicCount(org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)

Example 14 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.

the class AbstractStreamPatternMatcher method setup.

@Override
public void setup(Context.OperatorContext context) {
    super.setup(context);
    patternLength = new MutableInt(pattern.getStates().length - 1);
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt)

Example 15 with MutableInt

use of org.apache.commons.lang3.mutable.MutableInt in project apex-malhar by apache.

the class GPOUtils method serialize.

/**
 * Serializes the given {@link GPOMutable} object to an array of bytes.
 * @param gpo The {@link GPOMutable} object to serialize.
 * @param byteArrayList A byte array list to pack serialized data into. Note that
 * it is assumed that the byteArrayList is empty when passed to this method.
 * @return The serialized {@link GPOMutable} object.
 */
public static byte[] serialize(GPOMutable gpo, GPOByteArrayList byteArrayList) {
    int slength = serializedLength(gpo);
    byte[] sbytes = new byte[slength];
    MutableInt offset = new MutableInt(0);
    boolean[] fieldsBoolean = gpo.getFieldsBoolean();
    if (fieldsBoolean != null) {
        for (int index = 0; index < fieldsBoolean.length; index++) {
            serializeBoolean(fieldsBoolean[index], sbytes, offset);
        }
    }
    char[] fieldsCharacter = gpo.getFieldsCharacter();
    if (fieldsCharacter != null) {
        for (int index = 0; index < fieldsCharacter.length; index++) {
            serializeChar(fieldsCharacter[index], sbytes, offset);
        }
    }
    byte[] fieldsByte = gpo.getFieldsByte();
    if (fieldsByte != null) {
        for (int index = 0; index < fieldsByte.length; index++) {
            serializeByte(fieldsByte[index], sbytes, offset);
        }
    }
    short[] fieldsShort = gpo.getFieldsShort();
    if (fieldsShort != null) {
        for (int index = 0; index < fieldsShort.length; index++) {
            serializeShort(fieldsShort[index], sbytes, offset);
        }
    }
    int[] fieldsInteger = gpo.getFieldsInteger();
    if (fieldsInteger != null) {
        for (int index = 0; index < fieldsInteger.length; index++) {
            serializeInt(fieldsInteger[index], sbytes, offset);
        }
    }
    long[] fieldsLong = gpo.getFieldsLong();
    if (fieldsLong != null) {
        for (int index = 0; index < fieldsLong.length; index++) {
            serializeLong(fieldsLong[index], sbytes, offset);
        }
    }
    float[] fieldsFloat = gpo.getFieldsFloat();
    if (fieldsFloat != null) {
        for (int index = 0; index < fieldsFloat.length; index++) {
            serializeFloat(fieldsFloat[index], sbytes, offset);
        }
    }
    double[] fieldsDouble = gpo.getFieldsDouble();
    if (fieldsDouble != null) {
        for (int index = 0; index < fieldsDouble.length; index++) {
            serializeDouble(fieldsDouble[index], sbytes, offset);
        }
    }
    String[] fieldsString = gpo.getFieldsString();
    if (fieldsString != null) {
        for (int index = 0; index < fieldsString.length; index++) {
            serializeString(fieldsString[index], sbytes, offset);
        }
    }
    if (sbytes.length > 0) {
        byteArrayList.add(sbytes);
    }
    Object[] fieldsObject = gpo.getFieldsObject();
    Serde[] serdes = gpo.getFieldDescriptor().getSerdes();
    if (fieldsObject != null) {
        for (int index = 0; index < fieldsObject.length; index++) {
            byteArrayList.add(serdes[index].serializeObject(fieldsObject[index]));
        }
    }
    byte[] bytes = byteArrayList.toByteArray();
    byteArrayList.clear();
    return bytes;
}
Also used : MutableInt(org.apache.commons.lang3.mutable.MutableInt) JSONObject(org.codehaus.jettison.json.JSONObject)

Aggregations

MutableInt (org.apache.commons.lang3.mutable.MutableInt)46 Test (org.junit.Test)16 Type (org.apache.apex.malhar.lib.appdata.schemas.Type)6 HashMap (java.util.HashMap)5 MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)5 List (java.util.List)4 Map (java.util.Map)4 TimeoutException (java.util.concurrent.TimeoutException)4 FieldsDescriptor (org.apache.apex.malhar.lib.appdata.schemas.FieldsDescriptor)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 AllelicCount (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCount)2 AllelicCountCollection (org.broadinstitute.hellbender.tools.exome.alleliccount.AllelicCountCollection)2 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)2 GraphStoreFixture (org.neo4j.consistency.checking.GraphStoreFixture)2 IdGenerator (org.neo4j.consistency.checking.GraphStoreFixture.IdGenerator)2 TransactionDataBuilder (org.neo4j.consistency.checking.GraphStoreFixture.TransactionDataBuilder)2