use of com.milaboratory.primitivio.PrimitivO in project mixcr by milaboratory.
the class ActionAssembleContigs method go.
@Override
public void go(ActionHelper helper) throws Exception {
// TODO FIX!!!!!!!!!!!!!
if (parameters.threads > 1)
throw new ParameterException("Multithreaded processing is not supported yet.");
long beginTimestamp = System.currentTimeMillis();
FullSeqAssemblerParameters p = FullSeqAssemblerParameters.getByName("default");
if (!parameters.overrides.isEmpty()) {
// Perform parameters overriding
p = JsonOverrider.override(p, FullSeqAssemblerParameters.class, parameters.overrides);
if (p == null)
throw new ProcessException("Failed to override some parameter.");
}
final FullSeqAssemblerReport report = new FullSeqAssemblerReport();
FullSeqAssemblerParameters assemblerParameters = p;
int totalClonesCount = 0;
List<VDJCGene> genes;
VDJCAlignerParameters alignerParameters;
CloneAssemblerParameters cloneAssemblerParameters;
try (ClnAReader reader = new ClnAReader(parameters.getInputFileName(), VDJCLibraryRegistry.getDefault());
PrimitivO tmpOut = new PrimitivO(new BufferedOutputStream(new FileOutputStream(parameters.getOutputFileName())))) {
final CloneFactory cloneFactory = new CloneFactory(reader.getAssemblerParameters().getCloneFactoryParameters(), reader.getAssemblingFeatures(), reader.getGenes(), reader.getAlignerParameters().getFeaturesToAlignMap());
alignerParameters = reader.getAlignerParameters();
cloneAssemblerParameters = reader.getAssemblerParameters();
genes = reader.getGenes();
IOUtil.registerGeneReferences(tmpOut, genes, alignerParameters);
ClnAReader.CloneAlignmentsPort cloneAlignmentsPort = reader.clonesAndAlignments();
SmartProgressReporter.startProgressReport("Assembling", cloneAlignmentsPort);
OutputPort<Clone[]> parallelProcessor = new ParallelProcessor<>(cloneAlignmentsPort, cloneAlignments -> {
FullSeqAssembler fullSeqAssembler = new FullSeqAssembler(cloneFactory, assemblerParameters, cloneAlignments.clone, alignerParameters);
fullSeqAssembler.setReport(report);
FullSeqAssembler.RawVariantsData rawVariantsData = fullSeqAssembler.calculateRawData(() -> {
try {
return cloneAlignments.alignments();
} catch (IOException e) {
throw new RuntimeException(e);
}
});
return fullSeqAssembler.callVariants(rawVariantsData);
}, parameters.threads);
for (Clone[] clones : CUtils.it(parallelProcessor)) {
totalClonesCount += clones.length;
for (Clone cl : clones) tmpOut.writeObject(cl);
}
assert report.getInitialCloneCount() == reader.numberOfClones();
}
assert report.getFinalCloneCount() == totalClonesCount;
assert report.getFinalCloneCount() >= report.getInitialCloneCount();
Clone[] clones = new Clone[totalClonesCount];
try (PrimitivI tmpIn = new PrimitivI(new BufferedInputStream(new FileInputStream(parameters.getOutputFileName())))) {
IOUtil.registerGeneReferences(tmpIn, genes, alignerParameters);
int i = 0;
for (Clone clone : CUtils.it(new PipeDataInputReader<>(Clone.class, tmpIn, totalClonesCount))) clones[i++] = clone;
}
Arrays.sort(clones, Comparator.comparingDouble(c -> -c.getCount()));
for (int i = 0; i < clones.length; i++) clones[i] = clones[i].setId(i);
CloneSet cloneSet = new CloneSet(Arrays.asList(clones), genes, alignerParameters.getFeaturesToAlignMap(), alignerParameters, cloneAssemblerParameters);
try (CloneSetIO.CloneSetWriter writer = new CloneSetIO.CloneSetWriter(cloneSet, parameters.getOutputFileName())) {
SmartProgressReporter.startProgressReport(writer);
writer.write();
}
ReportWrapper reportWrapper = new ReportWrapper(command(), report);
reportWrapper.setStartMillis(beginTimestamp);
reportWrapper.setInputFiles(parameters.getInputFileName());
reportWrapper.setOutputFiles(parameters.getOutputFileName());
reportWrapper.setCommandLine(helper.getCommandLineArguments());
reportWrapper.setFinishMillis(System.currentTimeMillis());
// Writing report to stout
System.out.println("============= Report ==============");
Util.writeReportToStdout(report);
if (parameters.report != null)
Util.writeReport(parameters.report, reportWrapper);
if (parameters.jsonReport != null)
Util.writeJsonReport(parameters.jsonReport, reportWrapper);
}
use of com.milaboratory.primitivio.PrimitivO in project repseqio by repseqio.
the class IOTest method test1.
@Test
public void test1() throws Exception {
GeneFeature[] gfs = { GeneFeature.VDJTranscriptWithout5UTR, GeneFeature.CDR1, GeneFeature.CDR3 };
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrimitivO po = new PrimitivO(bos);
int cc = 10;
for (int i = 0; i < cc; ++i) {
po.writeObject(gfs);
}
System.out.println(bos.size());
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
PrimitivI pi = new PrimitivI(bis);
for (int i = 0; i < cc; ++i) Assert.assertArrayEquals(gfs, pi.readObject(GeneFeature[].class));
}
use of com.milaboratory.primitivio.PrimitivO in project mixcr by milaboratory.
the class SequenceHistoryTest method testIO1.
@Test
public void testIO1() throws Exception {
List<SequenceHistory> entries = new ArrayList<>();
SequenceHistory.RawSequence r1 = new SequenceHistory.RawSequence(123151243L, (byte) 1, false, 100);
SequenceHistory.RawSequence r2 = new SequenceHistory.RawSequence(0L, (byte) 0, true, 100);
entries.add(r1);
entries.add(r2);
entries.add(new SequenceHistory.Extend(r1, 10, 20));
entries.add(new SequenceHistory.Merge(SequenceHistory.OverlapType.CDR3Overlap, new SequenceHistory.Extend(r1, 10, 20), r2, 12, 1));
ByteArrayOutputStream bos = new ByteArrayOutputStream();
PrimitivO o = new PrimitivO(bos);
for (SequenceHistory entry : entries) o.writeObject(entry);
PrimitivI i = new PrimitivI(new ByteArrayInputStream(bos.toByteArray()));
for (SequenceHistory entry : entries) Assert.assertEquals(entry, i.readObject(SequenceHistory.class));
for (SequenceHistory entry : entries) TestUtil.assertJson(entry, SequenceHistory.class);
}
Aggregations