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();
}
}
}
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();
}
}
}
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();
}
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;
}
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);
// }
}
Aggregations