use of io.repseq.core.VDJCGene in project repseqio by repseqio.
the class BasicGGeneModel method create.
@Override
public GGeneGenerator create(RandomGenerator random, VDJCLibrary library) {
final VDJCGenesGenerator vdjcGenesGenerator = vdjcGenesModel.create(random, library);
List<VDJCGene> vGenes = vdjcGenesGenerator.genes(GeneType.Variable);
List<VDJCGene> dGenes = vdjcGenesGenerator.genes(GeneType.Diversity);
List<VDJCGene> jGenes = vdjcGenesGenerator.genes(GeneType.Joining);
List<VDJCGene> cGenes = vdjcGenesGenerator.genes(GeneType.Constant);
final VDJTrimmingGenerator trimmingGenerator = trimmingModel.create(random, vGenes, dGenes, jGenes, cGenes);
final InsertGenerator vInsertGenerator = vInsertModel.create(random, true, vGenes, dGenes, jGenes, cGenes);
final InsertGenerator djInsertGenerator = dGenes.isEmpty() ? null : djInsertModel.create(random, false, vGenes, dGenes, jGenes, cGenes);
return new GGeneGenerator() {
@Override
public GGene generate() {
VDJCGenes vdjcGenes = vdjcGenesGenerator.sample();
VDJTrimming trimming = trimmingGenerator.sample(vdjcGenes);
assert !vdjcGenes.isDDefined() || (vdjcGenes.isDDefined() && djInsertGenerator != null);
NucleotideSequence vInsert;
NucleotideSequence djInsert;
if (vdjcGenes.isDDefined()) {
assert djInsertGenerator != null;
GGene tempGene = new GGene(null, vdjcGenes, trimming, NucleotideSequence.EMPTY, NucleotideSequence.EMPTY);
vInsert = vInsertGenerator.generate(tempGene);
djInsert = djInsertGenerator.generate(tempGene);
} else {
GGene tempGene = new GGene(null, vdjcGenes, trimming, NucleotideSequence.EMPTY, null);
vInsert = vInsertGenerator.generate(tempGene);
djInsert = null;
}
return new GGene(null, vdjcGenes, trimming, vInsert, djInsert);
}
};
}
use of io.repseq.core.VDJCGene in project repseqio by repseqio.
the class VDJCGenesTest method serializationDeserializationTest.
@Test
public void serializationDeserializationTest() throws Exception {
VDJCLibrary library = VDJCLibraryRegistry.getDefaultLibrary("hs");
VDJCGene v = library.getSafe("TRBV12-3*00");
VDJCGene d = library.getSafe("TRBD1*00");
VDJCGene j = library.getSafe("TRBJ1-2*00");
VDJCGene c = library.getSafe("TRBC1*00");
TestUtil.assertJson(new VDJCGenes(v, d, j, c));
TestUtil.assertJson(new VDJCGenes(v, null, j, c));
}
use of io.repseq.core.VDJCGene in project mixcr by milaboratory.
the class ActionAssemble method go.
@Override
public void go(ActionHelper helper) throws Exception {
// Saving initial timestamp
long beginTimestamp = System.currentTimeMillis();
// Checking consistency between actionParameters.doWriteClnA() value and file extension
if ((actionParameters.getOutputFileName().toLowerCase().endsWith(".clna") && !actionParameters.doWriteClnA()) || (actionParameters.getOutputFileName().toLowerCase().endsWith(".clns") && actionParameters.doWriteClnA()))
System.out.println("WARNING: Unexpected file extension, use .clns extension for clones-only (normal) output and\n" + ".clna if -a / --write-alignments options specified.");
// Extracting V/D/J/C gene list from input vdjca file
final List<VDJCGene> genes;
final VDJCAlignerParameters alignerParameters;
try (VDJCAlignmentsReader reader = new VDJCAlignmentsReader(actionParameters.getInputFileName(), VDJCLibraryRegistry.getDefault())) {
genes = reader.getUsedGenes();
// Saving aligner parameters to correct assembler parameters
alignerParameters = reader.getParameters();
}
AlignmentsProvider alignmentsProvider = AlignmentsProvider.Util.createProvider(actionParameters.getInputFileName(), VDJCLibraryRegistry.getDefault());
CloneAssemblerParameters assemblerParameters = actionParameters.getCloneAssemblerParameters();
// set aligner parameters
assemblerParameters.updateFrom(alignerParameters);
// Overriding JSON parameters
if (!actionParameters.overrides.isEmpty()) {
assemblerParameters = JsonOverrider.override(assemblerParameters, CloneAssemblerParameters.class, actionParameters.overrides);
if (assemblerParameters == null) {
System.err.println("Failed to override some parameter.");
System.exit(1);
}
}
// Performing assembly
try (CloneAssembler assembler = new CloneAssembler(assemblerParameters, actionParameters.doWriteClnA() || actionParameters.events != null, genes, alignerParameters.getFeaturesToAlignMap())) {
// Creating event listener to collect run statistics
CloneAssemblerReport report = new CloneAssemblerReport();
report.setStartMillis(beginTimestamp);
report.setInputFiles(new String[] { actionParameters.getInputFileName() });
report.setOutputFiles(new String[] { actionParameters.getOutputFileName() });
report.setCommandLine(helper.getCommandLineArguments());
assembler.setListener(report);
// Running assembler
CloneAssemblerRunner assemblerRunner = new CloneAssemblerRunner(alignmentsProvider, assembler, actionParameters.threads);
SmartProgressReporter.startProgressReport(assemblerRunner);
assemblerRunner.run();
// Getting results
final CloneSet cloneSet = assemblerRunner.getCloneSet(alignerParameters);
// Passing final cloneset to assemble last pieces of statistics for report
report.onClonesetFinished(cloneSet);
// Writing results
if (actionParameters.doWriteClnA())
try (ClnAWriter writer = new ClnAWriter(actionParameters.getOutputFileName())) {
// writer will supply current stage and completion percent to the progress reporter
SmartProgressReporter.startProgressReport(writer);
// Writing clone block
writer.writeClones(cloneSet);
// Pre-soring alignments
try (AlignmentsMappingMerger merged = new AlignmentsMappingMerger(alignmentsProvider.create(), assembler.getAssembledReadsPort())) {
writer.sortAlignments(merged, assembler.getAlignmentsCount());
}
writer.writeAlignmentsAndIndex();
}
else
try (CloneSetIO.CloneSetWriter writer = new CloneSetIO.CloneSetWriter(cloneSet, actionParameters.getOutputFileName())) {
SmartProgressReporter.startProgressReport(writer);
writer.write();
}
// Writing report
report.setFinishMillis(System.currentTimeMillis());
assert cloneSet.getClones().size() == report.getCloneCount();
report.setTotalReads(alignmentsProvider.getTotalNumberOfReads());
// Writing report to stout
System.out.println("============= Report ==============");
Util.writeReportToStdout(report);
if (actionParameters.report != null)
Util.writeReport(actionParameters.report, report);
if (actionParameters.jsonReport != null)
Util.writeJsonReport(actionParameters.jsonReport, report);
// Writing raw events (not documented feature)
if (actionParameters.events != null)
try (PipeWriter<ReadToCloneMapping> writer = new PipeWriter<>(actionParameters.events)) {
CUtils.drain(assembler.getAssembledReadsPort(), writer);
}
}
}
use of io.repseq.core.VDJCGene in project mixcr by milaboratory.
the class IOUtil method writeAndRegisterGeneReferences.
public static void writeAndRegisterGeneReferences(PrimitivO output, List<VDJCGene> genes, HasFeatureToAlign featuresToAlign) {
// Writing gene ids
output.writeInt(genes.size());
for (VDJCGene gene : genes) output.writeObject(gene.getId());
registerGeneReferences(output, genes, featuresToAlign);
}
use of io.repseq.core.VDJCGene in project mixcr by milaboratory.
the class IOUtil method registerGeneReferences.
public static void registerGeneReferences(PrimitivO output, List<VDJCGene> genes, HasFeatureToAlign featuresToAlign) {
// Putting genes references and feature sequences to be serialized/deserialized as references
for (VDJCGene gene : genes) {
output.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;
output.putKnownReference(gene.getFeature(featuresToAlign.getFeatureToAlign(gene.getGeneType())));
}
}
}
Aggregations