Search in sources :

Example 1 with SerializersManager

use of com.milaboratory.primitivio.SerializersManager 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 2 with SerializersManager

use of com.milaboratory.primitivio.SerializersManager in project mixcr by milaboratory.

the class VDJCAlignmentsReader method init.

void init(Map<GeneFeature, GeneFeature> geneFeatureRefs) {
    if (usedGenes != null)
        return;
    assert MAGIC_BYTES.length == MAGIC_LENGTH;
    byte[] magic = new byte[MAGIC_LENGTH];
    input.readFully(magic);
    String magicString = new String(magic);
    this.magic = magicString;
    SerializersManager serializersManager = input.getSerializersManager();
    switch(magicString) {
        case MAGIC_V9:
            serializersManager.registerCustomSerializer(VDJCAlignments.class, new IO.VDJCAlignmentsSerializer21());
        case MAGIC:
            break;
        default:
            throw new RuntimeException("Unsupported file format; .vdjca file of version " + new String(magic) + " while you are running MiXCR " + MAGIC);
    }
    versionInfo = input.readUTF();
    parameters = input.readObject(VDJCAlignerParameters.class);
    this.usedGenes = IOUtil.readAndRegisterGeneReferences(input, vdjcRegistry, parameters);
    // Registering links to features to align
    for (GeneType gt : GeneType.VDJC_REFERENCE) {
        GeneFeature featureParams = parameters.getFeatureToAlign(gt);
        GeneFeature featureDeserialized = input.readObject(GeneFeature.class);
        if (!Objects.equals(featureDeserialized, featureParams))
            throw new RuntimeException("Wrong format.");
        // Find corresponding reference
        if (geneFeatureRefs != null) {
            featureParams = geneFeatureRefs.get(featureParams);
            if (featureParams == null)
                throw new RuntimeException("Absent record for " + featureDeserialized + " in geneFeatureRefs map.");
        }
        if (featureDeserialized != null)
            input.putKnownReference(featureParams);
    }
}
Also used : GeneFeature(io.repseq.core.GeneFeature) VDJCAlignerParameters(com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters) SerializersManager(com.milaboratory.primitivio.SerializersManager) GeneType(io.repseq.core.GeneType)

Aggregations

VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)2 SerializersManager (com.milaboratory.primitivio.SerializersManager)2 CloneAssemblerParameters (com.milaboratory.mixcr.assembler.CloneAssemblerParameters)1 PrimitivI (com.milaboratory.primitivio.PrimitivI)1 GeneFeature (io.repseq.core.GeneFeature)1 GeneType (io.repseq.core.GeneType)1 ArrayList (java.util.ArrayList)1