Skip to content

Commit

Permalink
Merge pull request #2 from milaboratory/calculate-pfconv-params
Browse files Browse the repository at this point in the history
calculate-pfconv-params
  • Loading branch information
dbolotin authored Sep 7, 2024
2 parents be2ffab + 9144a01 commit 945be49
Show file tree
Hide file tree
Showing 17 changed files with 1,596 additions and 171 deletions.
2 changes: 1 addition & 1 deletion test/src/wf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ blockTest(
const clonesPfColumnList = await ml.driverKit.pFrameDriver.listColumns(clonesPfHandle);

// console.log(clonesPfColumnList);
expect(clonesPfColumnList).length.to.greaterThanOrEqual(1);
expect(clonesPfColumnList).length.to.greaterThanOrEqual(7);

// console.dir(clonotypingStableState3, { depth: 8 });
}
Expand Down
5 changes: 0 additions & 5 deletions test/test_config.json

This file was deleted.

2 changes: 1 addition & 1 deletion workflow/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare type TemplateFromFile = { readonly type: "from-file"; readonly path: string; };
declare type TplName = "calculate-pfconv-params" | "export-clones" | "get-preset-for-back" | "get-preset" | "list-presets" | "mixcr-analyze" | "prerun" | "process" | "test.columns.test" | "main";
declare type TplName = "calculate-pfconv-params" | "export-clones" | "get-preset" | "list-presets" | "mixcr-analyze" | "prerun" | "process" | "test.columns.test" | "main";
declare const Templates: Record<TplName, TemplateFromFile>;
export { Templates };
1 change: 0 additions & 1 deletion workflow/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = { Templates: {
'calculate-pfconv-params': { type: 'from-file', path: require.resolve('./dist/tengo/tpl/calculate-pfconv-params.plj.gz') },
'export-clones': { type: 'from-file', path: require.resolve('./dist/tengo/tpl/export-clones.plj.gz') },
'get-preset-for-back': { type: 'from-file', path: require.resolve('./dist/tengo/tpl/get-preset-for-back.plj.gz') },
'get-preset': { type: 'from-file', path: require.resolve('./dist/tengo/tpl/get-preset.plj.gz') },
'list-presets': { type: 'from-file', path: require.resolve('./dist/tengo/tpl/list-presets.plj.gz') },
'mixcr-analyze': { type: 'from-file', path: require.resolve('./dist/tengo/tpl/mixcr-analyze.plj.gz') },
Expand Down
95 changes: 73 additions & 22 deletions workflow/src/calculate-pfconv-params.tpl.tengo
Original file line number Diff line number Diff line change
@@ -1,36 +1,87 @@
// calculate-pfconv-params

self := import("@milaboratory/tengo-sdk:tpl")

pvconfParams := import(":pfconv_params")

json := import("json")

self.defineOutputs("params")

self.body(func(inputs) {
// preset content
preset := inputs.preset

// filter function
filter := func(list, predicate) {
result := []
for item in list {
if predicate(item) {
result = append(result, item)
}
}
return result
}

fieldsToColumns := {
"-cellGroup": "cellGroup",
"-topChains": "topChains",
"-isotype": "isotype",
"-vHit": "bestVHit",
"-dHit": "bestDHit",
"-jHit": "bestJHit",
"-cHit": "bestCHit"
}

// get specs and preset data
specs := inputs.specs.getDataAsJson()
preset := inputs.preset.getDataAsJson()
//if using readCount or umiCount
columnsList := []
columnsOrder := []
if len(specs.umiTags) == 0 {
columnsList += ["readCount", "readFraction"]
} else {
columnsList += ["uniqueMoleculeCount", "uniqueMoleculeFraction"]
}

// check if imputed or not and filter columns by fieldsToColumns
imputed := undefined
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]) {
columnsList = append(columnsList, fieldsToColumns[field.field])
}
}

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

// filter pvconfParams by column name and get a list of fields from it
columns := []
for col in columnsList {
getColumn := filter(pvconfParams.columns, func(item) { return item.column == col})
columns += getColumn
}

// create axes fields
axes := []
if len(specs.cellTags) == 0 {
axes = filter(pvconfParams.axes, func(item) { return item.column == "cloneId" })
} else {
axes = pvconfParams.axes
}

return {
params: {
"axes": [{
"column": "cloneId",
"spec": {
"name": "pl7.app/vdj/cloneId",
"type": "Long"
}
}],
"columns": [{
"column": "readCount",
"id": "read-count",
"allowNA": false,
"spec": {
"name": "pl7.app/vdj/readCount",
"valueType": "Long",
"annotations": {
"pl7.app/label": "Number Of Reads"
}
}
}],
"axes": axes,
"columns": columns,
"storageFormat": "Binary",
"partitionKeyLength": 0
}
Expand Down
56 changes: 0 additions & 56 deletions workflow/src/get-preset-for-back.tpl.tengo

This file was deleted.

29 changes: 23 additions & 6 deletions workflow/src/get-preset.tpl.tengo
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ self := import("@milaboratory/tengo-sdk:tpl")
ll := import("@milaboratory/tengo-sdk:ll")
exec := import("@milaboratory/tengo-sdk:exec")
assets := import("@milaboratory/tengo-sdk:assets")
mixcr := import(":mixcr")

self.validateInputs({
"__options__,closed": "",
Expand All @@ -16,30 +17,46 @@ self.validateInputs({

mixcrSw := assets.importSoftware("@milaboratory/mixcr:main")

self.defineOutputs("preset")
self.defineOutputs("preset", "presetSpecForBack")

self.body(func(inputs) {
presetName := inputs.request.presetName
species := inputs.request.species

mixcrCmdBuilder := exec.builder().
mixcrExportPresetCmdBuilder := exec.builder().
software(mixcrSw).
printErrStreamToStdout().
arg("exportPreset").
arg("--preset-name").
arg(presetName)

mixcr.addAdditionalColumnArgs(mixcrExportPresetCmdBuilder)

if !is_undefined(species) {
mixcrCmdBuilder.arg("--species").arg(species)
mixcrExportPresetCmdBuilder.arg("--species").arg(species)
}

mixcrCmd := mixcrCmdBuilder.arg("preset.json").
mixcrExportPresetCmd := mixcrExportPresetCmdBuilder.arg("preset.json").
saveFileContent("preset.json").
saveFile("preset.json").
run()

presetContent := mixcrExportPresetCmd.getFileContent("preset.json")

mixcrForBackCmd := exec.builder().
software(mixcrSw).
printErrStreamToStdout().
arg("presetSpecificationsForBack").
addFile("preset.yaml", mixcrExportPresetCmd.getFile("preset.json")).
arg("preset.yaml").
arg("presetForBack.json").
saveFileContent("presetForBack.json").
run()

presetContent := mixcrCmd.getFileContent("preset.json")
presetSpecForBackContent := mixcrForBackCmd.getFileContent("presetForBack.json")

return {
preset: presetContent
preset: presetContent,
presetSpecForBack: presetSpecForBackContent
}
})
9 changes: 6 additions & 3 deletions workflow/src/main.tpl.tengo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exec := import("@milaboratory/tengo-sdk:exec")

json := import("json")

getPresetTpl := assets.importTemplate(":get-preset-for-back")
getPresetTpl := assets.importTemplate(":get-preset")
calculatePfconvParamsTpl := assets.importTemplate(":calculate-pfconv-params")
processTpl := assets.importTemplate(":process")

Expand All @@ -33,10 +33,13 @@ wf.body(func(args) {
species: species
}
})

presetContent := getPreset.output("preset", 24 * 60 * 60 * 1000)
specsContent := getPreset.output("presetSpecForBack", 24 * 60 * 60 * 1000)

calculatePfconvParams := render.create(calculatePfconvParamsTpl, {
preset: presetContent
preset: presetContent,
specs: specsContent
})
pfconvParams := calculatePfconvParams.output("params", 24 * 60 * 60 * 1000)

Expand All @@ -45,7 +48,7 @@ wf.body(func(args) {
preset: preset,
species: species
}),
presetContent: presetContent,
presetContent: specsContent,
pfconvParams: pfconvParams,
inputSpec: input.getFutureInputField("spec"),
inputData: input.getFutureInputField("data")
Expand Down
3 changes: 3 additions & 0 deletions workflow/src/mixcr-analyze.tpl.tengo
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ exec := import("@milaboratory/tengo-sdk:exec")
smart := import("@milaboratory/tengo-sdk:smart")
assets := import("@milaboratory/tengo-sdk:assets")
render := import("@milaboratory/tengo-sdk:render")
mixcr := import(":mixcr")

json := import("json")

Expand Down Expand Up @@ -58,6 +59,8 @@ self.body(func(inputs) {
software(mixcrSw).
arg("analyze")

mixcr.addAdditionalColumnArgs(mixcrCmdBuilder)

if !is_undefined(species) {
mixcrCmdBuilder.arg("--species").arg(species)
}
Expand Down
18 changes: 18 additions & 0 deletions workflow/src/mixcr.lib.tengo
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ll := import("@milaboratory/tengo-sdk:ll")

addAdditionalColumnArgs := func(mixcrCmdBuiler) {
mixcrCmdBuiler.
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
}

export ll.toStrict({
addAdditionalColumnArgs: addAdditionalColumnArgs
})
Loading

0 comments on commit 945be49

Please sign in to comment.