Search in sources :

Example 1 with ClnAReader

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

the class ActionExportCloneReads method go.

@Override
public void go(ActionHelper helper) throws Exception {
    try (ClnAReader clna = new ClnAReader(parameters.getInputFileName(), VDJCLibraryRegistry.createDefaultRegistry())) {
        VDJCAlignments firstAlignment = clna.readAllAlignments().take();
        if (firstAlignment == null)
            return;
        if (firstAlignment.getOriginalReads() == null)
            throw new ParameterException("Error: original reads were not saved in the .vdjca file: " + "re-run align with '-g' option.");
        int[] cid = parameters.getCloneIds();
        Supplier<IntStream> cloneIds;
        if (cid == null)
            cloneIds = () -> IntStream.range(0, clna.numberOfClones());
        else
            cloneIds = () -> IntStream.of(cid);
        long totalAlignments = cloneIds.get().mapToLong(clna::numberOfAlignmentsInClone).sum();
        AtomicLong alignmentsWritten = new AtomicLong();
        AtomicBoolean finished = new AtomicBoolean(false);
        SmartProgressReporter.startProgressReport("Writing reads", new CanReportProgress() {

            @Override
            public double getProgress() {
                return 1.0 * alignmentsWritten.get() / totalAlignments;
            }

            @Override
            public boolean isFinished() {
                return finished.get();
            }
        });
        boolean paired = firstAlignment.getOriginalReads().get(0).numberOfReads() == 2;
        boolean separate = parameters.doSeparate();
        SequenceWriter globalWriter = separate ? null : createWriter(paired, parameters.getOutputFileName());
        cloneIds.get().forEach(cloneId -> {
            try (SequenceWriter individualWriter = globalWriter == null ? createWriter(paired, cloneFile(parameters.getOutputFileName(), cloneId)) : null) {
                SequenceWriter actualWriter = globalWriter == null ? individualWriter : globalWriter;
                for (VDJCAlignments alignments : CUtils.it(clna.readAlignmentsOfClone(cloneId))) {
                    for (SequenceRead read : alignments.getOriginalReads()) actualWriter.write(read);
                    alignmentsWritten.incrementAndGet();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
    }
}
Also used : ClnAReader(com.milaboratory.mixcr.basictypes.ClnAReader) IOException(java.io.IOException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicLong(java.util.concurrent.atomic.AtomicLong) CanReportProgress(com.milaboratory.util.CanReportProgress) SequenceWriter(com.milaboratory.core.io.sequence.SequenceWriter) SequenceRead(com.milaboratory.core.io.sequence.SequenceRead) ParameterException(com.beust.jcommander.ParameterException) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) IntStream(java.util.stream.IntStream)

Example 2 with ClnAReader

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

the class VersionInfoAction method go.

@Override
public void go(ActionHelper helper) throws Exception {
    String inputFile = parameters.getInputFile();
    String i = inputFile.toLowerCase();
    if (i.endsWith(".vdjca.gz") || i.endsWith(".vdjca")) {
        try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(inputFile)) {
            reader.init();
            System.out.println("MagicBytes = " + reader.getMagic());
            System.out.println(reader.getVersionInfo());
        }
    } else if (i.endsWith(".clns.gz") || i.endsWith(".clns")) {
        CloneSet cs = CloneSetIO.read(inputFile);
        System.out.println(cs.getVersionInfo());
    } else if (i.endsWith(".clna")) {
        try (ClnAReader reader = new ClnAReader(inputFile, VDJCLibraryRegistry.createDefaultRegistry())) {
            System.out.println(reader.getVersionInfo());
        }
    } else
        throw new ParameterException("Wrong file type.");
}
Also used : CloneSet(com.milaboratory.mixcr.basictypes.CloneSet) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) ClnAReader(com.milaboratory.mixcr.basictypes.ClnAReader) ParameterException(com.beust.jcommander.ParameterException)

Aggregations

ParameterException (com.beust.jcommander.ParameterException)2 ClnAReader (com.milaboratory.mixcr.basictypes.ClnAReader)2 SequenceRead (com.milaboratory.core.io.sequence.SequenceRead)1 SequenceWriter (com.milaboratory.core.io.sequence.SequenceWriter)1 CloneSet (com.milaboratory.mixcr.basictypes.CloneSet)1 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)1 VDJCAlignmentsReader (com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader)1 CanReportProgress (com.milaboratory.util.CanReportProgress)1 IOException (java.io.IOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 IntStream (java.util.stream.IntStream)1