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