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