Search in sources :

Example 1 with GeneFeature

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

the class ActionAlignmentsStat method go.

@Override
public void go(ActionHelper helper) throws Exception {
    long[] geneFeatureCounters = new long[targetFeatures.length];
    AlignmentInfoCollector[] collectors = new AlignmentInfoCollector[targetFeatures.length + targetReferencePoints.length];
    int i = 0;
    for (GeneFeature targetFeature : targetFeatures) collectors[i++] = new GeneFeatureCoverageCollector(targetFeature);
    for (ReferencePoint targetReferencePoint : targetReferencePoints) collectors[i++] = new ReferencePointCoverageCollector(targetReferencePoint, 40, 40);
    final Collector collector = new Collector(collectors);
    try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(actionParameters.getInputFileName());
        PrintStream output = actionParameters.getOutputFileName().equals("-") ? System.out : new PrintStream(new BufferedOutputStream(new FileOutputStream(actionParameters.getOutputFileName()), 32768))) {
        SmartProgressReporter.startProgressReport("Analysis", reader);
        CUtils.processAllInParallel(reader, collector, Math.min(4, Runtime.getRuntime().availableProcessors()));
        collector.end();
        if (output == System.out)
            output.println();
        collector.write(output);
    }
}
Also used : GeneFeature(io.repseq.core.GeneFeature) PrintStream(java.io.PrintStream) ReferencePointCoverageCollector(com.milaboratory.mixcr.info.ReferencePointCoverageCollector) AlignmentInfoCollector(com.milaboratory.mixcr.info.AlignmentInfoCollector) VDJCAlignmentsReader(com.milaboratory.mixcr.basictypes.VDJCAlignmentsReader) ReferencePoint(io.repseq.core.ReferencePoint) GeneFeatureCoverageCollector(com.milaboratory.mixcr.info.GeneFeatureCoverageCollector) ReferencePoint(io.repseq.core.ReferencePoint) FileOutputStream(java.io.FileOutputStream) AlignmentInfoCollector(com.milaboratory.mixcr.info.AlignmentInfoCollector) ReferencePointCoverageCollector(com.milaboratory.mixcr.info.ReferencePointCoverageCollector) GeneFeatureCoverageCollector(com.milaboratory.mixcr.info.GeneFeatureCoverageCollector) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with GeneFeature

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

the class ActionExportAlignmentsPretty method printGeneFeatures.

public void printGeneFeatures(Filter<GeneFeature> containsFilter, PrintStream output, String prefix) {
    output.print(prefix);
    int totalLength = prefix.length();
    boolean first = true;
    for (GeneFeature geneFeature : GeneFeature.getNameByFeature().keySet()) {
        if (!containsFilter.accept(geneFeature))
            continue;
        if (first)
            first = false;
        else
            output.print(", ");
        String name = GeneFeature.getNameByFeature(geneFeature);
        if (totalLength + name.length() + 2 >= MAX_LENGTH) {
            output.println();
            totalLength = 0;
        }
        output.print(name);
        totalLength += name.length() + 2;
    }
    output.println();
}
Also used : GeneFeature(io.repseq.core.GeneFeature)

Example 3 with GeneFeature

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

the class ActionExportAlignmentsPretty method outputVerbose.

public void outputVerbose(PrintStream output, final VDJCAlignments alignments) {
    output.println(">>> Read ids: " + Arrays.toString(alignments.getReadIds()).replace("[", "").replace("]", ""));
    output.println();
    output.println(">>> Target sequences (input sequences):");
    output.println();
    for (int i = 0; i < alignments.numberOfTargets(); i++) {
        output.println("Sequence" + i + ":");
        final VDJCPartitionedSequence partitionedTarget = alignments.getPartitionedTarget(i);
        printGeneFeatures(new Filter<GeneFeature>() {

            @Override
            public boolean accept(GeneFeature object) {
                return partitionedTarget.getPartitioning().isAvailable(object);
            }
        }, output, "Contains features: ");
        output.println();
        output.print(new NSequenceWithQualityPrintHelper(alignments.getTarget(i), LINE_OFFSET, LINE_LENGTH));
    }
    if (alignments.numberOfTargets() > 1) {
        // Printing a set of available gene features for a full read
        output.println(">>> Gene features that can be extracted from this paired-read: ");
        printGeneFeatures(new Filter<GeneFeature>() {

            @Override
            public boolean accept(GeneFeature object) {
                return alignments.getFeature(object) != null;
            }
        }, output, "");
    }
    output.println();
    for (GeneType geneType : GeneType.values()) {
        output.println(">>> Alignments with " + geneType.getLetter() + " gene:");
        output.println();
        boolean exists = false;
        VDJCHit[] hits = alignments.getHits(geneType);
        if (hits.length > 0) {
            hits = actionParameters.isOnlyTop() ? new VDJCHit[] { hits[0] } : hits;
            for (VDJCHit hit : hits) {
                exists = true;
                output.println(hit.getGene().getName() + " (total score = " + hit.getScore() + ")");
                for (int i = 0; i < alignments.numberOfTargets(); i++) {
                    Alignment<NucleotideSequence> alignment = hit.getAlignment(i);
                    if (alignment == null)
                        continue;
                    output.println("Alignment of Sequence" + i + " (score = " + (alignment == null ? "NaN" : alignment.getScore()) + "):");
                    if (alignment != null) {
                        for (AlignmentHelper subHelper : alignment.getAlignmentHelper().split(LINE_LENGTH, LINE_OFFSET)) {
                            output.println(subHelper.toStringWithSeq2Quality(alignments.getTarget(i).getQuality()));
                            output.println();
                        }
                        if (actionParameters.printGeneSequence()) {
                            output.println("Gene sequence:");
                            output.println(alignment.getSequence1());
                            output.println();
                        }
                    }
                }
            }
        }
        if (!exists) {
            output.println("No hits.");
            output.println();
        }
    }
    char[] ll = new char[94];
    Arrays.fill(ll, '=');
    output.println(ll);
    output.println();
}
Also used : GeneFeature(io.repseq.core.GeneFeature) MultiAlignmentHelper(com.milaboratory.core.alignment.MultiAlignmentHelper) AlignmentHelper(com.milaboratory.core.alignment.AlignmentHelper) NSequenceWithQualityPrintHelper(com.milaboratory.util.NSequenceWithQualityPrintHelper) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) GeneType(io.repseq.core.GeneType)

Example 4 with GeneFeature

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

the class VDJCAlignmentsReader method initGeneFeatureReferencesFrom.

/**
 * Produce reader that uses the same reference for geneFeatures.
 *
 * @param reader     target reader
 * @param parameters parameters to take reference from
 */
public static void initGeneFeatureReferencesFrom(VDJCAlignmentsReader reader, VDJCAlignerParameters parameters) {
    Map<GeneFeature, GeneFeature> featureRefs = new HashMap<>();
    for (GeneType gt : GeneType.VDJC_REFERENCE) {
        GeneFeature f = parameters.getFeatureToAlign(gt);
        featureRefs.put(f, f);
    }
    reader.init(featureRefs);
}
Also used : GeneFeature(io.repseq.core.GeneFeature) HashMap(java.util.HashMap) GeneType(io.repseq.core.GeneType)

Example 5 with GeneFeature

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

the class IOUtil method registerGeneReferences.

public static void registerGeneReferences(PrimitivI input, List<VDJCGene> genes, HasFeatureToAlign featuresToAlign) {
    // Putting genes references and feature sequences to be serialized/deserialized as references
    for (VDJCGene gene : genes) {
        input.putKnownReference(gene);
        // Also put sequences of certain gene features of genes as known references if required
        if (featuresToAlign != null) {
            GeneFeature featureToAlign = featuresToAlign.getFeatureToAlign(gene.getGeneType());
            if (featureToAlign == null)
                continue;
            NucleotideSequence featureSequence = gene.getFeature(featureToAlign);
            if (featureSequence == null)
                continue;
            input.putKnownReference(featureSequence);
        }
    }
}
Also used : GeneFeature(io.repseq.core.GeneFeature) NucleotideSequence(com.milaboratory.core.sequence.NucleotideSequence) VDJCGene(io.repseq.core.VDJCGene)

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