Search in sources :

Example 1 with GeneType

use of io.repseq.core.GeneType in project mixcr by milaboratory.

the class ActionExportAlignmentsPretty method outputVerbose.

public void outputVerbose(PrintStream output, final VDJCAlignments alignments) {
    output.println(">>> Read ids: " + Arrays.toString(alignments.getReadIds()).replace("[", "").replace("]", ""));
    output.println();
    output.println(">>> Target sequences (input sequences):");
    output.println();
    for (int i = 0; i < alignments.numberOfTargets(); i++) {
        output.println("Sequence" + i + ":");
        final VDJCPartitionedSequence partitionedTarget = alignments.getPartitionedTarget(i);
        printGeneFeatures(new Filter<GeneFeature>() {

            @Override
            public boolean accept(GeneFeature object) {
                return partitionedTarget.getPartitioning().isAvailable(object);
            }
        }, output, "Contains features: ");
        output.println();
        output.print(new NSequenceWithQualityPrintHelper(alignments.getTarget(i), LINE_OFFSET, LINE_LENGTH));
    }
    if (alignments.numberOfTargets() > 1) {
        // Printing a set of available gene features for a full read
        output.println(">>> Gene features that can be extracted from this paired-read: ");
        printGeneFeatures(new Filter<GeneFeature>() {

            @Override
            public boolean accept(GeneFeature object) {
                return alignments.getFeature(object) != null;
            }
        }, output, "");
    }
    output.println();
    for (GeneType geneType : GeneType.values()) {
        output.println(">>> Alignments with " + geneType.getLetter() + " gene:");
        output.println();
        boolean exists = false;
        VDJCHit[] hits = alignments.getHits(geneType);
        if (hits.length > 0) {
            hits = actionParameters.isOnlyTop() ? new VDJCHit[] { hits[0] } : hits;
            for (VDJCHit hit : hits) {
                exists = true;
                output.println(hit.getGene().getName() + " (total score = " + hit.getScore() + ")");
                for (int i = 0; i < alignments.numberOfTargets(); i++) {
                    Alignment<NucleotideSequence> alignment = hit.getAlignment(i);
                    if (alignment == null)
                        continue;
                    output.println("Alignment of Sequence" + i + " (score = " + (alignment == null ? "NaN" : alignment.getScore()) + "):");
                    if (alignment != null) {
                        for (AlignmentHelper subHelper : alignment.getAlignmentHelper().split(LINE_LENGTH, LINE_OFFSET)) {
                            output.println(subHelper.toStringWithSeq2Quality(alignments.getTarget(i).getQuality()));
                            output.println();
                        }
                        if (actionParameters.printGeneSequence()) {
                            output.println("Gene sequence:");
                            output.println(alignment.getSequence1());
                            output.println();
                        }
                    }
                }
            }
        }
        if (!exists) {
            output.println("No hits.");
            output.println();
        }
    }
    char[] ll = new char[94];
    Arrays.fill(ll, '=');
    output.println(ll);
    output.println();
}
Also used : GeneFeature(io.repseq.core.GeneFeature) MultiAlignmentHelper(com.milaboratory.core.alignment.MultiAlignmentHelper) AlignmentHelper(com.milaboratory.core.alignment.AlignmentHelper) NSequenceWithQualityPrintHelper(com.milaboratory.util.NSequenceWithQualityPrintHelper) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) GeneType(io.repseq.core.GeneType)

Example 2 with GeneType

use of io.repseq.core.GeneType in project mixcr by milaboratory.

the class VDJCAlignmentsReader method initGeneFeatureReferencesFrom.

/**
 * Produce reader that uses the same reference for geneFeatures.
 *
 * @param reader     target reader
 * @param parameters parameters to take reference from
 */
public static void initGeneFeatureReferencesFrom(VDJCAlignmentsReader reader, VDJCAlignerParameters parameters) {
    Map<GeneFeature, GeneFeature> featureRefs = new HashMap<>();
    for (GeneType gt : GeneType.VDJC_REFERENCE) {
        GeneFeature f = parameters.getFeatureToAlign(gt);
        featureRefs.put(f, f);
    }
    reader.init(featureRefs);
}
Also used : GeneFeature(io.repseq.core.GeneFeature) HashMap(java.util.HashMap) GeneType(io.repseq.core.GeneType)

Example 3 with GeneType

use of io.repseq.core.GeneType in project mixcr by milaboratory.

the class CloneAccumulator method calculateScores.

public void calculateScores(CloneFactoryParameters parameters) {
    for (GeneType geneType : GeneType.VJC_REFERENCE) {
        VJCClonalAlignerParameters vjcParameters = parameters.getVJCParameters(geneType);
        if (vjcParameters == null)
            continue;
        TObjectFloatHashMap<VDJCGeneId> accumulatorGeneIds = geneScores.get(geneType);
        if (accumulatorGeneIds == null)
            continue;
        TObjectFloatIterator<VDJCGeneId> iterator = accumulatorGeneIds.iterator();
        float maxScore = 0;
        while (iterator.hasNext()) {
            iterator.advance();
            float value = iterator.value();
            if (value > maxScore)
                maxScore = value;
        }
        maxScore = maxScore * vjcParameters.getRelativeMinScore();
        iterator = accumulatorGeneIds.iterator();
        while (iterator.hasNext()) {
            iterator.advance();
            if (maxScore > iterator.value())
                iterator.remove();
            else
                iterator.setValue(Math.round(iterator.value() * 10f / coreCount) / 10f);
        }
    }
}
Also used : GeneType(io.repseq.core.GeneType) VDJCGeneId(io.repseq.core.VDJCGeneId)

Example 4 with GeneType

use of io.repseq.core.GeneType 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()));
    }
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) GeneType(io.repseq.core.GeneType) PairedRead(com.milaboratory.core.io.sequence.PairedRead) Test(org.junit.Test)

Example 5 with GeneType

use of io.repseq.core.GeneType 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()));
            }
        }
    }
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) GeneType(io.repseq.core.GeneType) PairedRead(com.milaboratory.core.io.sequence.PairedRead) Test(org.junit.Test)

Aggregations

GeneType (io.repseq.core.GeneType)25 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)14 GeneFeature (io.repseq.core.GeneFeature)8 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)7 VDJCGene (io.repseq.core.VDJCGene)5 PairedRead (com.milaboratory.core.io.sequence.PairedRead)4 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)4 EnumMap (java.util.EnumMap)4 Test (org.junit.Test)4 Alignment (com.milaboratory.core.alignment.Alignment)3 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)3 Chains (io.repseq.core.Chains)3 ReferencePoint (io.repseq.core.ReferencePoint)3 VDJCGeneId (io.repseq.core.VDJCGeneId)3 ArrayList (java.util.ArrayList)3 MultiAlignmentHelper (com.milaboratory.core.alignment.MultiAlignmentHelper)2 AlignmentHit (com.milaboratory.core.alignment.batch.AlignmentHit)2 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2