Search in sources :

Example 6 with VDJCAlignmentsWriter

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

the class ActionSortAlignments method go.

@Override
public void go(ActionHelper helper) throws Exception {
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(parameters.getInputFile())) {
        SmartProgressReporter.startProgressReport("Reading vdjca", reader);
        try (OutputPortCloseable<VDJCAlignments> sorted = Sorter.sort(reader, idComparator, 1024 * 512, new VDJCAlignmentsSerializer(reader), TempFileManager.getTempFile());
            VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(parameters.getOutputFile())) {
            writer.header(reader.getParameters(), reader.getUsedGenes());
            final long nReads = reader.getNumberOfReads();
            final CountingOutputPort<VDJCAlignments> counter = new CountingOutputPort<>(sorted);
            SmartProgressReporter.startProgressReport("Writing sorted alignments", SmartProgressReporter.extractProgress(counter, nReads));
            for (VDJCAlignments res : CUtils.it(counter)) writer.write(res);
            writer.setNumberOfProcessedReads(nReads);
        }
    }
}
Also used : VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) CountingOutputPort(cc.redberry.pipe.util.CountingOutputPort) VDJCAlignmentsWriter(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments)

Example 7 with VDJCAlignmentsWriter

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

the class ActionAlignmentsDiff method go.

@Override
public void go(ActionHelper actionHelper) throws Exception {
    try (VDJCAlignmentsReader reader1 = new VDJCAlignmentsReader(parameters.get1());
        VDJCAlignmentsReader reader2 = new VDJCAlignmentsReader(parameters.get2());
        VDJCAlignmentsWriterI only1 = parameters.onlyFirst == null ? VDJCAlignmentsWriterI.DummyWriter.INSTANCE : new VDJCAlignmentsWriter(parameters.onlyFirst);
        VDJCAlignmentsWriterI only2 = parameters.onlySecond == null ? VDJCAlignmentsWriterI.DummyWriter.INSTANCE : new VDJCAlignmentsWriter(parameters.onlySecond);
        VDJCAlignmentsWriterI diff1 = parameters.diff1 == null ? VDJCAlignmentsWriterI.DummyWriter.INSTANCE : new VDJCAlignmentsWriter(parameters.diff1);
        VDJCAlignmentsWriterI diff2 = parameters.diff1 == null ? VDJCAlignmentsWriterI.DummyWriter.INSTANCE : new VDJCAlignmentsWriter(parameters.diff2);
        PrintStream report = parameters.report().equals(".") ? System.out : new PrintStream(new FileOutputStream(parameters.report()))) {
        if (reader1.getNumberOfReads() > reader2.getNumberOfReads())
            SmartProgressReporter.startProgressReport("Analyzing diff", reader1);
        else
            SmartProgressReporter.startProgressReport("Analyzing diff", reader2);
        long same = 0, onlyIn1 = 0, onlyIn2 = 0, diffFeature = 0, justDiff = 0;
        long[] diffHits = new long[GeneType.NUMBER_OF_TYPES];
        only1.header(reader1.getParameters(), reader1.getUsedGenes());
        diff1.header(reader1.getParameters(), reader1.getUsedGenes());
        only2.header(reader2.getParameters(), reader2.getUsedGenes());
        diff2.header(reader2.getParameters(), reader2.getUsedGenes());
        VDJCAlignmentsDifferenceReader diffReader = new VDJCAlignmentsDifferenceReader(reader1, reader2, parameters.getFeature(), parameters.hitsCompareLevel);
        for (VDJCAlignmentsDifferenceReader.Diff diff : CUtils.it(diffReader)) {
            switch(diff.status) {
                case AlignmentsAreSame:
                    ++same;
                    break;
                case AlignmentPresentOnlyInFirst:
                    ++onlyIn1;
                    only1.write(diff.first);
                    break;
                case AlignmentPresentOnlyInSecond:
                    ++onlyIn2;
                    only2.write(diff.second);
                    break;
                case AlignmentsAreDifferent:
                    ++justDiff;
                    diff1.write(diff.first);
                    diff2.write(diff.second);
                    if (diff.reason.diffGeneFeature)
                        ++diffFeature;
                    for (Map.Entry<GeneType, Boolean> e : diff.reason.diffHits.entrySet()) if (e.getValue())
                        ++diffHits[e.getKey().ordinal()];
            }
        }
        only1.setNumberOfProcessedReads(onlyIn1);
        only2.setNumberOfProcessedReads(onlyIn2);
        diff1.setNumberOfProcessedReads(justDiff);
        diff2.setNumberOfProcessedReads(justDiff);
        report.println("First  file: " + parameters.get1());
        report.println("Second file: " + parameters.get2());
        report.println("Completely same reads: " + same);
        report.println("Aligned reads present only in the FIRST  file: " + onlyIn1 + " (" + Util.PERCENT_FORMAT.format(100. * onlyIn1 / reader1.getNumberOfReads()) + ")%");
        report.println("Aligned reads present only in the SECOND file: " + onlyIn2 + " (" + Util.PERCENT_FORMAT.format(100. * onlyIn2 / reader2.getNumberOfReads()) + ")%");
        report.println("Total number of different reads: " + justDiff);
        report.println("Reads with not same " + parameters.geneFeatureToMatch + ": " + diffFeature);
        for (GeneType geneType : GeneType.VDJC_REFERENCE) report.println("Reads with not same " + geneType.name() + " hits: " + diffHits[geneType.ordinal()]);
    }
}
Also used : PrintStream(java.io.PrintStream) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) VDJCAlignmentsWriterI(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriterI) VDJCAlignmentsWriter(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter) VDJCAlignmentsDifferenceReader(com.milaboratory.mixcr.util.VDJCAlignmentsDifferenceReader) FileOutputStream(java.io.FileOutputStream) GeneType(io.repseq.core.GeneType) Map(java.util.Map)

Aggregations

VDJCAlignmentsWriter (com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter)7 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)5 VDJCAlignmentsReader (com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader)4 CountLimitingOutputPort (cc.redberry.pipe.util.CountLimitingOutputPort)2 SequenceRead (com.milaboratory.core.io.sequence.SequenceRead)2 SingleFastqReader (com.milaboratory.core.io.sequence.fastq.SingleFastqReader)2 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)2 CanReportProgress (com.milaboratory.util.CanReportProgress)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ParallelProcessor (cc.redberry.pipe.blocks.ParallelProcessor)1 Chunk (cc.redberry.pipe.util.Chunk)1 CountingOutputPort (cc.redberry.pipe.util.CountingOutputPort)1 Indexer (cc.redberry.pipe.util.Indexer)1 ProcessException (com.milaboratory.cli.ProcessException)1 PairedEndReadsLayout (com.milaboratory.core.PairedEndReadsLayout)1 Target (com.milaboratory.core.Target)1 LinearGapAlignmentScoring (com.milaboratory.core.alignment.LinearGapAlignmentScoring)1 SequenceReader (com.milaboratory.core.io.sequence.SequenceReader)1 SequenceWriter (com.milaboratory.core.io.sequence.SequenceWriter)1