use of com.milaboratory.primitivio.PrimitivI in project mixcr by milaboratory.
the class CloneSetIO method readClns.
public static CloneSet readClns(InputStream inputStream, VDJCLibraryRegistry libraryRegistry) {
PrimitivI input = new PrimitivI(inputStream);
// Registering custom serializer
input.getSerializersManager().registerCustomSerializer(GeneFeature.class, new GeneFeatureSerializer(true));
byte[] magicBytes = new byte[MAGIC_LENGTH];
input.readFully(magicBytes);
String magicString = new String(magicBytes);
SerializersManager serializersManager = input.getSerializersManager();
switch(magicString) {
case MAGIC_V5:
serializersManager.registerCustomSerializer(Clone.class, new CompatibilityIO.CloneSerializerV5());
break;
case MAGIC:
break;
default:
throw new RuntimeException("Unsupported file format; .clns file of version " + magicString + " while you are running MiXCR " + MAGIC);
}
String versionInfo = input.readUTF();
if (!magicString.equals(MAGIC))
// Dropping this field for v5 files
input.readObject(GeneFeature[].class);
VDJCAlignerParameters alignerParameters;
CloneAssemblerParameters assemblerParameters;
if (magicString.equals(MAGIC)) {
alignerParameters = input.readObject(VDJCAlignerParameters.class);
assemblerParameters = input.readObject(CloneAssemblerParameters.class);
} else {
alignerParameters = null;
assemblerParameters = null;
}
EnumMap<GeneType, GeneFeature> alignedFeatures = IO.readGF2GTMap(input);
List<VDJCGene> genes = IOUtil.readAndRegisterGeneReferences(input, libraryRegistry, new GT2GFAdapter(alignedFeatures));
int count = input.readInt();
List<Clone> clones = new ArrayList<>(count);
for (int i = 0; i < count; i++) clones.add(input.readObject(Clone.class));
CloneSet cloneSet = new CloneSet(clones, genes, alignedFeatures, alignerParameters, assemblerParameters);
cloneSet.versionInfo = versionInfo;
return cloneSet;
}
use of com.milaboratory.primitivio.PrimitivI 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.PrimitivI 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);
}
use of com.milaboratory.primitivio.PrimitivI in project mixcr by milaboratory.
the class ClnAReader method readAssembledAlignments.
/**
* Constructs output port to read all alignments that are attached to a clone. Alignments are sorted by cloneIndex.
*/
public OutputPort<VDJCAlignments> readAssembledAlignments() throws IOException {
PrimitivI input = new PrimitivI(new InputDataStream(index[1], index[index.length - 1]));
IOUtil.registerGeneReferences(input, genes, alignedFeatures);
return new PipeDataInputReader<>(VDJCAlignments.class, input, totalAlignmentsCount - counts[0]);
}
Aggregations