use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class IOUtil method registerGeneReferences.
public static void registerGeneReferences(PrimitivI input, List<VDJCGene> genes, HasFeatureToAlign featuresToAlign) {
// Putting genes references and feature sequences to be serialized/deserialized as references
for (VDJCGene gene : genes) {
input.putKnownReference(gene);
// Also put sequences of certain gene features of genes as known references if required
if (featuresToAlign != null) {
GeneFeature featureToAlign = featuresToAlign.getFeatureToAlign(gene.getGeneType());
if (featureToAlign == null)
continue;
NucleotideSequence featureSequence = gene.getFeature(featureToAlign);
if (featureSequence == null)
continue;
input.putKnownReference(featureSequence);
}
}
}
use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class CloneAccumulator method rebuildClonalSequence.
public void rebuildClonalSequence() {
SequenceQuality newQuality = aggregator.getQuality();
final NSequenceWithQuality[] updated = new NSequenceWithQuality[sequence.size()];
int pointer = 0;
for (int i = 0; i < updated.length; i++) {
final NucleotideSequence s = this.sequence.get(i).getSequence();
updated[i] = new NSequenceWithQuality(s, newQuality.getRange(pointer, pointer + s.size()));
pointer += s.size();
}
sequence = new ClonalSequence(updated);
return;
}
use of com.milaboratory.core.sequence.NucleotideSequence 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;
}
use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class PartialAlignmentsAssemblerTest method test2.
@Test
public void test2() throws Exception {
RandomUtil.reseedThreadLocal(47);
final InputTestData input = createTestData(47);
final NucleotideSequence reference = input.reference;
final EnumMap<GeneType, int[]> refPositions = input.refPositions;
PairedRead[] data = { createPair(0, reference.getRange(refPositions.get(Diversity)[0] - 85, refPositions.get(Diversity)[0] + 10), reference.getRange(refPositions.get(Diversity)[1], refPositions.get(Diversity)[1] + 85).getReverseComplement()), createPair(1, reference.getRange(refPositions.get(Diversity)[0] - 135, refPositions.get(Diversity)[0] - 70), reference.getRange(refPositions.get(Diversity)[0] - 8, refPositions.get(Diversity)[0] + 85).getReverseComplement()) };
final TestResult testResult = processData(data, input);
for (VDJCAlignments al : testResult.assembled) {
MiXCRTestUtils.printAlignment(al);
// System.out.println(input.VJJunction);
// System.out.println(al.getFeature(GeneFeature.VJJunction).getSequence());
Assert.assertTrue(input.VJJunction.toString().contains(al.getFeature(GeneFeature.VJJunction).getSequence().toString()));
}
}
use of com.milaboratory.core.sequence.NucleotideSequence in project mixcr by milaboratory.
the class PartialAlignmentsAssemblerTest method test3.
@Test
public void test3() throws Exception {
for (int i = 0; i < 100; i++) {
RandomUtil.reseedThreadLocal(i);
// System.out.println(i);
final InputTestData input = createTestData(i);
final NucleotideSequence reference = input.reference;
final EnumMap<GeneType, int[]> refPositions = input.refPositions;
PairedRead[] data = { createPair(0, reference.getRange(refPositions.get(Diversity)[0] - 85, refPositions.get(Diversity)[0] + 10), reference.getRange(refPositions.get(Diversity)[1], refPositions.get(Diversity)[1] + 85).getReverseComplement()), createPair(1, reference.getRange(refPositions.get(Diversity)[0] - 135, refPositions.get(Diversity)[0] - 70), reference.getRange(refPositions.get(Diversity)[0] - 8, refPositions.get(Diversity)[0] + 85).getReverseComplement()) };
final TestResult testResult = processData(data, input);
for (VDJCAlignments al : testResult.assembled) {
// printAlignment(al);
if (al.numberOfTargets() == 1) {
// System.out.println(input.VJJunction);
// System.out.println(al.getFeature(GeneFeature.VJJunction).getSequence());
Assert.assertTrue(input.VJJunction.toString().contains(al.getFeature(GeneFeature.VJJunction).getSequence().toString()));
}
}
}
}
Aggregations