Search in sources :

Example 1 with VDJCLibrary

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

the class TargetBuilderTest method testGenerate1.

@Test
public void testGenerate1() throws Exception {
    VDJCLibrary library = VDJCLibraryRegistry.getDefault().getLibrary("default", "hs");
    TargetBuilder.VDJCGenes genes = new TargetBuilder.VDJCGenes(library, "TRBV12-1*00", "TRBD1*00", "TRBJ1-3*00", "TRBC2*00");
    String model = "{CDR3Begin(-20)}VVVVVVVVVVVvVVVvVVVVVVVVVVVVVNNNNNNN{DBegin(0)}DDDDDDDDDDNN{CDR3End(-10)}JJJJJJJJJJJJJJJJJJJJ";
    NucleotideSequence nucleotideSequence = TargetBuilder.generateSequence(genes, model, new Well44497b());
    Assert.assertEquals(36 + 12 + 20, nucleotideSequence.size());
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) Well44497b(org.apache.commons.math3.random.Well44497b) VDJCLibrary(io.repseq.core.VDJCLibrary) Test(org.junit.Test)

Example 2 with VDJCLibrary

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

the class ActionListLibraries method go.

@Override
public void go(ActionHelper helper) {
    VDJCLibraryRegistry.getDefault().loadAllLibraries();
    System.out.println("Available libraries:");
    List<VDJCLibrary> loadedLibraries = new ArrayList<>(VDJCLibraryRegistry.getDefault().getLoadedLibraries());
    Collections.sort(loadedLibraries);
    for (VDJCLibrary library : loadedLibraries) {
        System.out.println(library.getLibraryId());
        System.out.println(VDJCLibraryRegistry.getDefault().getSpeciesNames(library.getTaxonId()));
    }
}
Also used : ArrayList(java.util.ArrayList) VDJCLibrary(io.repseq.core.VDJCLibrary)

Example 3 with VDJCLibrary

use of io.repseq.core.VDJCLibrary 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 4 with VDJCLibrary

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

the class Main method main.

public static void main(String[] args) throws Exception {
    Signal.handle(new Signal("PIPE"), new SignalHandler() {

        @Override
        public void handle(Signal signal) {
            System.exit(0);
        }
    });
    if (System.getProperty("localOnly") == null) {
        Path cachePath = Paths.get(System.getProperty("user.home"), ".repseqio", "cache");
        SequenceResolvers.initDefaultResolver(cachePath);
    }
    // Setting up main helper
    JCommanderBasedMain main = new JCommanderBasedMain("repseqio", new ListAction(), new FilterAction(), new MergeAction(), new CompileAction(), new GenerateClonesAction(), new NormalizeCloneAbundancesAction(), new ExportCloneSequencesAction(), new FastaAction(), new TsvAction(), new InferAnchorPointsAction(), new DebugAction(), new FormatAction(), new StatAction(), new FromFastaAction(), new FromPaddedFastaAction());
    main.setVersionInfoCallback(new Runnable() {

        @Override
        public void run() {
            VersionInfo milib = VersionInfo.getVersionInfoForArtifact("milib");
            VersionInfo repseqio = VersionInfo.getVersionInfoForArtifact("repseqio");
            StringBuilder builder = new StringBuilder();
            builder.append("RepSeq.IO.CLI v").append(repseqio.getVersion()).append(" (built ").append(repseqio.getTimestamp()).append("; rev=").append(repseqio.getRevision()).append("; branch=").append(repseqio.getBranch()).append("; host=").append(repseqio.getHost()).append(")").append("\n");
            builder.append("MiLib v").append(milib.getVersion()).append(" (rev=").append(milib.getRevision()).append("; branch=").append(milib.getBranch()).append(")").append("\n");
            builder.append("Built-in libraries:\n");
            VDJCLibraryRegistry reg = VDJCLibraryRegistry.createDefaultRegistry();
            reg.loadAllLibraries("default");
            for (VDJCLibrary lib : reg.getLoadedLibraries()) builder.append(lib.getLibraryId()).append("\n");
            System.out.print(builder.toString());
        }
    });
    main.main(args);
}
Also used : Signal(sun.misc.Signal) Path(java.nio.file.Path) VersionInfo(com.milaboratory.util.VersionInfo) JCommanderBasedMain(com.milaboratory.cli.JCommanderBasedMain) SignalHandler(sun.misc.SignalHandler) VDJCLibrary(io.repseq.core.VDJCLibrary) VDJCLibraryRegistry(io.repseq.core.VDJCLibraryRegistry)

Example 5 with VDJCLibrary

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

the class TsvAction method go.

@Override
public void go(ActionHelper helper) throws Exception {
    VDJCLibraryRegistry reg = VDJCLibraryRegistry.getDefault();
    if (!"default".equals(params.getInput()))
        reg.registerLibraries(params.getInput());
    else
        reg.loadAllLibraries("default");
    Pattern chainPattern = params.chain == null ? null : Pattern.compile(params.chain);
    Pattern namePattern = params.name == null ? null : Pattern.compile(params.name);
    Long taxonFilter = params.taxonId;
    if (taxonFilter == null && params.species != null)
        taxonFilter = reg.resolveSpecies(params.species);
    try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(params.getOutputStream(), StandardCharsets.UTF_8))) {
        writer.write("Gene\tChains\tFeature\tStart\tStop\tSource\tSequence\n");
        for (VDJCLibrary lib : reg.getLoadedLibraries()) {
            if (taxonFilter != null && taxonFilter != lib.getTaxonId())
                continue;
            for (VDJCGene gene : lib.getGenes()) {
                if (chainPattern != null) {
                    boolean y = false;
                    for (String s : gene.getChains()) if (y |= chainPattern.matcher(s).matches())
                        break;
                    if (!y)
                        continue;
                }
                if (namePattern != null && !namePattern.matcher(gene.getName()).matches())
                    continue;
                for (GeneFeatureWithOriginalName feature : params.features) {
                    GeneFeature geneFeature = feature.feature;
                    NucleotideSequence featureSequence = gene.getFeature(geneFeature);
                    if (featureSequence == null)
                        continue;
                    // Don't output start and end positions for composite gene features
                    Long start = geneFeature.isComposite() ? null : gene.getData().getAnchorPoints().get(geneFeature.getFirstPoint());
                    Long end = geneFeature.isComposite() ? null : gene.getData().getAnchorPoints().get(geneFeature.getLastPoint());
                    NucleotideSequence nSequence = gene.getFeature(geneFeature);
                    List<String> tokens = Arrays.asList(gene.getGeneName(), gene.getChains().toString(), feature.originalName, // (so essentially 1-based inclusive). Report both as 1-based.
                    (start == null ? "" : params.isOneBased() ? String.valueOf(start + 1) : String.valueOf(start)), (end == null ? "" : String.valueOf(end)), gene.getData().getBaseSequence().getOrigin().toString(), nSequence.toString());
                    String delim = "";
                    for (String t : tokens) {
                        writer.write(delim);
                        writer.write(t);
                        delim = "\t";
                    }
                    writer.write('\n');
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) GeneFeature(io.repseq.core.GeneFeature) GeneFeatureWithOriginalName(io.repseq.cli.CLIUtils.GeneFeatureWithOriginalName) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCLibrary(io.repseq.core.VDJCLibrary) VDJCGene(io.repseq.core.VDJCGene) VDJCLibraryRegistry(io.repseq.core.VDJCLibraryRegistry)

Aggregations

VDJCLibrary (io.repseq.core.VDJCLibrary)11 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)7 VDJCGene (io.repseq.core.VDJCGene)6 VDJCLibraryRegistry (io.repseq.core.VDJCLibraryRegistry)5 GeneFeature (io.repseq.core.GeneFeature)3 ArrayList (java.util.ArrayList)3 Pattern (java.util.regex.Pattern)3 Test (org.junit.Test)3 GClone (io.repseq.gen.GClone)2 GGene (io.repseq.gen.GGene)2 Well44497b (org.apache.commons.math3.random.Well44497b)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 JCommanderBasedMain (com.milaboratory.cli.JCommanderBasedMain)1 Range (com.milaboratory.core.Range)1 AminoAcidSequence (com.milaboratory.core.sequence.AminoAcidSequence)1 SequenceProviderIndexOutOfBoundsException (com.milaboratory.core.sequence.provider.SequenceProviderIndexOutOfBoundsException)1 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)1 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)1 TargetBuilder (com.milaboratory.mixcr.tests.TargetBuilder)1