Search in sources :

Example 1 with MultiAlignmentHelper

use of com.milaboratory.core.alignment.MultiAlignmentHelper in project mixcr by milaboratory.

the class ActionExportAlignmentsPretty method outputCompact.

public void outputCompact(PrintStream output, final VDJCAlignments alignments) {
    output.println(">>> Read ids: " + Arrays.toString(alignments.getReadIds()).replace("[", "").replace("]", ""));
    output.println();
    for (int i = 0; i < alignments.numberOfTargets(); i++) {
        if (actionParameters.printDescriptions()) {
            output.println(">>> Assembly history: " + alignments.getHistory(i) + "\n");
        }
        MultiAlignmentHelper targetAsMultiAlignment = VDJCAlignmentsFormatter.getTargetAsMultiAlignment(alignments, i);
        if (targetAsMultiAlignment == null)
            continue;
        MultiAlignmentHelper[] split = targetAsMultiAlignment.split(80);
        for (MultiAlignmentHelper spl : split) {
            output.println(spl);
            output.println();
        }
    }
}
Also used : MultiAlignmentHelper(com.milaboratory.core.alignment.MultiAlignmentHelper)

Example 2 with MultiAlignmentHelper

use of com.milaboratory.core.alignment.MultiAlignmentHelper in project mixcr by milaboratory.

the class MiXCRTestUtils method printAlignment.

public static void printAlignment(VDJCAlignments alignments) {
    for (int i = 0; i < alignments.numberOfTargets(); i++) {
        // fixme
        // if (alignments.getTargetDescriptions() != null)
        // System.out.println(">>> Description: " + alignments.getTargetDescriptions()[i] + "\n");
        MultiAlignmentHelper targetAsMultiAlignment = VDJCAlignmentsFormatter.getTargetAsMultiAlignment(alignments, i);
        if (targetAsMultiAlignment == null)
            continue;
        MultiAlignmentHelper[] split = targetAsMultiAlignment.split(80);
        for (MultiAlignmentHelper spl : split) {
            System.out.println(spl);
            System.out.println();
        }
    }
}
Also used : MultiAlignmentHelper(com.milaboratory.core.alignment.MultiAlignmentHelper)

Example 3 with MultiAlignmentHelper

use of com.milaboratory.core.alignment.MultiAlignmentHelper in project mixcr by milaboratory.

the class ActionExportClonesPretty method outputCompact.

public static void outputCompact(PrintStream output, final Clone clone) {
    output.println(">>> Clone id: " + clone.getId());
    output.println(">>> Abundance, reads (fraction): " + clone.getCount() + " (" + clone.getFraction() + ")");
    output.println();
    for (int i = 0; i < clone.numberOfTargets(); i++) {
        MultiAlignmentHelper targetAsMultiAlignment = VDJCAlignmentsFormatter.getTargetAsMultiAlignment(clone, i, true, false);
        if (targetAsMultiAlignment == null)
            continue;
        MultiAlignmentHelper[] split = targetAsMultiAlignment.split(80);
        for (MultiAlignmentHelper spl : split) {
            output.println(spl);
            output.println();
        }
    }
    output.println();
}
Also used : MultiAlignmentHelper(com.milaboratory.core.alignment.MultiAlignmentHelper)

Example 4 with MultiAlignmentHelper

use of com.milaboratory.core.alignment.MultiAlignmentHelper in project mixcr by milaboratory.

the class VDJCAlignmentsFormatter method getTargetAsMultiAlignment.

public static MultiAlignmentHelper getTargetAsMultiAlignment(VDJCObject vdjcObject, int targetId, boolean addHitScore, boolean addReads) {
    if (addReads && !(vdjcObject instanceof VDJCAlignments))
        throw new IllegalArgumentException("Read alignments supported only for VDJCAlignments.");
    NSequenceWithQuality target = vdjcObject.getTarget(targetId);
    NucleotideSequence targetSeq = target.getSequence();
    SequencePartitioning partitioning = vdjcObject.getPartitionedTarget(targetId).getPartitioning();
    List<Alignment<NucleotideSequence>> alignments = new ArrayList<>();
    List<String> alignmentLeftComments = new ArrayList<>();
    List<String> alignmentRightComments = new ArrayList<>();
    for (GeneType gt : GeneType.values()) for (VDJCHit hit : vdjcObject.getHits(gt)) {
        Alignment<NucleotideSequence> alignment = hit.getAlignment(targetId);
        if (alignment == null)
            continue;
        alignment = alignment.invert(targetSeq);
        alignments.add(alignment);
        alignmentLeftComments.add(hit.getGene().getName());
        alignmentRightComments.add(" " + (int) (hit.getAlignment(targetId).getScore()) + (addHitScore ? " (" + (int) (hit.getScore()) + ")" : ""));
    }
    // Adding read information
    if (addReads) {
        VDJCAlignments vdjcAlignments = (VDJCAlignments) vdjcObject;
        SequenceHistory history = vdjcAlignments.getHistory(targetId);
        List<SequenceHistory.RawSequence> reads = history.rawReads();
        for (SequenceHistory.RawSequence read : reads) {
            NucleotideSequence seq = vdjcAlignments.getOriginalSequence(read.index).getSequence();
            int offset = history.offset(read.index);
            Alignment<NucleotideSequence> alignment = Aligner.alignOnlySubstitutions(targetSeq, seq, offset, seq.size(), 0, seq.size(), AffineGapAlignmentScoring.IGBLAST_NUCLEOTIDE_SCORING);
            alignments.add(alignment);
            alignmentLeftComments.add(read.index.toString());
            alignmentRightComments.add("");
        }
    }
    MultiAlignmentHelper helper = MultiAlignmentHelper.build(MultiAlignmentHelper.DEFAULT_SETTINGS, new Range(0, target.size()), targetSeq, alignments.toArray(new Alignment[alignments.size()]));
    if (!alignments.isEmpty())
        drawPoints(helper, partitioning, POINTS_FOR_REARRANGED);
    drawAASequence(helper, partitioning, targetSeq);
    helper.addSubjectQuality("Quality", target.getQuality());
    helper.setSubjectLeftTitle("Target" + targetId);
    helper.setSubjectRightTitle(" Score" + (addHitScore ? " (hit score)" : ""));
    for (int i = 0; i < alignmentLeftComments.size(); i++) {
        helper.setQueryLeftTitle(i, alignmentLeftComments.get(i));
        helper.setQueryRightTitle(i, alignmentRightComments.get(i));
    }
    return helper;
}
Also used : MultiAlignmentHelper(com.milaboratory.core.alignment.MultiAlignmentHelper) ArrayList(java.util.ArrayList) SequencePartitioning(io.repseq.core.SequencePartitioning) Range(com.milaboratory.core.Range) ReferencePoint(io.repseq.core.ReferencePoint) Alignment(com.milaboratory.core.alignment.Alignment) NSequenceWithQuality(com.milaboratory.core.sequence.NSequenceWithQuality) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) GeneType(io.repseq.core.GeneType)

Example 5 with MultiAlignmentHelper

use of com.milaboratory.core.alignment.MultiAlignmentHelper 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

MultiAlignmentHelper (com.milaboratory.core.alignment.MultiAlignmentHelper)5 ArrayList (java.util.ArrayList)2 Range (com.milaboratory.core.Range)1 Alignment (com.milaboratory.core.alignment.Alignment)1 PairedRead (com.milaboratory.core.io.sequence.PairedRead)1 PairedFastqReader (com.milaboratory.core.io.sequence.fastq.PairedFastqReader)1 NSequenceWithQuality (com.milaboratory.core.sequence.NSequenceWithQuality)1 NucleotideSequence (com.milaboratory.core.sequence.NucleotideSequence)1 VDJCAlignments (com.milaboratory.mixcr.basictypes.VDJCAlignments)1 VDJCHit (com.milaboratory.mixcr.basictypes.VDJCHit)1 GeneType (io.repseq.core.GeneType)1 ReferencePoint (io.repseq.core.ReferencePoint)1 SequencePartitioning (io.repseq.core.SequencePartitioning)1 VDJCGene (io.repseq.core.VDJCGene)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Test (org.junit.Test)1