use of io.repseq.core.GeneType in project mixcr by milaboratory.
the class CloneAccumulator method accumulate.
public synchronized void accumulate(ClonalSequence data, VDJCAlignments alignment, boolean mapped) {
if (!mapped) {
// Core sequence accumulation
coreCount += alignment.getNumberOfReads();
// Accumulate information about V-D-J alignments only for strictly clustered reads
// (only for core clonotypes members)
float score;
// Accumulate information about all genes
for (GeneType geneType : GeneType.VJC_REFERENCE) {
TObjectFloatHashMap<VDJCGeneId> geneScores = this.geneScores.get(geneType);
VDJCHit[] hits = alignment.getHits(geneType);
if (hits.length == 0)
continue;
if (geneScores == null)
this.geneScores.put(geneType, geneScores = new TObjectFloatHashMap<>());
for (VDJCHit hit : hits) {
// Calculating sum of natural logarithms of scores
score = hit.getScore();
geneScores.adjustOrPutValue(hit.getGene().getId(), score, score);
}
}
aggregator.aggregate(data.getConcatenated().getQuality());
} else
// Mapped sequence accumulation
mappedCount += alignment.getNumberOfReads();
}
use of io.repseq.core.GeneType in project mixcr by milaboratory.
the class PartialAlignmentsAssemblerTest method test2a.
@Test
public void test2a() throws Exception {
RandomUtil.reseedThreadLocal(47);
final InputTestData input = createTestData(47);
final NucleotideSequence reference = input.reference;
final EnumMap<GeneType, int[]> refPositions = input.refPositions;
NucleotideSequence left1 = reference.getRange(refPositions.get(Diversity)[0] - 85, refPositions.get(Diversity)[0] + 10);
final char[] chars = left1.toString().toCharArray();
chars[3] = 'a';
left1 = new NucleotideSequence(new String(chars));
PairedRead[] data = { createPair(0, left1, 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] - 30), 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 io.repseq.core.GeneType in project mixcr by milaboratory.
the class PartialAlignmentsAssemblerTest method createTestData.
public static InputTestData createTestData(long seed) throws Exception {
EnumMap<GeneType, String> geneNames = new EnumMap<GeneType, String>(GeneType.class) {
{
put(Variable, "TRBV20-1*00");
put(Diversity, "TRBD2*00");
put(Joining, "TRBJ2-6*00");
put(Constant, "TRBC2*00");
}
};
// config
RandomGenerator rnd = RandomUtil.getThreadLocalRandom();
rnd.setSeed(seed);
final VDJCAlignerParameters defaultFeatures = VDJCParametersPresets.getByName("default");
defaultFeatures.getVAlignerParameters().setGeneFeatureToAlign(VRegion);
defaultFeatures.getDAlignerParameters().setGeneFeatureToAlign(DRegion);
defaultFeatures.getJAlignerParameters().setGeneFeatureToAlign(JRegion);
// used alleles
EnumMap<GeneType, VDJCGene> genes = new EnumMap<>(GeneType.class);
// germline parts of sequences
EnumMap<GeneType, NucleotideSequence> germlineRegions = gtMap();
// left, right cut of germline
EnumMap<GeneType, int[]> germlineCuts = gtMap();
// begin, end positions in assembled sequence
EnumMap<GeneType, int[]> refPositions = gtMap();
// single assembled sequence
SequenceBuilder<NucleotideSequence> referenceBuilder = NucleotideSequence.ALPHABET.createBuilder();
NucleotideSequence VDJunction = TestUtil.randomSequence(NucleotideSequence.ALPHABET, 3, 10);
NucleotideSequence DJJunction = TestUtil.randomSequence(NucleotideSequence.ALPHABET, 3, 10);
for (GeneType gt : GeneType.VDJC_REFERENCE) {
VDJCGene gene = VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").get(geneNames.get(gt));
NucleotideSequence seq = gene.getFeature(defaultFeatures.getFeatureToAlign(gt));
int[] cuts = null;
switch(gt) {
case Variable:
cuts = new int[] { 0, rnd.nextInt(gene.getFeature(GermlineVCDR3Part).size() - 5) };
break;
case Diversity:
cuts = new int[] { rnd.nextInt(seq.size() / 3), rnd.nextInt(seq.size() / 3) };
break;
case Joining:
cuts = new int[] { rnd.nextInt(gene.getFeature(GermlineJCDR3Part).size() - 5), 0 };
break;
case Constant:
cuts = new int[] { 0, rnd.nextInt(seq.size() / 2) };
break;
}
NucleotideSequence gSeq = seq.getRange(cuts[0], seq.size() - cuts[1]);
int[] positions = new int[2];
positions[0] = referenceBuilder.size();
referenceBuilder.append(gSeq);
positions[1] = referenceBuilder.size();
if (gt == Variable)
referenceBuilder.append(VDJunction);
if (gt == Diversity)
referenceBuilder.append(DJJunction);
genes.put(gt, gene);
germlineCuts.put(gt, cuts);
germlineRegions.put(gt, gSeq);
refPositions.put(gt, positions);
}
NucleotideSequence VJJunction = NucleotideSequence.ALPHABET.createBuilder().append(VDJunction).append(germlineRegions.get(Diversity)).append(DJJunction).createAndDestroy();
NucleotideSequence reference = referenceBuilder.createAndDestroy();
return new InputTestData(genes, germlineRegions, germlineCuts, refPositions, VDJunction, DJJunction, reference, VJJunction);
}
use of io.repseq.core.GeneType in project mixcr by milaboratory.
the class PartialAlignmentsAssemblerTest method test1.
// @Test
// public void testMaxAllele() throws Exception {
// final LociLibrary ll = LociLibraryManager.getDefault().getLibrary("mi");
// final Locus locus = Locus.TRB;
//
// for (GeneFeature feature : new GeneFeature[]{VRegionWithP, DRegion, JRegionWithP, CRegion}) {
// Allele maxAllele = null;
// for (Allele allele : ll.getAllAlleles()) {
// if (allele.getLocusContainer().getSpeciesAndLocus().taxonId != Species.HomoSapiens)
// continue;
// if (!allele.isFunctional())
// continue;
// if (allele.getLocus() != locus)
// continue;
// if (maxAllele == null && allele.getFeature(feature) != null)
// maxAllele = allele;
// if (allele.getFeature(feature) != null && allele.getFeature(feature).size() > maxAllele.getFeature(feature).size())
// maxAllele = allele;
// }
//
// System.out.println(maxAllele.getName() + " Size: " + maxAllele.getFeature(feature).size());
// }
// }
@Test
public void test1() throws Exception {
final InputTestData input = createTestData();
final NucleotideSequence reference = input.reference;
final EnumMap<GeneType, int[]> refPositions = input.refPositions;
PairedRead[] data = { createPair(0, reference.getRange(refPositions.get(Variable)[1] - 85, refPositions.get(Variable)[1] + 15), reference.getRange(refPositions.get(Joining)[1] - 20, refPositions.get(Joining)[1] + 80).getReverseComplement()), createPair(1, reference.getRange(refPositions.get(Variable)[1] - 186, refPositions.get(Variable)[1] - 86), reference.getRange(refPositions.get(Variable)[1] - 10, refPositions.get(Variable)[1] + 102).getReverseComplement()) };
final TestResult testResult = processData(data, input);
for (VDJCAlignments al : testResult.assembled) {
MiXCRTestUtils.printAlignment(al);
}
}
use of io.repseq.core.GeneType in project mixcr by milaboratory.
the class MiXCRTestUtils method assertAlignments.
public static void assertAlignments(VDJCAlignments alignments) {
for (GeneType gt : GeneType.VDJC_REFERENCE) {
for (VDJCHit hit : alignments.getHits(gt)) {
for (int targetIndex = 0; targetIndex < alignments.numberOfTargets(); targetIndex++) {
Alignment<NucleotideSequence> al = hit.getAlignment(targetIndex);
if (al == null)
continue;
NucleotideSequence sequence = alignments.getTarget(targetIndex).getSequence();
AlignerTest.assertAlignment(al, sequence);
}
}
}
}
Aggregations