List of usage examples for org.apache.commons.lang ArrayUtils subarray
public static boolean[] subarray(boolean[] array, int startIndexInclusive, int endIndexExclusive)
Produces a new boolean
array containing the elements between the start and end indices.
From source file:org.apache.velocity.io.UnicodeInputStreamTestCase.java
protected byte[] readAllBytes(final InputStream inputStream, final String enc) throws Exception { InputStreamReader isr = null; byte[] res = new byte[0]; try {/* w ww.j a v a2s. c om*/ byte[] buf = new byte[1024]; int read = 0; while ((read = inputStream.read(buf)) >= 0) { res = ArrayUtils.addAll(res, ArrayUtils.subarray(buf, 0, read)); } } finally { if (isr != null) { isr.close(); } } return res; }
From source file:org.beanfuse.persist.hibernate.EntityDaoHibernate.java
public List load(String entityName, String keyName, Object[] values) { StringBuilder hql = new StringBuilder(); hql.append("select entity from ").append(entityName).append(" as entity where entity.").append(keyName) .append(" in (:keyName)"); Map parameterMap = new HashMap(1); if (values.length < 500) { parameterMap.put("keyName", values); EntityQuery query = new EntityQuery(hql.toString()); query.setParams(parameterMap);//from w w w. j av a2 s . co m return (List) search(query); } else { EntityQuery query = new EntityQuery(hql.toString()); query.setParams(parameterMap); List rs = new ArrayList(); int i = 0; while (i < values.length) { int end = i + 500; if (end > values.length) { end = values.length; } parameterMap.put("keyName", ArrayUtils.subarray(values, i, end)); rs.addAll(search(query)); i += 500; } return rs; } }
From source file:org.beangle.model.persist.hibernate.HibernateEntityDao.java
public <T> List<T> get(String entityName, String keyName, Object... values) { StringBuilder hql = new StringBuilder(); hql.append("select entity from ").append(entityName).append(" as entity where entity.").append(keyName) .append(" in (:keyName)"); Map<String, Object> parameterMap = CollectUtils.newHashMap(); if (values.length < 500) { parameterMap.put("keyName", values); QueryBuilder<T> query = OqlBuilder.hql(hql.toString()); return search(query.params(parameterMap).build()); } else {// ww w.ja v a 2 s .com QueryBuilder<T> query = OqlBuilder.hql(hql.toString()); List<T> rs = CollectUtils.newArrayList(); int i = 0; while (i < values.length) { int end = i + 500; if (end > values.length) { end = values.length; } parameterMap.put("keyName", ArrayUtils.subarray(values, i, end)); rs.addAll(search(query.params(parameterMap).build())); i += 500; } return rs; } }
From source file:org.broadinstitute.gatk.tools.walkers.haplotypecaller.LDMerger.java
protected VariantContext createMergedVariantContext(final VariantContext thisVC, final VariantContext nextVC, final byte[] ref, final GenomeLoc refLoc) { final int thisStart = thisVC.getStart(); final int nextStart = nextVC.getStart(); byte[] refBases = new byte[] {}; byte[] altBases = new byte[] {}; refBases = ArrayUtils.addAll(refBases, thisVC.getReference().getBases()); altBases = ArrayUtils.addAll(altBases, thisVC.getAlternateAllele(0).getBases()); int locus;/* w w w.java 2 s .c o m*/ for (locus = thisStart + refBases.length; locus < nextStart; locus++) { final byte refByte = ref[locus - refLoc.getStart()]; refBases = ArrayUtils.add(refBases, refByte); altBases = ArrayUtils.add(altBases, refByte); } refBases = ArrayUtils.addAll(refBases, ArrayUtils.subarray(nextVC.getReference().getBases(), locus > nextStart ? 1 : 0, nextVC.getReference().getBases().length)); // special case of deletion including the padding base of consecutive indel altBases = ArrayUtils.addAll(altBases, nextVC.getAlternateAllele(0).getBases()); int iii = 0; if (refBases.length == altBases.length) { // insertion + deletion of same length creates an MNP --> trim common prefix bases off the beginning of the allele while (iii < refBases.length && refBases[iii] == altBases[iii]) { iii++; } if (iii == refBases.length) { // we've become a null allele, such as with CA/C + A/AA -> CA/CA => after trimming there's nothing left // so return a null variant context so we can eliminate the variants from consideration return null; } } final Allele refAllele = Allele.create(ArrayUtils.subarray(refBases, iii, refBases.length), true); final Allele altAllele = Allele.create(ArrayUtils.subarray(altBases, iii, altBases.length), false); return new VariantContextBuilder("merged", thisVC.getChr(), thisVC.getStart() + iii, nextVC.getEnd(), Arrays.asList(refAllele, altAllele)).make(); }
From source file:org.broadinstitute.gatk.utils.activeregion.BandPassActivityProfileUnitTest.java
private double[] bandPassInOnePass(final BandPassActivityProfile profile, final double[] activeProbArray) { final double[] bandPassProbArray = new double[activeProbArray.length]; // apply the band pass filter for activeProbArray into filteredProbArray final double[] GaussianKernel = profile.getKernel(); for (int iii = 0; iii < activeProbArray.length; iii++) { final double[] kernel = ArrayUtils.subarray(GaussianKernel, Math.max(profile.getFilteredSize() - iii, 0), Math.min(GaussianKernel.length, profile.getFilteredSize() + activeProbArray.length - iii)); final double[] activeProbSubArray = ArrayUtils.subarray(activeProbArray, Math.max(0, iii - profile.getFilteredSize()), Math.min(activeProbArray.length, iii + profile.getFilteredSize() + 1)); bandPassProbArray[iii] = dotProduct(activeProbSubArray, kernel); }/*from w w w .jav a2s . c om*/ return bandPassProbArray; }
From source file:org.broadinstitute.gatk.utils.haplotype.Haplotype.java
@Requires({ "refInsertLocation >= 0" }) public Haplotype insertAllele(final Allele refAllele, final Allele altAllele, final int refInsertLocation, final int genomicInsertLocation) { // refInsertLocation is in ref haplotype offset coordinates NOT genomic coordinates final int haplotypeInsertLocation = ReadUtils.getReadCoordinateForReferenceCoordinate( alignmentStartHapwrtRef, cigar, refInsertLocation, ReadUtils.ClippingTail.RIGHT_TAIL, true); final byte[] myBases = this.getBases(); if (haplotypeInsertLocation == -1 || haplotypeInsertLocation + refAllele.length() >= myBases.length) { // desired change falls inside deletion so don't bother creating a new haplotype return null; }// w ww. j av a2s.co m byte[] newHaplotypeBases = new byte[] {}; newHaplotypeBases = ArrayUtils.addAll(newHaplotypeBases, ArrayUtils.subarray(myBases, 0, haplotypeInsertLocation)); // bases before the variant newHaplotypeBases = ArrayUtils.addAll(newHaplotypeBases, altAllele.getBases()); // the alt allele of the variant newHaplotypeBases = ArrayUtils.addAll(newHaplotypeBases, ArrayUtils.subarray(myBases, haplotypeInsertLocation + refAllele.length(), myBases.length)); // bases after the variant return new Haplotype(newHaplotypeBases); }
From source file:org.broadinstitute.sting.utils.activeregion.ActivityProfile.java
/** * Band pass this ActivityProfile, producing a new profile that's band pass filtered * @return a new ActivityProfile that's the band-pass filtered version of this profile *//* w w w.j a v a2 s .co m*/ public ActivityProfile bandPassFilter() { final Double[] activeProbArray = isActiveList.toArray(new Double[isActiveList.size()]); final Double[] filteredProbArray = new Double[activeProbArray.length]; if (!presetRegions) { for (int iii = 0; iii < activeProbArray.length; iii++) { final Double[] kernel = (Double[]) ArrayUtils.subarray(GaussianKernel, Math.max(FILTER_SIZE - iii, 0), Math.min(GaussianKernel.length, FILTER_SIZE + activeProbArray.length - iii)); final Double[] activeProbSubArray = (Double[]) ArrayUtils.subarray(activeProbArray, Math.max(0, iii - FILTER_SIZE), Math.min(activeProbArray.length, iii + FILTER_SIZE + 1)); filteredProbArray[iii] = MathUtils.dotProduct(activeProbSubArray, kernel); } } return new ActivityProfile(parser, presetRegions, Arrays.asList(filteredProbArray), regionStartLoc); }
From source file:org.broadinstitute.sting.utils.haplotype.Haplotype.java
@Requires({ "refInsertLocation >= 0" }) public Haplotype insertAllele(final Allele refAllele, final Allele altAllele, final int refInsertLocation, final int genomicInsertLocation) { // refInsertLocation is in ref haplotype offset coordinates NOT genomic coordinates final int haplotypeInsertLocation = ReadUtils.getReadCoordinateForReferenceCoordinate( alignmentStartHapwrtRef, cigar, refInsertLocation, ReadUtils.ClippingTail.RIGHT_TAIL, true); final byte[] myBases = this.getBases(); if (haplotypeInsertLocation == -1 || haplotypeInsertLocation + refAllele.length() >= myBases.length) { // desired change falls inside deletion so don't bother creating a new haplotype return null; }//from ww w .java 2 s . c o m byte[] newHaplotypeBases = new byte[] {}; newHaplotypeBases = ArrayUtils.addAll(newHaplotypeBases, ArrayUtils.subarray(myBases, 0, haplotypeInsertLocation)); // bases before the variant newHaplotypeBases = ArrayUtils.addAll(newHaplotypeBases, altAllele.getBases()); // the alt allele of the variant newHaplotypeBases = ArrayUtils.addAll(newHaplotypeBases, ArrayUtils.subarray(myBases, haplotypeInsertLocation + refAllele.length(), myBases.length)); // bases after the variant return new Haplotype(newHaplotypeBases, new Event(refAllele, altAllele, genomicInsertLocation)); }
From source file:org.broadinstitute.sting.utils.Haplotype.java
@Requires({ "refInsertLocation >= 0" }) public Haplotype insertAllele(final Allele refAllele, final Allele altAllele, final int refInsertLocation) { // refInsertLocation is in ref haplotype offset coordinates NOT genomic coordinates final int haplotypeInsertLocation = ReadUtils.getReadCoordinateForReferenceCoordinate( alignmentStartHapwrtRef, cigar, refInsertLocation, ReadUtils.ClippingTail.RIGHT_TAIL, true); if (haplotypeInsertLocation == -1 || haplotypeInsertLocation + refAllele.length() >= bases.length) { // desired change falls inside deletion so don't bother creating a new haplotype return null; }//from w w w .jav a2s. co m byte[] newHaplotypeBases = new byte[] {}; newHaplotypeBases = ArrayUtils.addAll(newHaplotypeBases, ArrayUtils.subarray(bases, 0, haplotypeInsertLocation)); // bases before the variant newHaplotypeBases = ArrayUtils.addAll(newHaplotypeBases, altAllele.getBases()); // the alt allele of the variant newHaplotypeBases = ArrayUtils.addAll(newHaplotypeBases, ArrayUtils.subarray(bases, haplotypeInsertLocation + refAllele.length(), bases.length)); // bases after the variant return new Haplotype(newHaplotypeBases); }
From source file:org.brushingbits.jnap.persistence.hibernate.DynaQueryBuilder.java
Object[] getPropertyValues(int size) { if ((propertyValueIndex + size) <= this.queryParams.length) { Object[] values = ArrayUtils.subarray(this.queryParams, propertyValueIndex, propertyValueIndex + size); propertyValueIndex += size;//from w w w . j a v a 2 s . c o m return values; } else { throw new QueryException( format("The number of parameters ({0}) does not satisfy " + "DynaQuery expression", Integer.toString(this.queryParams.length)), this.dynaQuery); } }