Skip to content

Commit

Permalink
add new columns
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Davydov committed Dec 13, 2024
1 parent db18312 commit 1b824e8
Show file tree
Hide file tree
Showing 8 changed files with 511 additions and 31 deletions.
87 changes: 73 additions & 14 deletions workflow/src/calculate-pfconv-params.tpl.tengo
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ self := import("@platforma-sdk/workflow-tengo:tpl")
// validation := import("@platforma-sdk/workflow-tengo:validation")

pfconvParamsLib := import(":pfconv_params")
getFeature := import(":check-feature")

json := import("json")

Expand All @@ -15,7 +16,7 @@ json := import("json")
// }
// })

self.defineOutputs("params")
self.defineOutputs("params", "featureParams")

self.body(func(inputs) {

Expand All @@ -32,6 +33,16 @@ self.body(func(inputs) {
return result
}

// contains function
contains := func(list, value) {
for item in list {
if item == value {
return true
}
}
return false
}

fieldsToColumns := {
"-cellGroup": "cellGroup",
"-topChains": "topChains",
Expand All @@ -46,45 +57,89 @@ self.body(func(inputs) {
specs := inputs.specs.getDataAsJson()
preset := inputs.preset.getDataAsJson()

// extract covered feature
imputed := false
assemblingFeature := undefined
if !is_undefined(specs.assemblingFeature) {
assemblingFeature = specs["assemblingFeature"][0]
} else {
assemblingFeature = "VDJRegion"
imputed = true
}

//if using readCount or umiCount
columnsList := []
columnsOrder := []
hasUmi := false
if len(specs.umiTags) == 0 {
columnsList += ["readCount", "readFraction"]
} else {
columnsList += ["uniqueMoleculeCount", "uniqueMoleculeFraction"]
hasUmi = true
columnsList += ["uniqueMoleculeCount", "uniqueMoleculeFraction", "readCount", "readFraction"]
}

// check if imputed or not and filter columns by fieldsToColumns
imputed := undefined
//filter columns by fieldsToColumns
for field in preset.exportClones.fields {
if field.field == "-allAAFeaturesImputed" {
imputed = true
} else if field.field == "-allAAFeatures" {
imputed = false
} else if !is_undefined(fieldsToColumns[field.field]) {
if !is_undefined(fieldsToColumns[field.field]) {
columnsList = append(columnsList, fieldsToColumns[field.field])
}
}

// add columns with sequences
// add columns with frameworks, cdrs sequences
for feature in specs.coveredFeaturesOnExport {
if imputed {
columnsList += ["nSeqImputed"+feature, "minQual"+feature, "aaSeqImputed"+feature]
columnsList += ["nSeqImputed"+feature, "aaSeqImputed"+feature,
"nSeq"+feature, "aaSeq"+feature]
} else {
columnsList += ["nSeq"+feature, "aaSeq"+feature]
}
}

// add columns with covered feature sequences
if assemblingFeature != "CDR3" {
if imputed {
columnsList += ["nSeqImputed"+assemblingFeature, "aaSeqImputed"+assemblingFeature,
"nSeq"+assemblingFeature, "aaSeq"+assemblingFeature]
} else {
columnsList += ["nSeq"+feature, "minQual"+feature, "aaSeq"+feature]
columnsList += ["nSeq"+assemblingFeature, "aaSeq"+assemblingFeature]
}
}

// add V, D, J germline sequences
columnsList += ["nSeqVRegionOfGermline", "nSeqDRegionOfGermline", "nSeqJRegionOfGermline"]

// add boolean columns (isProductive, hasStops, hasOOF)
featureSpec := getFeature.getProductiveFeature(assemblingFeature, imputed)
productiveFeature := featureSpec.productiveFeature
columnsList += ["isProductive"+productiveFeature, "isOOF"+productiveFeature, "hasStopsIn"+productiveFeature]

// add columns with mutations
if assemblingFeature != "CDR3" {
mutationVFeature := featureSpec.mutationVFeature
columnsList += ["nMutations"+mutationVFeature, "aaMutations"+mutationVFeature, "nMutationsCount"+mutationVFeature,
"aaMutationsCount"+mutationVFeature, "nMutationsRate"+mutationVFeature, "aaMutationsRate"+mutationVFeature,
"nMutationsFR4", "aaMutationsFR4"]
}

// filter pfconvParams by column name and get a list of fields from it
pfconvParams := pfconvParamsLib.getColumns(blockId)
pfconvParams := pfconvParamsLib.getColumns(blockId, {assemblingFeature: assemblingFeature, imputed: imputed})

columns := []
for col in columnsList {
getColumn := filter(pfconvParams.columns, func(item) { return item.column == col})
columns += getColumn
}

// if UMI in data make visibility of "readCount" and "readFraction" columns optional
targetColumns := ["readCount", "readFraction"]

if hasUmi {
for column in columns {
if contains(targetColumns, column["column"]) {
column["spec"]["annotations"]["pl7.app/table/visibility"] = "optional"
}
}
}

// create axes fields
axes := []
if len(specs.cellTags) == 0 {
Expand All @@ -99,6 +154,10 @@ self.body(func(inputs) {
"columns": columns,
"storageFormat": "Binary",
"partitionKeyLength": 0
},
featureParams: {
assemblingFeature: assemblingFeature,
imputed: imputed
}
}
})
30 changes: 30 additions & 0 deletions workflow/src/check-feature.lib.tengo
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ll := import("@platforma-sdk/workflow-tengo:ll")
text := import("text")

getProductiveFeature := func(assemblingFeature, imputed) {
productiveFeature := undefined
mutationVFeature := assemblingFeature
if assemblingFeature == "CDR3" || imputed {
productiveFeature = "CDR3"
} else if assemblingFeature == "VDJRegion" {
productiveFeature = "VDJRegion(0,-1)"
mutationVFeature = "{FR1Begin:FR3End}"
} else {
splittedFeature := text.split(assemblingFeature, "_to_")
if splittedFeature[1] == "FR4" {
productiveFeature = assemblingFeature + "(0,-1)"
mutationVFeature = "{"+splittedFeature[0]+":FR3End}"
} else {
productiveFeature = assemblingFeature
mutationVFeature = "{"+splittedFeature[0]+":FR3End}"
}
}
return {
productiveFeature: productiveFeature,
mutationVFeature: mutationVFeature
}
}

export ll.toStrict({
getProductiveFeature: getProductiveFeature
})
2 changes: 1 addition & 1 deletion workflow/src/get-preset.tpl.tengo
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ self.body(func(inputs) {
}


mixcr.addAdditionalColumnArgs(mixcrExportPresetCmdBuilder)
mixcr.addAdditionalColumnArgs(mixcrExportPresetCmdBuilder, {assemblingFeature: "CDR3", imputed: false})

if !is_undefined(species) {
mixcrExportPresetCmdBuilder.arg("--species").arg(species)
Expand Down
2 changes: 2 additions & 0 deletions workflow/src/main.tpl.tengo
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ wf.body(func(args) {
specs: specsContent
})
pfconvParams := calculatePfconvParams.output("params", 24 * 60 * 60 * 1000)
featureParams := calculatePfconvParams.output("featureParams", 24 * 60 * 60 * 1000)

runMixcr := render.createEphemeral(processTpl, {
preset: presetResource,
Expand All @@ -85,6 +86,7 @@ wf.body(func(args) {
blockId: blockId,
presetCommonName: args.presetCommonName
}),
featureParams: featureParams,
pfconvParams: pfconvParams,
inputSpec: input.getFutureInputField("spec"),
inputData: input.getFutureInputField("data")
Expand Down
3 changes: 2 additions & 1 deletion workflow/src/mixcr-analyze.tpl.tengo
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ self.body(func(inputs) {
limitInput := params.limitInput
fileExtension := params.fileExtension
reports := params.reports
featureParams := params.featureParams

presetContent := inputs.presetContent // already in JSON
pfconvParams := inputs.pfconvParams // already in JSON
Expand Down Expand Up @@ -70,7 +71,7 @@ self.body(func(inputs) {
secret("MI_LICENSE", "MI_LICENSE").
arg("analyze")

mixcr.addAdditionalColumnArgs(mixcrCmdBuilder)
mixcr.addAdditionalColumnArgs(mixcrCmdBuilder, featureParams)

if !is_undefined(species) {
mixcrCmdBuilder.arg("--species").arg(species)
Expand Down
84 changes: 80 additions & 4 deletions workflow/src/mixcr.lib.tengo
Original file line number Diff line number Diff line change
@@ -1,16 +1,92 @@
ll := import("@platforma-sdk/workflow-tengo:ll")
text := import("text")
getFeature := import(":check-feature")

addAdditionalColumnArgs := func(mixcrCmdBuiler) {
mixcrCmdBuiler.

addAdditionalColumnArgs := func(mixcrCmdBuilder, featureParams) {
assemblingFeature := featureParams.assemblingFeature
imputed := featureParams.imputed
featureSpec := getFeature.getProductiveFeature(assemblingFeature, imputed)
addColumns := true
if assemblingFeature == "CDR3" {
addColumns = false
}

mixcrCmdBuilder.
arg("--append-export-clones-field").
arg("-vHit").
arg("--append-export-clones-field").
arg("-dHit").
arg("--append-export-clones-field").
arg("-jHit").
arg("--append-export-clones-field").
arg("-cHit")
return mixcrCmdBuiler
arg("-cHit").
arg("--append-export-clones-field").
arg("-nFeature").arg("VRegion").arg("germline").
arg("--append-export-clones-field").
arg("-nFeature").arg("DRegion").arg("germline").
arg("--append-export-clones-field").
arg("-nFeature").arg("JRegion").arg("germline")


if addColumns {
if imputed {
mixcrCmdBuilder.
arg("--append-export-clones-field").
arg("-allNFeatures").
arg("--append-export-clones-field").
arg("-allAAFeatures").
arg("--append-export-clones-field").
arg("-allNFeaturesImputed").
arg("--append-export-clones-field").
arg("-allAAFeaturesImputed").
arg("--append-export-clones-field").
arg("-nFeature").arg(assemblingFeature).
arg("--append-export-clones-field").
arg("-aaFeature").arg(assemblingFeature).
arg("--append-export-clones-field").
arg("-nFeatureImputed").arg(assemblingFeature).
arg("--append-export-clones-field").
arg("-aaFeatureImputed").arg(assemblingFeature).
arg("--append-export-clones-field").
arg("-isProductive").arg("CDR3").
arg("--append-export-clones-field").
arg("-isOOF").arg("CDR3").
arg("--append-export-clones-field").
arg("-hasStops").arg("CDR3")
} else {
mutationVFeature := featureSpec.mutationVFeature
productiveFeature := featureSpec.productiveFeature
mixcrCmdBuilder.
arg("--append-export-clones-field").
arg("-isProductive").arg(productiveFeature).
arg("--append-export-clones-field").
arg("-isOOF").arg(productiveFeature).
arg("--append-export-clones-field").
arg("-hasStops").arg(productiveFeature).
arg("--append-export-clones-field").
arg("-nMutations").arg(mutationVFeature).
arg("--append-export-clones-field").
arg("-aaMutations").arg(mutationVFeature).
arg("--append-export-clones-field").
arg("-nMutations").arg("FR4").
arg("--append-export-clones-field").
arg("-aaMutations").arg("FR4").
arg("--append-export-clones-field").
arg("-nMutationsCount").arg(mutationVFeature).
arg("--append-export-clones-field").
arg("-aaMutationsCount").arg(mutationVFeature).
arg("--append-export-clones-field").
arg("-nMutationsRate").arg(mutationVFeature).
arg("--append-export-clones-field").
arg("-aaMutationsRate").arg(mutationVFeature).
arg("--append-export-clones-field").
arg("-nFeature").arg(assemblingFeature).
arg("--append-export-clones-field").
arg("-aaFeature").arg(assemblingFeature)
}
}
return mixcrCmdBuilder
}

export ll.toStrict({
Expand Down
Loading

0 comments on commit 1b824e8

Please sign in to comment.