Search in sources :

Example 21 with VDJCGene

use of io.repseq.core.VDJCGene in project repseqio by repseqio.

the class BasicGGeneModel method create.

@Override
public GGeneGenerator create(RandomGenerator random, VDJCLibrary library) {
    final VDJCGenesGenerator vdjcGenesGenerator = vdjcGenesModel.create(random, library);
    List<VDJCGene> vGenes = vdjcGenesGenerator.genes(GeneType.Variable);
    List<VDJCGene> dGenes = vdjcGenesGenerator.genes(GeneType.Diversity);
    List<VDJCGene> jGenes = vdjcGenesGenerator.genes(GeneType.Joining);
    List<VDJCGene> cGenes = vdjcGenesGenerator.genes(GeneType.Constant);
    final VDJTrimmingGenerator trimmingGenerator = trimmingModel.create(random, vGenes, dGenes, jGenes, cGenes);
    final InsertGenerator vInsertGenerator = vInsertModel.create(random, true, vGenes, dGenes, jGenes, cGenes);
    final InsertGenerator djInsertGenerator = dGenes.isEmpty() ? null : djInsertModel.create(random, false, vGenes, dGenes, jGenes, cGenes);
    return new GGeneGenerator() {

        @Override
        public GGene generate() {
            VDJCGenes vdjcGenes = vdjcGenesGenerator.sample();
            VDJTrimming trimming = trimmingGenerator.sample(vdjcGenes);
            assert !vdjcGenes.isDDefined() || (vdjcGenes.isDDefined() && djInsertGenerator != null);
            NucleotideSequence vInsert;
            NucleotideSequence djInsert;
            if (vdjcGenes.isDDefined()) {
                assert djInsertGenerator != null;
                GGene tempGene = new GGene(null, vdjcGenes, trimming, NucleotideSequence.EMPTY, NucleotideSequence.EMPTY);
                vInsert = vInsertGenerator.generate(tempGene);
                djInsert = djInsertGenerator.generate(tempGene);
            } else {
                GGene tempGene = new GGene(null, vdjcGenes, trimming, NucleotideSequence.EMPTY, null);
                vInsert = vInsertGenerator.generate(tempGene);
                djInsert = null;
            }
            return new GGene(null, vdjcGenes, trimming, vInsert, djInsert);
        }
    };
}
Also used : VDJCGenes(io.repseq.gen.VDJCGenes) VDJTrimming(io.repseq.gen.VDJTrimming) GGene(io.repseq.gen.GGene) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCGene(io.repseq.core.VDJCGene)

Example 22 with VDJCGene

use of io.repseq.core.VDJCGene in project repseqio by repseqio.

the class VDJCGenesTest method serializationDeserializationTest.

@Test
public void serializationDeserializationTest() throws Exception {
    VDJCLibrary library = VDJCLibraryRegistry.getDefaultLibrary("hs");
    VDJCGene v = library.getSafe("TRBV12-3*00");
    VDJCGene d = library.getSafe("TRBD1*00");
    VDJCGene j = library.getSafe("TRBJ1-2*00");
    VDJCGene c = library.getSafe("TRBC1*00");
    TestUtil.assertJson(new VDJCGenes(v, d, j, c));
    TestUtil.assertJson(new VDJCGenes(v, null, j, c));
}
Also used : VDJCLibrary(io.repseq.core.VDJCLibrary) VDJCGene(io.repseq.core.VDJCGene) Test(org.junit.Test)

Example 23 with VDJCGene

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

the class ActionAssemble method go.

@Override
public void go(ActionHelper helper) throws Exception {
    // Saving initial timestamp
    long beginTimestamp = System.currentTimeMillis();
    // Checking consistency between actionParameters.doWriteClnA() value and file extension
    if ((actionParameters.getOutputFileName().toLowerCase().endsWith(".clna") && !actionParameters.doWriteClnA()) || (actionParameters.getOutputFileName().toLowerCase().endsWith(".clns") && actionParameters.doWriteClnA()))
        System.out.println("WARNING: Unexpected file extension, use .clns extension for clones-only (normal) output and\n" + ".clna if -a / --write-alignments options specified.");
    // Extracting V/D/J/C gene list from input vdjca file
    final List<VDJCGene> genes;
    final VDJCAlignerParameters alignerParameters;
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(actionParameters.getInputFileName(), VDJCLibraryRegistry.getDefault())) {
        genes = reader.getUsedGenes();
        // Saving aligner parameters to correct assembler parameters
        alignerParameters = reader.getParameters();
    }
    AlignmentsProvider alignmentsProvider = AlignmentsProvider.Util.createProvider(actionParameters.getInputFileName(), VDJCLibraryRegistry.getDefault());
    CloneAssemblerParameters assemblerParameters = actionParameters.getCloneAssemblerParameters();
    // set aligner parameters
    assemblerParameters.updateFrom(alignerParameters);
    // Overriding JSON parameters
    if (!actionParameters.overrides.isEmpty()) {
        assemblerParameters = JsonOverrider.override(assemblerParameters, CloneAssemblerParameters.class, actionParameters.overrides);
        if (assemblerParameters == null) {
            System.err.println("Failed to override some parameter.");
            System.exit(1);
        }
    }
    // Performing assembly
    try (CloneAssembler assembler = new CloneAssembler(assemblerParameters, actionParameters.doWriteClnA() || actionParameters.events != null, genes, alignerParameters.getFeaturesToAlignMap())) {
        // Creating event listener to collect run statistics
        CloneAssemblerReport report = new CloneAssemblerReport();
        report.setStartMillis(beginTimestamp);
        report.setInputFiles(new String[] { actionParameters.getInputFileName() });
        report.setOutputFiles(new String[] { actionParameters.getOutputFileName() });
        report.setCommandLine(helper.getCommandLineArguments());
        assembler.setListener(report);
        // Running assembler
        CloneAssemblerRunner assemblerRunner = new CloneAssemblerRunner(alignmentsProvider, assembler, actionParameters.threads);
        SmartProgressReporter.startProgressReport(assemblerRunner);
        assemblerRunner.run();
        // Getting results
        final CloneSet cloneSet = assemblerRunner.getCloneSet(alignerParameters);
        // Passing final cloneset to assemble last pieces of statistics for report
        report.onClonesetFinished(cloneSet);
        // Writing results
        if (actionParameters.doWriteClnA())
            try (ClnAWriter writer = new ClnAWriter(actionParameters.getOutputFileName())) {
                // writer will supply current stage and completion percent to the progress reporter
                SmartProgressReporter.startProgressReport(writer);
                // Writing clone block
                writer.writeClones(cloneSet);
                // Pre-soring alignments
                try (AlignmentsMappingMerger merged = new AlignmentsMappingMerger(alignmentsProvider.create(), assembler.getAssembledReadsPort())) {
                    writer.sortAlignments(merged, assembler.getAlignmentsCount());
                }
                writer.writeAlignmentsAndIndex();
            }
        else
            try (CloneSetIO.CloneSetWriter writer = new CloneSetIO.CloneSetWriter(cloneSet, actionParameters.getOutputFileName())) {
                SmartProgressReporter.startProgressReport(writer);
                writer.write();
            }
        // Writing report
        report.setFinishMillis(System.currentTimeMillis());
        assert cloneSet.getClones().size() == report.getCloneCount();
        report.setTotalReads(alignmentsProvider.getTotalNumberOfReads());
        // Writing report to stout
        System.out.println("============= Report ==============");
        Util.writeReportToStdout(report);
        if (actionParameters.report != null)
            Util.writeReport(actionParameters.report, report);
        if (actionParameters.jsonReport != null)
            Util.writeJsonReport(actionParameters.jsonReport, report);
        // Writing raw events (not documented feature)
        if (actionParameters.events != null)
            try (PipeWriter<ReadToCloneMapping> writer = new PipeWriter<>(actionParameters.events)) {
                CUtils.drain(assembler.getAssembledReadsPort(), writer);
            }
    }
}
Also used : VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) CloneSetIO(com.milaboratory.mixcr.basictypes.CloneSetIO) PipeWriter(com.milaboratory.primitivio.PipeWriter) CloneSet(com.milaboratory.mixcr.basictypes.CloneSet) ClnAWriter(com.milaboratory.mixcr.basictypes.ClnAWriter) VDJCGene(io.repseq.core.VDJCGene)

Example 24 with VDJCGene

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

the class IOUtil method writeAndRegisterGeneReferences.

public static void writeAndRegisterGeneReferences(PrimitivO output, List<VDJCGene> genes, HasFeatureToAlign featuresToAlign) {
    // Writing gene ids
    output.writeInt(genes.size());
    for (VDJCGene gene : genes) output.writeObject(gene.getId());
    registerGeneReferences(output, genes, featuresToAlign);
}
Also used : VDJCGene(io.repseq.core.VDJCGene)

Example 25 with VDJCGene

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

the class IOUtil method registerGeneReferences.

public static void registerGeneReferences(PrimitivO output, List<VDJCGene> genes, HasFeatureToAlign featuresToAlign) {
    // Putting genes references and feature sequences to be serialized/deserialized as references
    for (VDJCGene gene : genes) {
        output.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;
            output.putKnownReference(gene.getFeature(featuresToAlign.getFeatureToAlign(gene.getGeneType())));
        }
    }
}
Also used : GeneFeature(io.repseq.core.GeneFeature) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCGene(io.repseq.core.VDJCGene)

Aggregations

VDJCGene (io.repseq.core.VDJCGene)27 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)15 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)7 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)7 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)6 GeneFeature (io.repseq.core.GeneFeature)6 VDJCLibrary (io.repseq.core.VDJCLibrary)6 GeneType (io.repseq.core.GeneType)5 VDJCLibraryRegistry (io.repseq.core.VDJCLibraryRegistry)5 SingleRead (com.milaboratory.core.io.sequence.SingleRead)3 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)3 ReferencePoint (io.repseq.core.ReferencePoint)3 VDJCGeneId (io.repseq.core.VDJCGeneId)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Pattern (java.util.regex.Pattern)3 ParallelProcessor (cc.redberry.pipe.blocks.ParallelProcessor)2 AlignmentHit (com.milaboratory.core.alignment.batch.AlignmentHit)2 PairedRead (com.milaboratory.core.io.sequence.PairedRead)2