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);
}
});
}
}
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.");
}
Aggregations