Search in sources :

Example 36 with GeneFeature

use of io.repseq.core.GeneFeature in project repseqio by repseqio.

the class GeneFeatureTest method test3.

@Test
public void test3() throws Exception {
    GeneFeature f1, f2, f3, expected, actual;
    f1 = createWithOffsets(1, 3, -2, 0);
    f2 = createWithOffsets(3, 5, 1, 1);
    f3 = createWithOffsets(5, 7, 1, 5);
    expected = create(new int[] { 1, 3, 3, 7 }, new int[] { -2, 0, 1, 5 });
    actual = new GeneFeature(f2, f1, f3);
    assertEquals(expected, actual);
    f1 = createWithOffsets(1, 3, -2, 0);
    f2 = createWithOffsets(3, 5, 1, -1);
    f3 = createWithOffsets(5, 7, -1, 5);
    expected = create(new int[] { 1, 3, 3, 7 }, new int[] { -2, 0, 1, 5 });
    actual = new GeneFeature(f2, f1, f3);
    assertEquals(expected, actual);
    f1 = createWithOffsets(1, 3, -2, 0);
    f2 = createWithOffsets(3, 5, 1, -3);
    f3 = createWithOffsets(5, 7, -2, 5);
    expected = create(new int[] { 1, 3, 3, 5, 5, 7 }, new int[] { -2, 0, 1, -3, -2, 5 });
    actual = new GeneFeature(f2, f1, f3);
    assertEquals(expected, actual);
    assertEquals(3, actual.regions.length);
}
Also used : GeneFeature(io.repseq.core.GeneFeature) Test(org.junit.Test)

Example 37 with GeneFeature

use of io.repseq.core.GeneFeature in project repseqio by repseqio.

the class GeneFeatureTest method create.

static final GeneFeature create(int... indexes) {
    assert indexes.length % 2 == 0;
    GeneFeature[] res = new GeneFeature[indexes.length / 2];
    for (int i = 0; i < indexes.length; ) {
        res[i / 2] = new GeneFeature(new ReferencePoint(BasicReferencePoint.getByIndex(indexes[i])), new ReferencePoint(BasicReferencePoint.getByIndex(indexes[i + 1])));
        i += 2;
    }
    return new GeneFeature(res);
}
Also used : GeneFeature(io.repseq.core.GeneFeature)

Example 38 with GeneFeature

use of io.repseq.core.GeneFeature in project mixcr by milaboratory.

the class VDJCAlignmentsWriter method header.

@Override
public void header(VDJCAlignerParameters parameters, List<VDJCGene> genes) {
    if (parameters == null || genes == null)
        throw new IllegalArgumentException();
    if (header)
        throw new IllegalStateException();
    // Writing magic bytes
    assert MAGIC_BYTES.length == MAGIC_LENGTH;
    output.write(MAGIC_BYTES);
    // Writing version information
    output.writeUTF(MiXCRVersionInfo.get().getVersionString(MiXCRVersionInfo.OutputType.ToFile));
    // Writing parameters
    output.writeObject(parameters);
    IOUtil.writeAndRegisterGeneReferences(output, genes, parameters);
    // Registering links to features to align
    for (GeneType gt : GeneType.VDJC_REFERENCE) {
        GeneFeature feature = parameters.getFeatureToAlign(gt);
        output.writeObject(feature);
        if (feature != null)
            output.putKnownReference(feature);
    }
    header = true;
}
Also used : GeneFeature(io.repseq.core.GeneFeature) GeneType(io.repseq.core.GeneType)

Example 39 with GeneFeature

use of io.repseq.core.GeneFeature 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)

Example 40 with GeneFeature

use of io.repseq.core.GeneFeature in project mixcr by milaboratory.

the class IO method readGF2GTMap.

public static EnumMap<GeneType, GeneFeature> readGF2GTMap(PrimitivI input) {
    int count = input.readInt();
    EnumMap<GeneType, GeneFeature> map = new EnumMap<GeneType, GeneFeature>(GeneType.class);
    for (int i = 0; i < count; i++) {
        GeneType gt = input.readObject(GeneType.class);
        GeneFeature gf = input.readObject(GeneFeature.class);
        map.put(gt, gf);
    }
    return map;
}
Also used : GeneFeature(io.repseq.core.GeneFeature) GeneType(io.repseq.core.GeneType) EnumMap(java.util.EnumMap)

Aggregations

GeneFeature (io.repseq.core.GeneFeature)41 Test (org.junit.Test)23 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)10 GeneType (io.repseq.core.GeneType)9 VDJCGene (io.repseq.core.VDJCGene)6 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)3 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)3 ReferencePoint (io.repseq.core.ReferencePoint)3 VDJCLibrary (io.repseq.core.VDJCLibrary)3 VDJCLibraryRegistry (io.repseq.core.VDJCLibraryRegistry)3 Pattern (java.util.regex.Pattern)3 SequenceRead (com.milaboratory.core.io.sequence.SequenceRead)2 AminoAcidSequence (com.milaboratory.core.sequence.AminoAcidSequence)2 Clone (com.milaboratory.mixcr.basictypes.Clone)2 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)2 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)2 IntArrayList (com.milaboratory.util.IntArrayList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Well19937c (org.apache.commons.math3.random.Well19937c)2