Skip to content

Commit

Permalink
rename columns, add count by tag, option to don't show secondary chain
Browse files Browse the repository at this point in the history
  • Loading branch information
gnefedev committed Sep 5, 2023
1 parent 490479c commit 0e1d7bf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import com.milaboratory.mixcr.basictypes.CloneSetIO
import com.milaboratory.mixcr.basictypes.IOUtil
import com.milaboratory.mixcr.basictypes.MiXCRFileInfo
import com.milaboratory.mixcr.basictypes.tag.TagCountAggregator
import com.milaboratory.mixcr.basictypes.tag.TagType
import com.milaboratory.mixcr.basictypes.tag.TagsInfo
import com.milaboratory.mixcr.cli.CommonDescriptions.DEFAULT_VALUE_FROM_PRESET
import com.milaboratory.mixcr.clonegrouping.CellType
import com.milaboratory.mixcr.export.CloneGroup
Expand Down Expand Up @@ -162,10 +160,13 @@ object CommandExportCloneGroups {
)

val recalculatedClones = filterClones(initialSet, params, fileInfo)
val groups = cloneGroups(recalculatedClones, tagsInfo)
val groups = cloneGroups(recalculatedClones)

val headerForExport = MetaForExport(fileInfo)
val fieldExtractors = CloneGroupFieldsExtractorsFactory(params.types.ifEmpty { CellType.values().toList() })
val fieldExtractors = CloneGroupFieldsExtractorsFactory(
params.types.ifEmpty { CellType.values().toList() },
params.showSecondaryChains
)
.createExtractors(params.fields, headerForExport)

val rowMetaForExport = RowMetaForExport(
Expand All @@ -186,16 +187,10 @@ object CommandExportCloneGroups {
}
}

private fun cloneGroups(
recalculatedClones: CloneSet,
tagsInfo: TagsInfo
): List<CloneGroup> = recalculatedClones
private fun cloneGroups(recalculatedClones: CloneSet): List<CloneGroup> = recalculatedClones
.groupBy { it.group!! }
.map { (groupId, clones) ->
val clonesGroupedByChains = clones.groupBy { it.chains }
val totalTagsCount = TagCountAggregator().also { aggregator ->
clones.forEach { clone -> aggregator.add(clone.tagCount) }
}.createAndDestroy()
CloneGroup(
groupId = groupId,
clonePairs = clonesGroupedByChains.mapValues { (_, clonesWithChain) ->
Expand All @@ -205,10 +200,11 @@ object CommandExportCloneGroups {
sorted.getOrNull(1)
)
},
cellsCount = totalTagsCount.getTagDiversity(tagsInfo.getDepthFor(TagType.Cell)),
cloneCount = clonesGroupedByChains.mapValues { it.value.size },
totalReadsCount = clones.sumOf { it.count },
totalTagsCount = totalTagsCount
totalTagsCount = TagCountAggregator().also { aggregator ->
clones.forEach { clone -> aggregator.add(clone.tagCount) }
}.createAndDestroy()
)
}
.sortedBy { it.groupId }
Expand Down
20 changes: 19 additions & 1 deletion src/main/kotlin/com/milaboratory/mixcr/cli/Mixins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,29 @@ object ExportMiXCRMixins {
@Option(
description = ["Export clone groups for all cell types."],
names = [ExportMixins.ExportCloneGroupsForAllCellTypes.CMD_OPTION],
order = OptionsOrder.mixins.exports + 5_200,
order = OptionsOrder.mixins.exports + 5_101,
arity = "0",
)
fun exportCloneGroupsForAllCellTypes(ignored: Boolean) =
mixIn(ExportMixins.ExportCloneGroupsForAllCellTypes)

@Option(
description = ["Show columns for secondary chains in export for cell groups."],
names = [ExportMixins.ShowSecondaryChainOnExportCellGroups.CMD_OPTION_FOR_SHOW],
order = OptionsOrder.mixins.exports + 5_200,
arity = "0",
)
fun showSecondaryChainOnExportCellGroups(ignored: Boolean) =
mixIn(ExportMixins.ShowSecondaryChainOnExportCellGroups(true))

@Option(
description = ["Don't show columns for secondary chains in export for cell groups."],
names = [ExportMixins.ShowSecondaryChainOnExportCellGroups.CMD_OPTION_FOR_DONT_SHOW],
order = OptionsOrder.mixins.exports + 5_201,
arity = "0",
)
fun dontShowSecondaryChainOnExportCellGroups(ignored: Boolean) =
mixIn(ExportMixins.ShowSecondaryChainOnExportCellGroups(false))
}

private interface ExportClonesMixins : GeneralExportClonesMixins {
Expand Down
16 changes: 10 additions & 6 deletions src/main/resources/presets/blocks/10-exportCloneGroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ exportCloneGroups-single-cell-no-umi-base:
abstract: true
exportCloneGroups:
types: [ ]
showSecondaryChains: true
fields:
- field: "-cellGroup"
- field: "-groupCellsCount"
- field: "-groupReadsCount"
- field: "-groupReadCount"
- field: "-groupUniqueTagCount"
args: [ "Cell" ]
- field: "-uniqClonesPerChainCount"
- field: "-cloneId"
- field: "-readCount"
- field: "-targetSequences"
- field: "-targetQualities"
Expand All @@ -27,12 +28,15 @@ exportCloneGroups-single-cell-with-umi-base:
abstract: true
exportCloneGroups:
types: [ ]
showSecondaryChains: true
fields:
- field: "-cellGroup"
- field: "-groupCellsCount"
- field: "-groupReadsCount"
- field: "-groupReadCount"
- field: "-groupUniqueTagCount"
args: [ "Cell" ]
- field: "-groupUniqueTagCount"
args: [ "Molecule" ]
- field: "-uniqClonesPerChainCount"
- field: "-cloneId"
- field: "-readCount"
- field: "-uniqueTagCount"
args: [ "Molecule" ]
Expand Down
4 changes: 2 additions & 2 deletions src/test/kotlin/com/milaboratory/mixcr/PresetsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ class PresetsTest {
val bundle = Presets.MiXCRBundleResolver.resolvePreset(presetName)
MiXCRCommandDescriptor.groupClones in bundle.pipeline!!.steps
}
.forEach { presetName ->
.forAll { presetName ->
val bundle = Presets.MiXCRBundleResolver.resolvePreset(presetName)
val exportClonesFields = bundle.exportClones!!.fields
val exportCloneGroupsFields = bundle.exportCloneGroups!!.fields

presetName.asClue {
exportCloneGroupsFields shouldContainAll exportClonesFields
.filter { it.field !in CloneGroupFieldsExtractorsFactory.excludeCloneFields }
.filter { it.field !in (CloneGroupFieldsExtractorsFactory.excludeCloneFields + "-cloneId") }
exportCloneGroupsFields.forAll {
it.field shouldNotBeIn (CloneGroupFieldsExtractorsFactory.excludeCloneFields - "-cellGroup")
}
Expand Down

0 comments on commit 0e1d7bf

Please sign in to comment.