Search in sources :

Example 1 with VDJCAlignmentsReader

use of com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader in project mixcr by milaboratory.

the class ActionAlignmentsStat method go.

@Override
public void go(ActionHelper helper) throws Exception {
    long[] geneFeatureCounters = new long[targetFeatures.length];
    AlignmentInfoCollector[] collectors = new AlignmentInfoCollector[targetFeatures.length + targetReferencePoints.length];
    int i = 0;
    for (GeneFeature targetFeature : targetFeatures) collectors[i++] = new GeneFeatureCoverageCollector(targetFeature);
    for (ReferencePoint targetReferencePoint : targetReferencePoints) collectors[i++] = new ReferencePointCoverageCollector(targetReferencePoint, 40, 40);
    final Collector collector = new Collector(collectors);
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(actionParameters.getInputFileName());
        PrintStream output = actionParameters.getOutputFileName().equals("-") ? System.out : new PrintStream(new BufferedOutputStream(new FileOutputStream(actionParameters.getOutputFileName()), 32768))) {
        SmartProgressReporter.startProgressReport("Analysis", reader);
        CUtils.processAllInParallel(reader, collector, Math.min(4, Runtime.getRuntime().availableProcessors()));
        collector.end();
        if (output == System.out)
            output.println();
        collector.write(output);
    }
}
Also used : GeneFeature(io.repseq.core.GeneFeature) PrintStream(java.io.PrintStream) ReferencePointCoverageCollector(com.milaboratory.mixcr.info.ReferencePointCoverageCollector) AlignmentInfoCollector(com.milaboratory.mixcr.info.AlignmentInfoCollector) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) ReferencePoint(io.repseq.core.ReferencePoint) GeneFeatureCoverageCollector(com.milaboratory.mixcr.info.GeneFeatureCoverageCollector) ReferencePoint(io.repseq.core.ReferencePoint) FileOutputStream(java.io.FileOutputStream) AlignmentInfoCollector(com.milaboratory.mixcr.info.AlignmentInfoCollector) ReferencePointCoverageCollector(com.milaboratory.mixcr.info.ReferencePointCoverageCollector) GeneFeatureCoverageCollector(com.milaboratory.mixcr.info.GeneFeatureCoverageCollector) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with VDJCAlignmentsReader

use of com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader in project mixcr by milaboratory.

the class ActionExportAlignments method go0.

@Override
public void go0() throws Exception {
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(parameters.getInputFile(), VDJCLibraryRegistry.getDefault());
        InfoWriter<VDJCAlignments> writer = new InfoWriter<>(parameters.getOutputFile())) {
        SmartProgressReporter.startProgressReport("Exporting alignments", reader, System.err);
        writer.attachInfoProviders((List) parameters.exporters);
        writer.ensureHeader();
        VDJCAlignments alignments;
        long count = 0;
        long limit = parameters.getLimit();
        OutputPort<VDJCAlignments> alignmentsPort = new FilteringPort<>(reader, parameters.getFilter());
        while ((alignments = alignmentsPort.take()) != null && count < limit) {
            writer.put(alignments);
            ++count;
        }
    }
}
Also used : InfoWriter(com.milaboratory.mixcr.export.InfoWriter) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) FilteringPort(cc.redberry.pipe.blocks.FilteringPort) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Example 3 with VDJCAlignmentsReader

use of com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader in project mixcr by milaboratory.

the class VDJCAlignerSTest method testSerialization1.

@Test
public void testSerialization1() throws Exception {
    VDJCAlignerParameters parameters = VDJCParametersPresets.getByName("default");
    // LociLibrary ll = LociLibraryManager.getDefault().getLibrary("mi");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    List<VDJCAlignments> alignemntsList = new ArrayList<>();
    int header;
    try (SingleFastqReader reader = new SingleFastqReader(VDJCAlignerSTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R1.fastq"), true)) {
        VDJCAlignerS aligner = new VDJCAlignerS(parameters);
        for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes(Chains.IGH)) if (parameters.containsRequiredFeature(gene))
            aligner.addGene(gene);
        try (VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(bos)) {
            writer.header(aligner);
            header = bos.size();
            for (SingleRead read : CUtils.it(reader)) {
                VDJCAlignmentResult<SingleRead> result = aligner.process(read);
                if (result.alignment != null) {
                    writer.write(result.alignment);
                    alignemntsList.add(result.alignment);
                }
            }
        }
    }
    Assert.assertTrue(alignemntsList.size() > 10);
    System.out.println("Bytes per alignment: " + (bos.size() - header) / alignemntsList.size());
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(new ByteArrayInputStream(bos.toByteArray()))) {
        int i = 0;
        for (VDJCAlignments alignments : CUtils.it(reader)) Assert.assertEquals(alignemntsList.get(i++), alignments);
    }
}
Also used : SingleFastqReader(com.milaboratory.core.io.sequence.fastq.SingleFastqReader) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) ArrayList(java.util.ArrayList) VDJCAlignmentsWriter(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) VDJCGene(io.repseq.core.VDJCGene) SingleRead(com.milaboratory.core.io.sequence.SingleRead) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) Test(org.junit.Test)

Example 4 with VDJCAlignmentsReader

use of com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader in project mixcr by milaboratory.

the class ActionInfo method processAlignmentsFile.

public void processAlignmentsFile(String name) throws IOException {
    long size = Files.size(Paths.get(name));
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(name)) {
        long numberOfAlignedReads = 0;
        if (size > 30000000)
            SmartProgressReporter.startProgressReport("Processing " + name, reader, System.err);
        else
            System.err.println("Processing " + name + "...");
        for (VDJCAlignments alignments : CUtils.it(reader)) {
            numberOfAlignedReads++;
        }
        tableAdapter.row(name, reader.getNumberOfReads(), numberOfAlignedReads);
    }
}
Also used : VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Example 5 with VDJCAlignmentsReader

use of com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader in project mixcr by milaboratory.

the class ActionFilterAlignments method go.

@Override
public void go(ActionHelper helper) throws Exception {
    try (VDJCAlignmentsReader reader = parameters.getInput();
        VDJCAlignmentsWriter writer = parameters.getOutput()) {
        CanReportProgress progress = reader;
        OutputPort<VDJCAlignments> sReads = reader;
        if (parameters.limit != 0) {
            sReads = new CountLimitingOutputPort<>(sReads, parameters.limit);
            progress = SmartProgressReporter.extractProgress((CountLimitingOutputPort<?>) sReads);
        }
        writer.header(reader.getParameters(), reader.getUsedGenes());
        SmartProgressReporter.startProgressReport("Filtering", progress);
        int total = 0, passed = 0;
        final AlignmentsFilter filter = parameters.getFilter();
        for (VDJCAlignments al : CUtils.it(CUtils.buffered(sReads, 2048))) {
            ++total;
            if (filter.accept(al)) {
                writer.write(al);
                ++passed;
            }
        }
        writer.setNumberOfProcessedReads(reader.getNumberOfReads());
        System.out.printf("%s alignments analysed\n", total);
        System.out.printf("%s alignments written (%.1f%%)\n", passed, 100.0 * passed / total);
    }
}
Also used : CountLimitingOutputPort(cc.redberry.pipe.util.CountLimitingOutputPort) CanReportProgress(com.milaboratory.util.CanReportProgress) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) VDJCAlignmentsWriter(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Aggregations

VDJCAlignmentsReader (com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader)10 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)5 VDJCAlignmentsWriter (com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter)4 CloneSet (com.milaboratory.mixcr.basictypes.CloneSet)2 VDJCGene (io.repseq.core.VDJCGene)2 FileOutputStream (java.io.FileOutputStream)2 PrintStream (java.io.PrintStream)2 FilteringPort (cc.redberry.pipe.blocks.FilteringPort)1 CountLimitingOutputPort (cc.redberry.pipe.util.CountLimitingOutputPort)1 CountingOutputPort (cc.redberry.pipe.util.CountingOutputPort)1 ParameterException (com.beust.jcommander.ParameterException)1 SingleRead (com.milaboratory.core.io.sequence.SingleRead)1 SingleFastqReader (com.milaboratory.core.io.sequence.fastq.SingleFastqReader)1 ClnAReader (com.milaboratory.mixcr.basictypes.ClnAReader)1 ClnAWriter (com.milaboratory.mixcr.basictypes.ClnAWriter)1 CloneSetIO (com.milaboratory.mixcr.basictypes.CloneSetIO)1 VDJCAlignmentsWriterI (com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriterI)1 InfoWriter (com.milaboratory.mixcr.export.InfoWriter)1 AlignmentInfoCollector (com.milaboratory.mixcr.info.AlignmentInfoCollector)1 GeneFeatureCoverageCollector (com.milaboratory.mixcr.info.GeneFeatureCoverageCollector)1