Separates motifs via clustering.

@param clusterTSIdx The index.
@param sameLenMotifs the motif groups.
@return same length motifs.
768792
private ArrayList<SameLengthMotifs> SeparateMotifsByClustering(ArrayList<String[]> clusterTSIdx,
      SameLengthMotifs sameLenMotifs) {
    ArrayList<SameLengthMotifs> newResult = new ArrayList<SameLengthMotifs>();
    if (clusterTSIdx.size() > 1) {
      ArrayList<SAXMotif> subsequences = sameLenMotifs.getSameLenMotifs();
      for (String[] idxesInCluster : clusterTSIdx) {
        SameLengthMotifs newIthSLM = new SameLengthMotifs();
        ArrayList<SAXMotif> sameLenSS = new ArrayList<SAXMotif>();
        int minL = sameLenMotifs.getMinMotifLen();
        int maxL = sameLenMotifs.getMaxMotifLen();

        for (String i : idxesInCluster) {
          SAXMotif ssI = subsequences.get(Integer.parseInt(i));
          int len = ssI.getPos().getEnd() - ssI.getPos().getStart();
          if (len < minL) {
            minL = len;
          }
          else if (len > maxL) {
            maxL = len;
          }
          sameLenSS.add(ssI);
        }

        newIthSLM.setSameLenMotifs(sameLenSS);
        newIthSLM.setMaxMotifLen(maxL);
        newIthSLM.setMinMotifLen(minL);
        newResult.add(newIthSLM);
      }
    }
    else {
      newResult.add(sameLenMotifs);
    }

    return newResult;
  }
472451
public double[] aggregate(double[][] descriptors) throws Exception {
		if (descriptors.length > 0) {
			if (descriptors[0].length != descriptorLength) {
				throw new Exception("Descriptor length is incompatible with codebook centroid length!");
			}
		}
		return aggregateInternal(descriptors);
	}
650543
public static <T extends BaseObject<Long>> List<Long> convert2IdList(
            List<T> enTs) {
        List<Long> result = new ArrayList<Long>();

        if (enTs == null) {
            return result;
        }

        for (T t : enTs) {
            result.add(t.getId());
        }

        return result;
    }
717102
protected void matchPointsToClusters(List<double[]> points) {
		sumDistance = 0;
		for (int i = 0; i < points.size(); i++) {
			double[]p = points.get(i);

			// find the cluster which is closest to the point
			int bestCluster = findBestMatch(p);

			// sum up all the points which are members of this cluster
			double[] c = workClusters.get(bestCluster);
			for (int j = 0; j < c.length; j++) {
				c[j] += p[j];
			}
			memberCount.data[bestCluster]++;
			labels.data[i] = bestCluster;
			sumDistance += bestDistance;
		}
	}
878663
public Map<Integer, Set<Integer>> getClusters(double cutoff) {

		if (dendrogram==null) {
			clusterIt();
		}

		Map<Integer, Set<Integer>> clusters = new TreeMap<Integer, Set<Integer>>();

		int clusterId = 1;

		for (int i=0;i<numItems-1;i++) {

			if (isWithinCutoff(i, cutoff)) {

				//int containingClusterId = getContainingCluster(clusters, dendrogram[i]);

				int firstClusterId = -1;
				int secondClusterId = -1;
				for (int cId:clusters.keySet()) {
					Set<Integer> members = clusters.get(cId);

					if (members.contains(dendrogram[i].getFirst())) {
						firstClusterId = cId;
					}
					if (members.contains(dendrogram[i].getSecond())) {
						secondClusterId = cId;
					}
				}


				if (firstClusterId==-1 && secondClusterId==-1) {
					// neither member is in a cluster yet, let's assign a new cluster and put them both in
					Set<Integer> members = new TreeSet<Integer>();
					members.add(dendrogram[i].getFirst());
					members.add(dendrogram[i].getSecond());
					clusters.put(clusterId, members);
					clusterId++;
				} else if (firstClusterId!=-1 && secondClusterId==-1) {
					// first member was in firstClusterId already, we add second
					clusters.get(firstClusterId).add(dendrogram[i].getSecond());
				} else if (secondClusterId!=-1 && firstClusterId==-1) {
					// second member was in secondClusterId already, we add first
					clusters.get(secondClusterId).add(dendrogram[i].getFirst());
				} else {
					// both were in different clusters already
					// we need to join them: necessarily one must be of size 1 and the other of size>=1
					Set<Integer> firstCluster = clusters.get(firstClusterId);
					Set<Integer> secondCluster = clusters.get(secondClusterId);
					if (firstCluster.size()<secondCluster.size()) {
						logger.debug("Joining cluster "+firstClusterId+" to cluster "+secondClusterId);
						// we join first onto second
						for (int member : firstCluster) {
							secondCluster.add(member);
						}
						clusters.remove(firstClusterId);
					} else {
						logger.debug("Joining cluster "+secondClusterId+" to cluster "+firstClusterId);
						// we join second onto first
						for (int member : secondCluster) {
							firstCluster.add(member);
						}
						clusters.remove(secondClusterId);
					}
				}

				logger.debug("Within cutoff:     "+dendrogram[i]);

			} else {

				logger.debug("Not within cutoff: "+dendrogram[i]);

			}
		}

		// reassigning cluster numbers by creating a new map (there can be gaps in the numbering if cluster-joining happened)
		Map<Integer,Set<Integer>> finalClusters = new TreeMap<Integer, Set<Integer>>();
		int newClusterId = 1;
		for (int oldClusterId:clusters.keySet()) {
			finalClusters.put(newClusterId, clusters.get(oldClusterId));
			newClusterId++;
		}

		// anything not clustered is assigned to a singleton cluster (cluster with one member)
		for (int i=0;i<numItems;i++) {
			boolean isAlreadyClustered = false;
			for (Set<Integer> cluster:finalClusters.values()) {
				if (cluster.contains(i)) {
					isAlreadyClustered = true;
					break;
				}
			}
			if (!isAlreadyClustered) {
				Set<Integer> members = new TreeSet<Integer>();
				members.add(i);
				finalClusters.put(newClusterId, members);
				newClusterId++;
			}

		}

		logger.debug("Clusters: \n"+clustersToString(finalClusters));

		return finalClusters;
	}
136071
void setClusterUserIndex(int cluster, int index, int value) {
		int i = getClusterIndex_(cluster);
		AttributeStreamOfInt32 stream = m_clusterIndices.get(index);
		if (stream.size() <= i)
			stream.resize(m_clusterData.size(), -1);

		stream.write(i, value);
	}
1187416
public static List<Structure> divideStructure(CeSymmResult symmetry)
			throws StructureException {

		if (!symmetry.isRefined())
			throw new IllegalArgumentException("The symmetry result "
					+ "is not refined, repeats cannot be defined");

		int order = symmetry.getMultipleAlignment().size();
		Atom[] atoms = symmetry.getAtoms();
		Set<Group> allGroups = StructureTools.getAllGroupsFromSubset(atoms, GroupType.HETATM);
		List<StructureIdentifier> repeatsId = symmetry.getRepeatsID();
		List<Structure> repeats = new ArrayList<Structure>(order);

		// Create new structure containing the repeat atoms
		for (int i = 0; i < order; i++) {

			Structure s = new StructureImpl();
			s.addModel(new ArrayList<Chain>(1));
			s.setStructureIdentifier(repeatsId.get(i));

			Block align = symmetry.getMultipleAlignment().getBlock(0);

			// Get the start and end of the repeat
			// Repeats are always sequential blocks
			int res1 = align.getStartResidue(i);
			int res2 = align.getFinalResidue(i);

			// All atoms from the repeat, used for ligand search
			// AA have an average of 8.45 atoms, so guess capacity with that
			List<Atom> repeat = new ArrayList<>(Math.max(9*(res2-res1+1),9));
			// speedy chain lookup
			Chain prevChain = null;
			for(int k=res1;k<=res2; k++) {
				Group g = atoms[k].getGroup();
				prevChain = StructureTools.addGroupToStructure(s, g, 0, prevChain,true);
				repeat.addAll(g.getAtoms());
			}


			List<Group> ligands = StructureTools.getLigandsByProximity(
					allGroups,
					repeat.toArray(new Atom[repeat.size()]),
					StructureTools.DEFAULT_LIGAND_PROXIMITY_CUTOFF);

			logger.warn("Adding {} ligands to {}",ligands.size(), symmetry.getMultipleAlignment().getStructureIdentifier(i));
			for( Group ligand : ligands) {
				prevChain = StructureTools.addGroupToStructure(s, ligand, 0, prevChain,true);
			}

			repeats.add(s);
		}
		return repeats;
	}
643058
public int sharedSegments(Triangle t2) {
		int counter = 0;

		if(a.equals(t2.a)) {
			counter++;
		}
		if(a.equals(t2.b)) {
			counter++;
		}
		if(a.equals(t2.c)) {
			counter++;
		}
		if(b.equals(t2.a)) {
			counter++;
		}
		if(b.equals(t2.b)) {
			counter++;
		}
		if(b.equals(t2.c)) {
			counter++;
		}
		if(c.equals(t2.a)) {
			counter++;
		}
		if(c.equals(t2.b)) {
			counter++;
		}
		if(c.equals(t2.c)) {
			counter++;
		}

		return counter;
	}
445510
public Assignments cluster(Matrix matrix, Properties props) {
        int endSize = Integer.parseInt(props.getProperty(
                NUM_CLUSTERS_END, DEFAULT_NUM_CLUSTERS_END));
        return cluster(matrix, endSize, props);
    }
1157437
private void getMultiWordSpans(final String[] tokens, final List<WF> wfs,
      final List<ixa.kaflib.Span<WF>> tokenSpans) {
    final Span[] multiWordSpans = this.multiWordMatcher
        .multiWordsToSpans(tokens);
    int counter = 0;
    for (final Span mwSpan : multiWordSpans) {
      final Integer fromIndex = mwSpan.getStart() - counter;
      final Integer toIndex = mwSpan.getEnd() - counter;
      // add to the counter the length of the span removed
      counter = counter + tokenSpans.subList(fromIndex, toIndex).size() - 1;
      // create multiword targets and Span
      final List<WF> wfTargets = wfs
          .subList(mwSpan.getStart(), mwSpan.getEnd());
      final ixa.kaflib.Span<WF> multiWordSpan = KAFDocument
          .newWFSpan(wfTargets);
      // remove the token Spans to be replaced by the multiword span
      tokenSpans.subList(fromIndex, toIndex).clear();
      // add the new Span containing several WFs (multiWordSpan)
      // the counter is used to allow matching the spans to the
      // tokenSpans list indexes
      tokenSpans.add(fromIndex, multiWordSpan);
    }
  }
409428
public static List<RedisClusterNode> sortByLatency(Iterable<RedisClusterNode> clusterNodes) {

        List<RedisClusterNode> ordered = LettuceLists.newList(clusterNodes);
        ordered.sort(LatencyComparator.INSTANCE);
        return ordered;
    }
34486
public int getAggregationDistinctColumnIndex(final int derivedSumIndex) {
        for (Entry<Integer, Integer> entry : aggregationDistinctColumnIndexAndSumColumnIndexes.entrySet()) {
            if (entry.getValue().equals(derivedSumIndex)) {
                return entry.getKey();
            }
        }
        throw new ShardingException("Can not get aggregation distinct column index.");
    }
175105
public static Assignments cluster(Matrix matrix,
                                      int numClusters,
                                      int numRepetitions,
                                      CriterionFunction criterion) {
        return cluster(matrix, numClusters, numRepetitions,
                       new RandomSeed(), criterion);
    }
306678
protected List<PMultipleBind> getMultipleTypeBindList(PType patternType,
			ILexNameToken... patternNames)
	{
		List<PMultipleBind> typeBindList = new Vector<PMultipleBind>();
		typeBindList.add(getMultipleTypeBind(patternType, patternNames));
		return typeBindList;
	}
190647
public static List<RedisClusterNode> sortByClientCount(Iterable<RedisClusterNode> clusterNodes) {

        LettuceAssert.notNull(clusterNodes, "Cluster nodes must not be null");

        List<RedisClusterNode> ordered = LettuceLists.newList(clusterNodes);
        ordered.sort(ClientCountComparator.INSTANCE);
        return ordered;
    }
1203265
int getClusterUserIndex(int cluster, int index) {
		int i = getClusterIndex_(cluster);
		AttributeStreamOfInt32 stream = m_clusterIndices.get(index);
		if (stream.size() <= i)
			return -1;
		return stream.read(i);
	}
876812
def cluster(dset,min_distance,min_cluster_size,prefix=None):
    ''''''
    if prefix==None:
        prefix = nl.suffix(dset,'_clust%d' % min_cluster_size)
    return available_method('cluster')(dset,min_distance,min_cluster_size,prefix)