Search in sources :

Example 1 with GClone

use of io.repseq.gen.GClone 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)

Example 2 with GClone

use of io.repseq.gen.GClone in project repseqio by repseqio.

the class BasicGCloneModel method create.

@Override
public GCloneGenerator create(RandomGenerator random, VDJCLibraryRegistry registry) {
    VDJCLibrary library = registry.getLibrary(vdjcLibrary);
    final IndependentRealGenerator abundanceGenerator = abundanceModel.create(random);
    final Map<String, GGeneGenerator> geneGenerators = new HashMap<>();
    for (Map.Entry<String, GGeneModel> e : geneModels.entrySet()) geneGenerators.put(e.getKey(), e.getValue().create(random, library));
    return new GCloneGenerator() {

        @Override
        public GClone sample() {
            double abundance = abundanceGenerator.generate();
            Map<String, GGene> genes = new HashMap<>();
            for (Map.Entry<String, GGeneGenerator> e : geneGenerators.entrySet()) genes.put(e.getKey(), e.getValue().generate());
            return new GClone(abundance, genes);
        }
    };
}
Also used : HashMap(java.util.HashMap) GGene(io.repseq.gen.GGene) VDJCLibrary(io.repseq.core.VDJCLibrary) Map(java.util.Map) HashMap(java.util.HashMap) GClone(io.repseq.gen.GClone)

Example 3 with GClone

use of io.repseq.gen.GClone in project repseqio by repseqio.

the class BasicGCloneModelTest method test1.

@Test
public void test1() throws Exception {
    GGeneModel geneModel = new BasicGGeneModel(new IndependentVDJCGenesModel(b("TRBV12-2*00", 1.0).put("TRBV12-3*00", 0.0).get(), b("TRBD1*00", 1.0).put("TRBD2*00", 0.0).get(), b("TRBJ1-2*00", 1.0).put("TRBJ1-3*00", 0.0).get(), b("TRBC1*00", 1.0).put("TRBC2*00", 0.0).get()), new IndependentVDJTrimmingModel(new CommonCategoricalGeneTrimmingModel(b(-1, 1.0).get()), new CommonCategoricalDGeneTrimmingModel(b("-2|-3", 1.0).get()), new CommonCategoricalGeneTrimmingModel(b(-4, 1.0).get())), new FixedInsertModel(new NucleotideSequence("ATTA")), new FixedInsertModel(new NucleotideSequence("GACA")));
    BasicGCloneModel model = new BasicGCloneModel(new VDJCLibraryId("default", 9606), new FixedRealModel(1.0), b("TRB", geneModel).get());
    TestUtil.assertJson(model);
    GCloneGenerator gen = model.create(new Well19937c(123), VDJCLibraryRegistry.getDefault());
    GClone clone = gen.sample();
    TestUtil.assertJson(clone);
    GGene trb = clone.genes.get("TRB");
    assertEquals(trb.vdjcGenes.v.getName(), "TRBV12-2*00");
    assertEquals(trb.vdjcGenes.d.getName(), "TRBD1*00");
    assertEquals(trb.vdjcGenes.j.getName(), "TRBJ1-2*00");
    assertEquals(trb.vdjcGenes.c.getName(), "TRBC1*00");
    assertEquals(new VDJTrimming(-1, -4, -2, -3), trb.vdjTrimming);
    assertEquals(new NucleotideSequence("ATTA"), trb.vInsert);
    assertEquals(new NucleotideSequence("GACA"), trb.djInsert);
}
Also used : VDJCLibraryId(io.repseq.core.VDJCLibraryId) Well19937c(org.apache.commons.math3.random.Well19937c) VDJTrimming(io.repseq.gen.VDJTrimming) GGene(io.repseq.gen.GGene) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) GClone(io.repseq.gen.GClone) Test(org.junit.Test)

Aggregations

GClone (io.repseq.gen.GClone)3 GGene (io.repseq.gen.GGene)3 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)2 VDJCLibrary (io.repseq.core.VDJCLibrary)2 Well19937c (org.apache.commons.math3.random.Well19937c)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 VDJCLibraryId (io.repseq.core.VDJCLibraryId)1 VDJTrimming (io.repseq.gen.VDJTrimming)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 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CloseShieldOutputStream (org.apache.commons.io.output.CloseShieldOutputStream)1 Test (org.junit.Test)1