Search in sources :

Example 1 with PairedFastqReader

use of com.milaboratory.core.io.sequence.fastq.PairedFastqReader in project mixcr by milaboratory.

the class RunMiXCRTest method test2.

// @Test
// public void testt() throws Exception {
// try {
// Path cachePath = Paths.get(System.getProperty("user.home"), ".repseqio", "cache");
// SequenceResolvers.initDefaultResolver(cachePath);
// VDJCLibraryRegistry.getDefault().registerLibraries("/Volumes/Data/Projects/repseqio/reference/human/TRB.json", "mi");
// System.out.println(VDJCLibraryRegistry.getDefault().getLibrary("mi", "hs").get("TRBV12-3*00").getFeature(GeneFeature.parse("VRegion(-100,+10000000)")));
// } catch (SequenceProviderIndexOutOfBoundsException e) {
// System.out.println(e.getAvailableRange());
// }
// }
@Test
public void test2() throws Exception {
    // Path cachePath = Paths.get(System.getProperty("user.home"), ".repseqio", "cache");
    // SequenceResolvers.initDefaultResolver(cachePath);
    // VDJCLibraryRegistry.getDefault().addPathResolver("/Volumes/Data/Projects/repseqio/reference/human/");
    RunMiXCR.RunMiXCRAnalysis params = new RunMiXCR.RunMiXCRAnalysis(RunMiXCR.class.getResource("/sequences/test_R1.fastq").getFile(), RunMiXCR.class.getResource("/sequences/test_R2.fastq").getFile());
    params.alignerParameters.setSaveOriginalReads(true);
    // params.library = "human_TR";
    // params.species = "hs";
    RunMiXCR.AlignResult align = RunMiXCR.align(params);
    List<PairedRead> reads = new ArrayList<>();
    try (PairedFastqReader fReader = new PairedFastqReader(RunMiXCR.class.getResource("/sequences/test_R1.fastq").getFile(), RunMiXCR.class.getResource("/sequences/test_R2.fastq").getFile())) {
        for (PairedRead s : CUtils.it(fReader)) reads.add(s);
    }
    File tempFile = TempFileManager.getTempFile();
    try (VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(tempFile)) {
        writer.header(align.aligner);
        for (VDJCAlignments alignment : align.alignments) writer.write(alignment);
    }
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(tempFile)) {
        int tr = 0;
        for (VDJCAlignments alignment : CUtils.it(reader)) {
            PairedRead actual = reads.get((int) alignment.getMinReadId());
            ++tr;
            Assert.assertEquals(actual, alignment.getOriginalReads().get(0));
        }
        System.out.println(tr);
    }
}
Also used : ArrayList(java.util.ArrayList) PairedRead(com.milaboratory.core.io.sequence.PairedRead) File(java.io.File) PairedFastqReader(com.milaboratory.core.io.sequence.fastq.PairedFastqReader) Test(org.junit.Test)

Example 2 with PairedFastqReader

use of com.milaboratory.core.io.sequence.fastq.PairedFastqReader in project mixcr by milaboratory.

the class VDJCAlignerWithMergeTest method test1.

@Test
public void test1() throws Exception {
    VDJCAlignerParameters parameters = VDJCParametersPresets.getByName("default");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    List<VDJCAlignments> alignemntsList = new ArrayList<>();
    int header;
    int total = 0;
    int leftHit = 0;
    try (PairedFastqReader reader = new PairedFastqReader(VDJCAlignerSTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R1.fastq"), VDJCAlignerSTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R2.fastq"), true)) {
        VDJCAlignerWithMerge aligner = new VDJCAlignerWithMerge(parameters);
        for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes(Chains.IGH)) {
            if (parameters.containsRequiredFeature(gene))
                aligner.addGene(gene);
        }
        for (PairedRead read : CUtils.it(reader)) {
            ++total;
            VDJCAlignmentResult<PairedRead> result = aligner.process(read);
            if (result.alignment != null) {
                alignemntsList.add(result.alignment);
                for (VDJCHit hit : result.alignment.getHits(GeneType.Variable)) if (hit.getAlignment(0) != null && hit.getAlignment(1) != null)
                    ++leftHit;
            }
        }
    }
    // for (VDJCAlignments alignments : alignemntsList) {
    // for (int i = 0; i < alignments.numberOfTargets(); i++) {
    // System.out.println(VDJCAlignmentsFormatter.getTargetAsMultiAlignment(alignments, i));
    // }
    // }
    System.out.println(alignemntsList.size());
    System.out.println(total);
    System.out.println(leftHit);
    Assert.assertTrue(alignemntsList.size() > 10);
// System.out.println("Bytes per alignment: " + (bos.size() - header) / alignemntsList.size());
// 
// try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(new ByteArrayInputStream(bos.toByteArray()), ll)) {
// int i = 0;
// for (VDJCAlignments alignments : CUtils.it(reader))
// Assert.assertEquals(alignemntsList.get(i++), alignments);
// }
}
Also used : ArrayList(java.util.ArrayList) VDJCGene(io.repseq.core.VDJCGene) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PairedRead(com.milaboratory.core.io.sequence.PairedRead) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) PairedFastqReader(com.milaboratory.core.io.sequence.fastq.PairedFastqReader) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit) Test(org.junit.Test)

Example 3 with PairedFastqReader

use of com.milaboratory.core.io.sequence.fastq.PairedFastqReader in project mixcr by milaboratory.

the class CloneAssemblerRunnerTest method runFullPipeline.

private static CloneSet runFullPipeline(String... fastqFiles) throws IOException, InterruptedException {
    // building alignments
    VDJCAlignerParameters alignerParameters = VDJCParametersPresets.getByName("default");
    VDJCAligner aligner = fastqFiles.length == 1 ? new VDJCAlignerS(alignerParameters) : new VDJCAlignerWithMerge(alignerParameters);
    for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("mi", "hs").getGenes(Chains.IGH)) if (alignerParameters.containsRequiredFeature(gene))
        aligner.addGene(gene);
    SequenceReader reader;
    if (fastqFiles.length == 1)
        reader = new SingleFastqReader(CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[0]), true);
    else
        reader = new PairedFastqReader(CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[0]), CloneAssemblerRunnerTest.class.getClassLoader().getResourceAsStream(fastqFiles[1]), true);
    // write alignments to byte array
    ByteArrayOutputStream alignmentsSerialized = new ByteArrayOutputStream();
    try (VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(alignmentsSerialized)) {
        writer.header(aligner);
        for (Object read : CUtils.it(reader)) {
            VDJCAlignmentResult result = (VDJCAlignmentResult) aligner.process((SequenceRead) read);
            if (result.alignment != null)
                writer.write(result.alignment);
        }
    }
    AlignmentsProvider alignmentsProvider = AlignmentsProvider.Util.createProvider(alignmentsSerialized.toByteArray(), VDJCLibraryRegistry.getDefault());
    LinearGapAlignmentScoring<NucleotideSequence> scoring = new LinearGapAlignmentScoring<>(NucleotideSequence.ALPHABET, 5, -9, -12);
    CloneFactoryParameters factoryParameters = new CloneFactoryParameters(new VJCClonalAlignerParameters(0.8f, scoring, 5), new VJCClonalAlignerParameters(0.8f, scoring, 5), null, new DAlignerParameters(GeneFeature.DRegion, 0.85f, 30.0f, 3, scoring));
    CloneAssemblerParameters assemblerParameters = new CloneAssemblerParameters(new GeneFeature[] { GeneFeature.CDR3 }, 12, QualityAggregationType.Average, new CloneClusteringParameters(2, 1, TreeSearchParameters.ONE_MISMATCH, new RelativeConcentrationFilter(1.0E-6)), factoryParameters, true, true, false, 0.4, true, (byte) 20, .8, "2 of 6", (byte) 15);
    System.out.println(GlobalObjectMappers.toOneLine(assemblerParameters));
    CloneAssemblerRunner assemblerRunner = new CloneAssemblerRunner(alignmentsProvider, new CloneAssembler(assemblerParameters, true, aligner.getUsedGenes(), alignerParameters), 2);
    SmartProgressReporter.startProgressReport(assemblerRunner);
    assemblerRunner.run();
    CloneSet cloneSet = assemblerRunner.getCloneSet(null);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    CloneSetIO.write(cloneSet, bos);
    CloneSet cloneSetDeserialized = CloneSetIO.readClns(new ByteArrayInputStream(bos.toByteArray()));
    assertCSEquals(cloneSet, cloneSetDeserialized);
    OutputPortCloseable<ReadToCloneMapping> rrr = assemblerRunner.assembler.getAssembledReadsPort();
    ReadToCloneMapping take;
    while ((take = rrr.take()) != null) System.out.println(take);
    return cloneSet;
}
Also used : SingleFastqReader(com.milaboratory.core.io.sequence.fastq.SingleFastqReader) VDJCAlignmentsWriter(com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter) CloneSet(com.milaboratory.mixcr.basictypes.CloneSet) LinearGapAlignmentScoring(com.milaboratory.core.alignment.LinearGapAlignmentScoring) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) SequenceRead(com.milaboratory.core.io.sequence.SequenceRead) SequenceReader(com.milaboratory.core.io.sequence.SequenceReader) PairedFastqReader(com.milaboratory.core.io.sequence.fastq.PairedFastqReader)

Example 4 with PairedFastqReader

use of com.milaboratory.core.io.sequence.fastq.PairedFastqReader in project mixcr by milaboratory.

the class RunMiXCRTest method test3.

@Ignore
@Test
public void test3() throws Exception {
    RunMiXCR.RunMiXCRAnalysis params = new RunMiXCR.RunMiXCRAnalysis("/Users/poslavsky/Projects/milab/temp/R1_part.fastq.gz", "/Users/poslavsky/Projects/milab/temp/R2_part.fastq.gz");
    RunMiXCR.AlignResult align = RunMiXCR.align(params);
    List<PairedRead> reads = new ArrayList<>();
    try (PairedFastqReader fReader = new PairedFastqReader("/Users/poslavsky/Projects/milab/temp/R1_part.fastq.gz", "/Users/poslavsky/Projects/milab/temp/R2_part.fastq.gz", true)) {
        for (PairedRead s : CUtils.it(fReader)) reads.add(s);
    }
    File tempFile = TempFileManager.getTempFile();
    try (VDJCAlignmentsWriter writer = new VDJCAlignmentsWriter(tempFile)) {
        writer.header(align.aligner);
        for (VDJCAlignments alignment : align.alignments) writer.write(alignment);
    }
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(tempFile)) {
        int tr = 0;
        for (VDJCAlignments alignment : CUtils.it(reader)) {
            PairedRead actual = reads.get((int) alignment.getMinReadId());
            ++tr;
            Assert.assertEquals(actual, alignment.getOriginalReads().get(0));
        }
        System.out.println(tr);
    }
}
Also used : ArrayList(java.util.ArrayList) PairedRead(com.milaboratory.core.io.sequence.PairedRead) File(java.io.File) PairedFastqReader(com.milaboratory.core.io.sequence.fastq.PairedFastqReader) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with PairedFastqReader

use of com.milaboratory.core.io.sequence.fastq.PairedFastqReader in project mixcr by milaboratory.

the class VDJCAlignerPVFirstTest method test1.

@Test
public void test1() throws Exception {
    VDJCAlignerParameters parameters = VDJCParametersPresets.getByName("default");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    List<VDJCAlignments> alignemntsList = new ArrayList<>();
    int header;
    int total = 0;
    int leftHit = 0;
    try (PairedFastqReader reader = new PairedFastqReader(VDJCAlignerSTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R1.fastq"), VDJCAlignerSTest.class.getClassLoader().getResourceAsStream("sequences/sample_IGH_R2.fastq"), true)) {
        VDJCAlignerPVFirst aligner = new VDJCAlignerPVFirst(parameters);
        for (VDJCGene gene : VDJCLibraryRegistry.getDefault().getLibrary("default", "hs").getGenes(Chains.IGH)) {
            if (parameters.containsRequiredFeature(gene))
                aligner.addGene(gene);
        }
        for (PairedRead read : CUtils.it(reader)) {
            ++total;
            VDJCAlignmentResult<PairedRead> result = aligner.process(read);
            if (result.alignment != null) {
                alignemntsList.add(result.alignment);
                for (VDJCHit hit : result.alignment.getHits(GeneType.Variable)) if (hit.getAlignment(0) != null && hit.getAlignment(1) != null)
                    ++leftHit;
            }
        }
    }
    System.out.println(alignemntsList.size());
    System.out.println(total);
    System.out.println(leftHit);
    Assert.assertTrue(alignemntsList.size() > 10);
    int k = 10;
    for (VDJCAlignments alignments : alignemntsList) {
        for (int target = 0; target < alignments.numberOfTargets(); target++) {
            MultiAlignmentHelper helperBig = VDJCAlignmentsFormatter.getTargetAsMultiAlignment(alignments, target);
            if (helperBig == null)
                continue;
            for (MultiAlignmentHelper helper : helperBig.split(80)) {
                System.out.println(helper);
                System.out.println();
                if (--k < 0)
                    return;
            }
        }
    }
// System.out.println("Bytes per alignment: " + (bos.size() - header) / alignemntsList.size());
// 
// try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(new ByteArrayInputStream(bos.toByteArray()), ll)) {
// int i = 0;
// for (VDJCAlignments alignments : CUtils.it(reader))
// Assert.assertEquals(alignemntsList.get(i++), alignments);
// }
}
Also used : MultiAlignmentHelper(com.milaboratory.core.alignment.MultiAlignmentHelper) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PairedRead(com.milaboratory.core.io.sequence.PairedRead) VDJCGene(io.repseq.core.VDJCGene) VDJCAlignments(com.milaboratory.mixcr.basictypes.VDJCAlignments) PairedFastqReader(com.milaboratory.core.io.sequence.fastq.PairedFastqReader) VDJCHit(com.milaboratory.mixcr.basictypes.VDJCHit) Test(org.junit.Test)

Aggregations

PairedFastqReader (com.milaboratory.core.io.sequence.fastq.PairedFastqReader)5 PairedRead (com.milaboratory.core.io.sequence.PairedRead)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)2 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)2 VDJCGene (io.repseq.core.VDJCGene)2 File (java.io.File)2 LinearGapAlignmentScoring (com.milaboratory.core.alignment.LinearGapAlignmentScoring)1 MultiAlignmentHelper (com.milaboratory.core.alignment.MultiAlignmentHelper)1 SequenceRead (com.milaboratory.core.io.sequence.SequenceRead)1 SequenceReader (com.milaboratory.core.io.sequence.SequenceReader)1 SingleFastqReader (com.milaboratory.core.io.sequence.fastq.SingleFastqReader)1 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)1 CloneSet (com.milaboratory.mixcr.basictypes.CloneSet)1 VDJCAlignmentsWriter (com.milaboratory.mixcr.basictypes.VDJCAlignmentsWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Ignore (org.junit.Ignore)1