Skip to content

Commit

Permalink
Merge pull request #1534 from milaboratory/reduceToCommonAssembleFeature
Browse files Browse the repository at this point in the history
Reduce to common assemble feature
  • Loading branch information
gnefedev authored Feb 16, 2024
2 parents 94568c5 + e03ef10 commit 7377009
Show file tree
Hide file tree
Showing 29 changed files with 185 additions and 163 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ val toObfuscate: Configuration by configurations.creating {
val obfuscationLibs: Configuration by configurations.creating


val mixcrAlgoVersion = "4.6.0-43-fixes"
val mixcrAlgoVersion = "4.6.0-46-reduceToCommonAssembleFeature"
// may be blank (will be inherited from mixcr-algo)
val milibVersion = ""
// may be blank (will be inherited from mixcr-algo or milib)
Expand Down
15 changes: 7 additions & 8 deletions regression/cli-help/findAlleles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ of V and J genes and the same features to align.
In case of directory no filter by file type will be applied.
--output-template <template.clns>
Output template may contain {file_name} and {file_dir_path},
outputs for '-o /output/folder/{file_name}_with_alleles.clns
input_file.clns input_file2.clns' will be
/output/folder/input_file_with_alleles.clns and
/output/folder/input_file2_with_alleles.clns,
outputs for '-o {file_dir_path}/{file_name}_with_alleles.clns
outputs for '-o /output/folder/{file_name}_suffix.clns input_file.clns
input_file2.clns' will be /output/folder/input_file_suffix.clns and
/output/folder/input_file2_suffix.clns,
outputs for '-o {file_dir_path}/{file_name}_suffix.clns
/some/folder1/input_file.clns /some/folder2/input_file2.clns' will
be /seme/folder1/input_file_with_alleles.clns and
/some/folder2/input_file2_with_alleles.clns
be /seme/folder1/input_file_suffix.clns and
/some/folder2/input_file2_suffix.clns
Resulted outputs must be uniq
--no-clns-output Command will not realign input clns files. Must be specified if
`--output-template` is omitted.
Expand Down Expand Up @@ -81,7 +80,7 @@ of V and J genes and the same features to align.
allele.
--dont-remove-unused-genes
Don't remove genes that weren't used in clones in the result library
-O <key=value> Overrides default build SHM parameter values
-O <key=value> Overrides default find alleles parameter values
-r, --report <path> Report file (human readable version, see `-j / --json-report` for
machine readable report).
-j, --json-report <path> JSON formatted report file.
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/com/milaboratory/mixcr/cli/CommandAlign.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2023, MiLaboratories Inc. All Rights Reserved
* Copyright (c) 2014-2024, MiLaboratories Inc. All Rights Reserved
*
* Before downloading or accessing the software, please read carefully the
* License Agreement available at:
Expand Down Expand Up @@ -73,9 +73,9 @@ import com.milaboratory.mixcr.cli.CommonDescriptions.Labels
import com.milaboratory.mixcr.cli.MiXCRCommand.OptionsOrder
import com.milaboratory.mixcr.presets.AlignMixins
import com.milaboratory.mixcr.presets.AlignMixins.LimitInput
import com.milaboratory.mixcr.presets.AnalyzeCommandDescriptor
import com.milaboratory.mixcr.presets.AnalyzeCommandDescriptor.Companion.dotAfterIfNotBlank
import com.milaboratory.mixcr.presets.FullSampleSheetParsed
import com.milaboratory.mixcr.presets.MiXCRCommandDescriptor
import com.milaboratory.mixcr.presets.MiXCRCommandDescriptor.Companion.dotAfterIfNotBlank
import com.milaboratory.mixcr.presets.MiXCRParamsBundle
import com.milaboratory.mixcr.presets.MiXCRParamsSpec
import com.milaboratory.mixcr.presets.MiXCRStepParams
Expand Down Expand Up @@ -127,7 +127,7 @@ import kotlin.io.path.readText
import kotlin.math.max

object CommandAlign {
const val COMMAND_NAME = MiXCRCommandDescriptor.align.name
const val COMMAND_NAME = AnalyzeCommandDescriptor.align.name

const val SAVE_OUTPUT_FILE_NAMES_OPTION = "--save-output-file-names"
const val STRICT_SAMPLE_NAME_MATCHING_OPTION = "--strict-sample-sheet-matching"
Expand Down Expand Up @@ -1165,7 +1165,7 @@ object CommandAlign {
MiXCRHeader(
inputHash,
dontSavePresetOption.presetToSave(paramsSpecPacked),
MiXCRStepParams().add(MiXCRCommandDescriptor.align, cmdParams),
MiXCRStepParams().add(AnalyzeCommandDescriptor.align, cmdParams),
tagsExtractor.tagsInfo,
aligner.parameters,
aligner.parameters.featuresToAlignMap,
Expand Down Expand Up @@ -1306,7 +1306,7 @@ object CommandAlign {
reportBuilder.setTransformerReports(tagsExtractor.transformerReports)

val report = reportBuilder.buildReport()
writers?.setFooter(MiXCRFooter().addStepReport(MiXCRCommandDescriptor.align, report))
writers?.setFooter(MiXCRFooter().addStepReport(AnalyzeCommandDescriptor.align, report))

// Writing report to stout
ReportUtil.writeReportToStdout(report)
Expand Down
31 changes: 15 additions & 16 deletions src/main/kotlin/com/milaboratory/mixcr/cli/CommandAnalyze.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2023, MiLaboratories Inc. All Rights Reserved
* Copyright (c) 2014-2024, MiLaboratories Inc. All Rights Reserved
*
* Before downloading or accessing the software, please read carefully the
* License Agreement available at:
Expand All @@ -22,10 +22,9 @@ import com.milaboratory.mixcr.cli.CommandAlign.inputFileGroups
import com.milaboratory.mixcr.cli.CommandAlign.listSamplesForSeedFileName
import com.milaboratory.mixcr.cli.CommonDescriptions.Labels
import com.milaboratory.mixcr.presets.AlignMixins
import com.milaboratory.mixcr.presets.AnyMiXCRCommand
import com.milaboratory.mixcr.presets.AnalyzeCommandDescriptor
import com.milaboratory.mixcr.presets.AnalyzeCommandDescriptor.Companion.dotAfterIfNotBlank
import com.milaboratory.mixcr.presets.FullSampleSheetParsed
import com.milaboratory.mixcr.presets.MiXCRCommandDescriptor
import com.milaboratory.mixcr.presets.MiXCRCommandDescriptor.Companion.dotAfterIfNotBlank
import com.milaboratory.mixcr.presets.MiXCRParamsBundle
import com.milaboratory.mixcr.presets.MiXCRParamsSpec
import com.milaboratory.mixcr.presets.MiXCRPipeline
Expand Down Expand Up @@ -338,7 +337,7 @@ object CommandAnalyze {
.let { (first, second) -> first to second.steps.sortedBy { it.order } }

// Creating execution plan
if (pipeline[0] != MiXCRCommandDescriptor.align)
if (pipeline[0] != AnalyzeCommandDescriptor.align)
throw ValidationException("Pipeline must stat from the align action.")

val planBuilder = PlanBuilder(
Expand All @@ -365,7 +364,7 @@ object CommandAnalyze {
// Adding "align" step
if (outputNoUsedReads)
pathsForNotAligned.fillWithDefaults(inputFileGroups.inputType, outputFolder, outputNamePrefix)
planBuilder.addStep(MiXCRCommandDescriptor.align) { _, _, _ ->
planBuilder.addStep(AnalyzeCommandDescriptor.align) { _, _, _ ->
listOf("--preset", presetName) + extraAlignArgs +
mixins.flatMap { it.cmdArgs } + pathsForNotAligned.argsForAlign()
}
Expand All @@ -381,24 +380,24 @@ object CommandAnalyze {
// Adding all steps with calculations
pipeline
.drop(1)
.filter { cmd -> cmd !is MiXCRCommandDescriptor.ExportCommandDescriptor }
.filter { cmd -> cmd !is AnalyzeCommandDescriptor.ExportCommandDescriptor }
.forEach { cmd ->
planBuilder.addStep(cmd) { outputFolder, prefix, sampleName ->
when (cmd) {
MiXCRCommandDescriptor.assemble -> {
AnalyzeCommandDescriptor.assemble -> {
val additionalArgs = mutableListOf<String>()
if (consensusAlignments)
additionalArgs += listOf(
"--consensus-alignments",
outputFolder.resolve(
MiXCRCommandDescriptor.assemble.consensusAlignments(prefix, sampleName)
AnalyzeCommandDescriptor.assemble.consensusAlignments(prefix, sampleName)
).toString()
)
if (consensusStateStats)
additionalArgs += listOf(
"--consensus-state-stat",
outputFolder.resolve(
MiXCRCommandDescriptor.assemble.consensusStateStats(prefix, sampleName)
AnalyzeCommandDescriptor.assemble.consensusStateStats(prefix, sampleName)
).toString()
)
consensusStateStatsDownsampling?.let {
Expand All @@ -417,7 +416,7 @@ object CommandAnalyze {
}

pipeline
.filterIsInstance<MiXCRCommandDescriptor.ExportCommandDescriptor<*>>()
.filterIsInstance<AnalyzeCommandDescriptor.ExportCommandDescriptor<*>>()
.forEach { cmd ->
planBuilder.addExportStep(cmd)
}
Expand All @@ -442,9 +441,9 @@ object CommandAnalyze {
private val forceOverride: Boolean
) {
private val executionPlan = mutableListOf<ExecutionStep>()
private val rounds = mutableMapOf<AnyMiXCRCommand, Int>()
private val rounds = mutableMapOf<AnalyzeCommandDescriptor<*, *>, Int>()
private var nextInputs: List<InputFileSet> = listOf(InputFileSet("", initialInputs.map { it.toString() }))
private val outputsForCommands = mutableListOf<Pair<AnyMiXCRCommand, List<InputFileSet>>>()
private val outputsForCommands = mutableListOf<Pair<AnalyzeCommandDescriptor<*, *>, List<InputFileSet>>>()

fun setActualAlignOutputs(fileNames: List<String>) {
val outputSeed = Path(nextInputs.requireSingleton().fileNames.requireSingleton()).name
Expand Down Expand Up @@ -483,7 +482,7 @@ object CommandAnalyze {
for (input in inputsForQc) {
check(input.fileNames.size == 1)
val round = 0
val cmd = MiXCRCommandDescriptor.qc
val cmd = AnalyzeCommandDescriptor.qc
val outputName = cmd.outputName(outputNamePrefix, input.sampleName, paramsBundle, round)
val arguments = mutableListOf("--print-to-stdout")
if (forceOverride)
Expand All @@ -503,7 +502,7 @@ object CommandAnalyze {
}
}

fun addExportStep(cmd: MiXCRCommandDescriptor.ExportCommandDescriptor<*>) {
fun addExportStep(cmd: AnalyzeCommandDescriptor.ExportCommandDescriptor<*>) {
val runAfter = cmd.runAfterLastOf()
val inputsForExport = outputsForCommands.findLast { (cmd) -> cmd in runAfter }!!.second
for (input in inputsForExport) {
Expand All @@ -527,7 +526,7 @@ object CommandAnalyze {
}

fun addStep(
cmd: AnyMiXCRCommand,
cmd: AnalyzeCommandDescriptor<*, *>,
extraArgs: (outputFolder: Path, prefix: String, sampleName: String) -> List<String> = { _, _, _ -> emptyList() }
) {
val round = rounds.compute(cmd) { c, p ->
Expand Down
12 changes: 6 additions & 6 deletions src/main/kotlin/com/milaboratory/mixcr/cli/CommandAssemble.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2023, MiLaboratories Inc. All Rights Reserved
* Copyright (c) 2014-2024, MiLaboratories Inc. All Rights Reserved
*
* Before downloading or accessing the software, please read carefully the
* License Agreement available at:
Expand Down Expand Up @@ -42,7 +42,7 @@ import com.milaboratory.mixcr.basictypes.tag.TagType
import com.milaboratory.mixcr.basictypes.validateCompositeFeatures
import com.milaboratory.mixcr.cli.CommonDescriptions.DEFAULT_VALUE_FROM_PRESET
import com.milaboratory.mixcr.cli.CommonDescriptions.Labels
import com.milaboratory.mixcr.presets.MiXCRCommandDescriptor
import com.milaboratory.mixcr.presets.AnalyzeCommandDescriptor
import com.milaboratory.mixcr.presets.MiXCRParamsBundle
import com.milaboratory.util.ArraysUtils
import com.milaboratory.util.HashFunctions
Expand All @@ -66,7 +66,7 @@ import kotlin.io.path.bufferedWriter
import kotlin.io.path.extension

object CommandAssemble {
const val COMMAND_NAME = MiXCRCommandDescriptor.assemble.name
const val COMMAND_NAME = AnalyzeCommandDescriptor.assemble.name

abstract class CmdBase : MiXCRCommandWithOutputs(), MiXCRPresetAwareCommand<CommandAssembleParams> {
@Option(
Expand Down Expand Up @@ -388,7 +388,7 @@ object CommandAssemble {
val resultHeader = inputHeader
.withAssemblerParameters(cloneAssemblerParameters)
.addStepParams(
MiXCRCommandDescriptor.assemble,
AnalyzeCommandDescriptor.assemble,
paramsResolver.resolve(paramSpec).second
)
.copy(paramsSpec = dontSavePresetOption.presetToSave(paramSpec))
Expand Down Expand Up @@ -440,7 +440,7 @@ object CommandAssemble {
report = reportBuilder.buildReport()
writer.setFooter(
alignmentsReader.footer.addStepReport(
MiXCRCommandDescriptor.assemble,
AnalyzeCommandDescriptor.assemble,
report
)
)
Expand All @@ -453,7 +453,7 @@ object CommandAssemble {
report = reportBuilder.buildReport()
writer.setFooter(
alignmentsReader.footer.addStepReport(
MiXCRCommandDescriptor.assemble,
AnalyzeCommandDescriptor.assemble,
report
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.milaboratory.mixcr.basictypes.VDJCSProperties.CloneOrdering
import com.milaboratory.mixcr.basictypes.validateCompositeFeatures
import com.milaboratory.mixcr.cli.CommonDescriptions.DEFAULT_VALUE_FROM_PRESET
import com.milaboratory.mixcr.cli.CommonDescriptions.Labels
import com.milaboratory.mixcr.presets.MiXCRCommandDescriptor
import com.milaboratory.mixcr.presets.AnalyzeCommandDescriptor
import com.milaboratory.mixcr.presets.MiXCRParamsBundle
import com.milaboratory.mixcr.presets.MiXCRParamsSpec
import com.milaboratory.mixcr.util.Concurrency
Expand Down Expand Up @@ -66,7 +66,7 @@ import java.nio.file.Path
import java.util.*

object CommandAssembleContigs {
const val COMMAND_NAME = MiXCRCommandDescriptor.assembleContigs.name
const val COMMAND_NAME = AnalyzeCommandDescriptor.assembleContigs.name

abstract class CmdBase : MiXCRCommandWithOutputs(), MiXCRPresetAwareCommand<CommandAssembleContigsParams> {
@Option(
Expand Down Expand Up @@ -172,19 +172,19 @@ object CommandAssembleContigs {

validateParams(cmdParams, reader.header)

require(reader.assemblingFeatures.size == 1) {
ValidationException.require(reader.assemblingFeatures.size == 1) {
"Supports only singular assemblingFeature."
}
val assemblingFeature = reader.assemblingFeatures.first()
require(!assemblingFeature.isComposite) {
ValidationException.require(!assemblingFeature.isComposite) {
"Supports only non-composite gene features as an assemblingFeature."
}

if (assemblingRegions != null) {
val fullyIncluded = assemblingRegions.features.any { assemblingRegion ->
GeneFeature.intersection(assemblingRegion, assemblingFeature) == assemblingFeature
}
require(fullyIncluded) {
ValidationException.require(fullyIncluded) {
"AssemblingFeature of input must be included fully in assemblingRegions"
}
}
Expand Down Expand Up @@ -305,10 +305,10 @@ object CommandAssembleContigs {
clones += clone.withId(cloneId++)
}
}
val allFullyCoveredBy = cmdParams.allClonesWillBeCoveredByFeature()
val allFullyCoveredBy = cmdParams.parameters.allClonesWillBeCoveredByFeature()
val resultHeader = header
.copy(allFullyCoveredBy = if (allFullyCoveredBy) assemblingRegions else null)
.addStepParams(MiXCRCommandDescriptor.assembleContigs, cmdParams)
.addStepParams(AnalyzeCommandDescriptor.assembleContigs, cmdParams)
.copy(paramsSpec = dontSavePresetOption.presetToSave(paramsSpec))

val cloneSet = CloneSet.Builder(clones, genes, resultHeader)
Expand All @@ -327,7 +327,7 @@ object CommandAssembleContigs {
// Writing report to stout
ReportUtil.writeReportToStdout(report)
reportOptions.appendToFiles(report)
writer.setFooter(footer.addStepReport(MiXCRCommandDescriptor.assembleContigs, report))
writer.setFooter(footer.addStepReport(AnalyzeCommandDescriptor.assembleContigs, report))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2023, MiLaboratories Inc. All Rights Reserved
* Copyright (c) 2014-2024, MiLaboratories Inc. All Rights Reserved
*
* Before downloading or accessing the software, please read carefully the
* License Agreement available at:
Expand All @@ -25,7 +25,7 @@ import com.milaboratory.mixcr.basictypes.tag.TagType
import com.milaboratory.mixcr.cli.CommonDescriptions.DEFAULT_VALUE_FROM_PRESET
import com.milaboratory.mixcr.cli.CommonDescriptions.Labels
import com.milaboratory.mixcr.partialassembler.PartialAlignmentsAssembler
import com.milaboratory.mixcr.presets.MiXCRCommandDescriptor
import com.milaboratory.mixcr.presets.AnalyzeCommandDescriptor
import com.milaboratory.mixcr.presets.MiXCRParamsBundle
import com.milaboratory.util.ReportUtil
import com.milaboratory.util.SmartProgressReporter
Expand All @@ -38,7 +38,7 @@ import picocli.CommandLine.Parameters
import java.nio.file.Path

object CommandAssemblePartial {
const val COMMAND_NAME = MiXCRCommandDescriptor.assemblePartial.name
const val COMMAND_NAME = AnalyzeCommandDescriptor.assemblePartial.name

abstract class CmdBase : MiXCRCommandWithOutputs(), MiXCRPresetAwareCommand<CommandAssemblePartialParams> {
@Option(
Expand Down Expand Up @@ -144,7 +144,7 @@ object CommandAssemblePartial {
writer.writeHeader(
header
.updateTagInfo { ti -> ti.setSorted(groupingDepth) } // output data will be grouped only up to a groupingDepth
.addStepParams(MiXCRCommandDescriptor.assemblePartial, cmdParams)
.addStepParams(AnalyzeCommandDescriptor.assemblePartial, cmdParams)
.copy(paramsSpec = dontSavePresetOption.presetToSave(paramsSpec)),
reader.usedGenes
)
Expand Down Expand Up @@ -203,7 +203,7 @@ object CommandAssemblePartial {
}
reportOptions.appendToFiles(report)
writer.setNumberOfProcessedReads(reader.numberOfReads - assembler.overlapped.get())
writer.setFooter(reader.footer.addStepReport(MiXCRCommandDescriptor.assemblePartial, report))
writer.setFooter(reader.footer.addStepReport(AnalyzeCommandDescriptor.assemblePartial, report))
}
}
}
Expand Down
Loading

0 comments on commit 7377009

Please sign in to comment.