Search in sources :

Example 1 with GCloneGenerator

use of io.repseq.gen.dist.GCloneGenerator in project repseqio by repseqio.

the class GenerateClonesAction method go.

@Override
public void go(ActionHelper helper) throws Exception {
    GCloneModel model = GModels.getGCloneModelByName(params.getModelName());
    GCloneGenerator generator = model.create(new Well19937c(params.getSeed()), VDJCLibraryRegistry.getDefault());
    VDJCLibrary library = VDJCLibraryRegistry.getDefault().getLibrary(model.libraryId());
    try (BufferedOutputStream s = new BufferedOutputStream(params.getOutput().equals(".") ? System.out : new FileOutputStream(params.getOutput()), 128 * 1024)) {
        s.write(GlobalObjectMappers.toOneLine(model.libraryId()).getBytes());
        s.write('\n');
        ObjectWriter writer = GlobalObjectMappers.ONE_LINE.writerFor(new TypeReference<GClone>() {
        }).withAttribute(VDJCGene.JSON_CURRENT_LIBRARY_ATTRIBUTE_KEY, library);
        OUTER: for (int i = 0; i < params.numberOfClones; i++) {
            GClone clone = generator.sample();
            for (GGene g : clone.genes.values()) {
                NucleotideSequence cdr3 = g.getFeature(GeneFeature.CDR3);
                if (params.isInFrame())
                    if (cdr3.size() % 3 != 0) {
                        --i;
                        continue OUTER;
                    }
                if (params.isNoStops())
                    if (AminoAcidSequence.translateFromCenter(cdr3).containStops()) {
                        --i;
                        continue OUTER;
                    }
            }
            writer.writeValue(new CloseShieldOutputStream(s), clone);
            s.write('\n');
        }
    }
}
Also used : GCloneGenerator(io.repseq.gen.dist.GCloneGenerator) GGene(io.repseq.gen.GGene) FileOutputStream(java.io.FileOutputStream) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCLibrary(io.repseq.core.VDJCLibrary) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) TypeReference(com.fasterxml.jackson.core.type.TypeReference) GCloneModel(io.repseq.gen.dist.GCloneModel) Well19937c(org.apache.commons.math3.random.Well19937c) BufferedOutputStream(java.io.BufferedOutputStream) GClone(io.repseq.gen.GClone) CloseShieldOutputStream(org.apache.commons.io.output.CloseShieldOutputStream)

Aggregations

TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)1 VDJCLibrary (io.repseq.core.VDJCLibrary)1 GClone (io.repseq.gen.GClone)1 GGene (io.repseq.gen.GGene)1 GCloneGenerator (io.repseq.gen.dist.GCloneGenerator)1 GCloneModel (io.repseq.gen.dist.GCloneModel)1 BufferedOutputStream (java.io.BufferedOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 CloseShieldOutputStream (org.apache.commons.io.output.CloseShieldOutputStream)1 Well19937c (org.apache.commons.math3.random.Well19937c)1