use of com.milaboratory.core.clustering.Cluster in project mixcr by milaboratory.
the class CloneAssembler method runClustering.
public void runClustering() {
if (clusteredClonesAccumulators != null)
throw new IllegalStateException("Already clustered.");
if (!preClusteringDone)
throw new IllegalStateException("No preclustering done.");
@SuppressWarnings("unchecked") Clustering clustering = new Clustering(cloneList, new SequenceExtractor<CloneAccumulator, NucleotideSequence>() {
@Override
public NucleotideSequence getSequence(CloneAccumulator object) {
return object.getSequence().getConcatenated().getSequence();
}
}, new CloneClusteringStrategy(parameters.getCloneClusteringParameters(), this));
this.progressReporter = clustering;
List<Cluster<CloneAccumulator>> clusters = clustering.performClustering();
clusteredClonesAccumulators = new ArrayList<>(clusters.size());
idMapping = new TIntIntHashMap(cloneList.size());
for (int i = 0; i < clusters.size(); ++i) {
final Cluster<CloneAccumulator> cluster = clusters.get(i);
final CloneAccumulator head = cluster.getHead();
idMapping.put(head.getCloneIndex(), i);
head.setCloneIndex(i);
final int k = ~i;
cluster.processAllChildren(new TObjectProcedure<Cluster<CloneAccumulator>>() {
@Override
public boolean execute(Cluster<CloneAccumulator> object) {
onClustered(head, object.getHead());
if (parameters.isAddReadsCountOnClustering())
head.mergeCounts(object.getHead());
idMapping.put(object.getHead().getCloneIndex(), k);
return true;
}
});
clusteredClonesAccumulators.add(head);
}
this.progressReporter = null;
}
Aggregations