Search in sources :

Example 16 with Range

use of com.milaboratory.core.Range in project repseqio by repseqio.

the class SequenceBaseTest method test1.

@Test
public void test1() throws Exception {
    SequenceBase base = new SequenceBase();
    base.put("A1", 10, new NucleotideSequence("ATTAGACACACAC"));
    base.put("A1", 30, new NucleotideSequence("ATTACACA"));
    base.put("A2", 0, new NucleotideSequence("TATAGACATAAGCA"));
    assertNull(base.get("A1", new Range(21, 24)));
    assertNull(base.get("A1", new Range(29, 32)));
    assertNull(base.get("A3", new Range(29, 32)));
    assertEquals(new NucleotideSequence("TAGA"), base.get("A1", new Range(12, 16)));
    assertEquals(new NucleotideSequence("TCTA"), base.get("A1", new Range(16, 12)));
    assertEquals(new NucleotideSequence("GACA"), base.get("A2", new Range(4, 8)));
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) Range(com.milaboratory.core.Range) Test(org.junit.Test)

Example 17 with Range

use of com.milaboratory.core.Range in project repseqio by repseqio.

the class SequenceBaseTest method test3m.

@Test
public void test3m() throws Exception {
    SequenceBase base = new SequenceBase();
    base.put("A1", 100, new NucleotideSequence("ATTAGACACACAC"));
    base.put("A1", 20, new NucleotideSequence("CACATA"));
    base.put("A1", 10, new NucleotideSequence("ATTAGACACACAC"));
    assertEquals(new NucleotideSequence("ACACA"), base.get("A1", new Range(19, 24)));
    assertEquals(new NucleotideSequence("TTAG"), base.get("A1", new Range(101, 105)));
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) Range(com.milaboratory.core.Range) Test(org.junit.Test)

Example 18 with Range

use of com.milaboratory.core.Range in project repseqio by repseqio.

the class SequenceBaseTest method test5.

@Test
public void test5() throws Exception {
    SequenceBase base = new SequenceBase();
    base.put("A1", 10, new NucleotideSequence("ATTAGACACACAC"));
    base.put("A1", 18, new NucleotideSequence("CAC"));
    assertEquals(new NucleotideSequence("ATTAGACACAC"), base.get("A1", new Range(10, 21)));
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) Range(com.milaboratory.core.Range) Test(org.junit.Test)

Example 19 with Range

use of com.milaboratory.core.Range in project repseqio by repseqio.

the class SequenceBaseTest method test3.

@Test
public void test3() throws Exception {
    SequenceBase base = new SequenceBase();
    base.put("A1", 20, new NucleotideSequence("CACATA"));
    base.put("A1", 10, new NucleotideSequence("ATTAGACACACAC"));
    assertEquals(new NucleotideSequence("ACACA"), base.get("A1", new Range(19, 24)));
}
Also used : NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) Range(com.milaboratory.core.Range) Test(org.junit.Test)

Example 20 with Range

use of com.milaboratory.core.Range in project repseqio by repseqio.

the class MarkovInsertModel method create.

@Override
public InsertGenerator create(RandomGenerator random, final boolean v, List<VDJCGene> vGenes, List<VDJCGene> dGenes, List<VDJCGene> jGenes, List<VDJCGene> cGenes) {
    Map<Byte, List<Pair<Byte, Double>>> distParams = new HashMap<>();
    for (Map.Entry<String, Double> s : distribution.entrySet()) {
        String[] split = s.getKey().split(">");
        if (split.length != 2 || split[0].length() != 1 || split[1].length() != 1)
            throw new IllegalArgumentException("Illegal distribution key: " + s.getKey() + ". " + "Expected something like \"A>C\"");
        byte codeFrom = NucleotideSequence.ALPHABET.symbolToCode(split[0].charAt(0));
        byte codeTo = NucleotideSequence.ALPHABET.symbolToCode(split[1].charAt(0));
        if (codeFrom == -1 || codeTo == -1)
            throw new IllegalArgumentException("Illegal nucleotide in: " + s.getKey() + ".");
        List<Pair<Byte, Double>> pairs = distParams.get(codeFrom);
        if (pairs == null)
            distParams.put(codeFrom, pairs = new ArrayList<>());
        pairs.add(new Pair<>(codeTo, s.getValue()));
    }
    final Map<Byte, EnumeratedDistribution<Byte>> dists = new HashMap<>();
    for (byte from = 0; from < NucleotideSequence.ALPHABET.basicSize(); from++) {
        List<Pair<Byte, Double>> d = distParams.get(from);
        if (d == null)
            throw new IllegalArgumentException("No distribution for letter: " + NucleotideSequence.ALPHABET.codeToSymbol(from));
        dists.put(from, new EnumeratedDistribution<>(random, d));
    }
    final IndependentIntGenerator lengthDist = lengthDistribution.create(random);
    return new InsertGenerator() {

        @Override
        public NucleotideSequence generate(GGene gene) {
            ReferencePoint point = beginPoint(fromLeft, v);
            int pointPosition = gene.getPartitioning().getPosition(point);
            if (pointPosition == -1)
                throw new RuntimeException("Point " + point + " is not available for gene " + gene);
            byte letter = gene.getSequence(new Range(pointPosition, pointPosition + 1)).codeAt(0);
            int length = lengthDist.sample();
            byte[] array = new byte[length];
            for (int i = 0; i < length; i++) {
                byte cLetter = dists.get(letter).sample();
                array[i] = cLetter;
                letter = cLetter;
            }
            if (!fromLeft)
                ArraysUtils.reverse(array);
            return NucleotideSequence.ALPHABET.createBuilder().ensureCapacity(length).append(array).createAndDestroy();
        }
    };
}
Also used : ReferencePoint(io.repseq.core.ReferencePoint) Pair(org.apache.commons.math3.util.Pair) EnumeratedDistribution(org.apache.commons.math3.distribution.EnumeratedDistribution) Range(com.milaboratory.core.Range) ReferencePoint(io.repseq.core.ReferencePoint) GGene(io.repseq.gen.GGene)

Aggregations

Range (com.milaboratory.core.Range)45 Test (org.junit.Test)23 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)19 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)4 ArrayList (java.util.ArrayList)4 SingleFastqReaderTest (com.milaboratory.core.io.sequence.fastq.SingleFastqReaderTest)3 MutationsBuilder (com.milaboratory.core.mutations.MutationsBuilder)3 ReferencePoint (io.repseq.core.ReferencePoint)3 Path (java.nio.file.Path)3 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)2 Clone (com.milaboratory.mixcr.basictypes.Clone)2 VDJCPartitionedSequence (com.milaboratory.mixcr.basictypes.VDJCPartitionedSequence)2 VDJCAlignerParameters (com.milaboratory.mixcr.vdjaligners.VDJCAlignerParameters)2 CUtils (cc.redberry.pipe.CUtils)1 OutputPort (cc.redberry.pipe.OutputPort)1 com.milaboratory.core.alignment (com.milaboratory.core.alignment)1 Alignment (com.milaboratory.core.alignment.Alignment)1 LinearGapAlignmentScoring (com.milaboratory.core.alignment.LinearGapAlignmentScoring)1 MultiAlignmentHelper (com.milaboratory.core.alignment.MultiAlignmentHelper)1 com.milaboratory.core.sequence (com.milaboratory.core.sequence)1