Search in sources :

Example 6 with PrimitivI

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;
}
Also used : VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) SerializersManager(com.milaboratory.primitivio.SerializersManager) ArrayList(java.util.ArrayList) CloneAssemblerParameters(com.milaboratory.mixcr.assembler.CloneAssemblerParameters) PrimitivI(com.milaboratory.primitivio.PrimitivI)

Example 7 with PrimitivI

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));
}
Also used : PrimitivO(com.milaboratory.primitivio.PrimitivO) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrimitivI(com.milaboratory.primitivio.PrimitivI) Test(org.junit.Test)

Example 8 with PrimitivI

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);
}
Also used : PrimitivO(com.milaboratory.primitivio.PrimitivO) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrimitivI(com.milaboratory.primitivio.PrimitivI) Test(org.junit.Test)

Example 9 with PrimitivI

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]);
}
Also used : PipeDataInputReader(com.milaboratory.primitivio.PipeDataInputReader) PrimitivI(com.milaboratory.primitivio.PrimitivI)

Aggregations

PrimitivI (com.milaboratory.primitivio.PrimitivI)9 PipeDataInputReader (com.milaboratory.primitivio.PipeDataInputReader)5 PrimitivO (com.milaboratory.primitivio.PrimitivO)3 ArrayList (java.util.ArrayList)3 CloneAssemblerParameters (com.milaboratory.mixcr.assembler.CloneAssemblerParameters)2 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Test (org.junit.Test)2 CUtils (cc.redberry.pipe.CUtils)1 OutputPort (cc.redberry.pipe.OutputPort)1 ParallelProcessor (cc.redberry.pipe.blocks.ParallelProcessor)1 DynamicParameter (com.beust.jcommander.DynamicParameter)1 Parameter (com.beust.jcommander.Parameter)1 ParameterException (com.beust.jcommander.ParameterException)1 Parameters (com.beust.jcommander.Parameters)1 PositiveInteger (com.beust.jcommander.validators.PositiveInteger)1 Action (com.milaboratory.cli.Action)1 ActionHelper (com.milaboratory.cli.ActionHelper)1 ActionParametersWithOutput (com.milaboratory.cli.ActionParametersWithOutput)1