Search in sources :

Example 6 with NucleotideSequence

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);
        }
    }
}
Also used : GeneFeature(io.repseq.core.GeneFeature) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCGene(io.repseq.core.VDJCGene)

Example 7 with NucleotideSequence

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;
}
Also used : SequenceQuality(com.milaboratory.core.sequence.SequenceQuality) NSequenceWithQuality(com.milaboratory.core.sequence.NSequenceWithQuality) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) ClonalSequence(com.milaboratory.mixcr.basictypes.ClonalSequence)

Example 8 with NucleotideSequence

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;
}
Also used : Cluster(com.milaboratory.core.clustering.Cluster) Clustering(com.milaboratory.core.clustering.Clustering) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) TIntIntHashMap(gnu.trove.map.hash.TIntIntHashMap)

Example 9 with NucleotideSequence

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()));
    }
}
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 10 with NucleotideSequence

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()));
            }
        }
    }
}
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

NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)81 Test (org.junit.Test)32 Range (com.milaboratory.core.Range)19 VDJCGene (io.repseq.core.VDJCGene)15 GeneType (io.repseq.core.GeneType)14 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)13 GeneFeature (io.repseq.core.GeneFeature)9 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)8 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)8 ReferencePoint (io.repseq.core.ReferencePoint)7 VDJCLibrary (io.repseq.core.VDJCLibrary)7 ArrayList (java.util.ArrayList)7 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)6 AlignmentHit (com.milaboratory.core.alignment.batch.AlignmentHit)5 PairedRead (com.milaboratory.core.io.sequence.PairedRead)5 AminoAcidSequence (com.milaboratory.core.sequence.AminoAcidSequence)5 Path (java.nio.file.Path)5 Alignment (com.milaboratory.core.alignment.Alignment)4 Pattern (java.util.regex.Pattern)4 AlignmentHelper (com.milaboratory.core.alignment.AlignmentHelper)3