datagrok-ai / public

Public package repository for the Datagrok.ai platform
MIT License
43 stars 26 forks source link

#3010: Qnum does not seem to work in connection with if #3010

Closed ptosco closed 2 days ago

ptosco commented 1 month ago

I would like to enter a formula that conditionally computes a qualified pIC50, but it does not seem to work.

  1. Load qnum.csv into native DG
  2. Open dev console and create a few calculated columns:
    table = grok.shell.tableByName('qnum')
    await table.columns.addNewCalculated('IsLesserThan', 'eq(Qualifier(${IC50 (uM)}), \'<\')', 'bool')
    await table.columns.addNewCalculated('IsGreaterThan', 'eq(Qualifier(${IC50 (uM)}), \'>\')', 'bool')
    await table.columns.addNewCalculated('IsExact', 'eq(Qualifier(${IC50 (uM)}), \'=\')', 'bool')
    await table.columns.addNewCalculated('pIC50', 'if(${IsLesserThan}, Qnum(-Log10(${IC50 (uM)}*1.0e-6), \'>\'), if(${IsGreaterThan}, Qnum(-Log10(${IC50 (uM)}*1.0e-6), \'<\'), Qnum(-Log10(${IC50 (uM)}*1.0e-6), \'=\')))', 'qnum')

    I would have expected that the pIC50 column showed a qnum with inverted qualifier compared to the IC50 (uM) column, but that does not seem to work. Outside the if things work as expected:

    await table.columns.addNewCalculated('QualifierWithoutIf', 'Qnum(-Log10(${IC50 (uM)}*1.0e-6), \'<\')', 'qnum')

    The QualifierWithoutIf column shows all numbers with<, as expected. If I try to put the above into an if, it fails:

    await table.columns.addNewCalculated('QualifierWithIf', 'if(true, Qnum(-Log10(${IC50 (uM)}*1.0e-6), \'<\'), Qnum(-Log10(${IC50 (uM)}*1.0e-6), \'>\'))', 'qnum')

    Obviously in principle the intermediate columns are unnecessary, I just wanted to try to break down the issue a bit; the formula below should work in isolation, but it does not:

    await table.columns.addNewCalculated('pIC50', 'if(eq(Qualifier(${IC50 (uM)}), \'<\'), Qnum(-Log10(${IC50 (uM)}*1.0e-6), \'>\'), if(eq(Qualifier(${IC50 (uM)}), \'>\'), Qnum(-Log10(${IC50 (uM)}*1.0e-6), \'<\'), Qnum(-Log10(${IC50 (uM)}*1.0e-6), \'=\')))', 'qnum')

For an even simpler test:

await table.columns.addNewCalculated('test', 'if(true, Qnum(1, \'>\'), Qnum(1, \'<\'))', 'qnum')
dnillovna commented 1 month ago

This issue has been mirrored in Jira: https://reddata.atlassian.net/browse/GROK-16526

LesiaPavlenko commented 2 days ago

PowerPack > v.1.1.14

LesiaPavlenko commented 2 days ago

Will work for DG 1.22+

LesiaPavlenko commented 2 days ago

Screenshot_49