Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for effect allele not showing in coefficients table when one snp is analyzed #2407

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/mass/test/regression.integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ tape('Linear: continuous outcome = "agedx", cat. independents = "sex" + "genetic
test.equal(results, true, `Should render all intercept data in ${tableLabel}`)

testTerm = 'Sex'
const checkValues1 = ['Sex\nREFFemale', 'Male']
const checkValues1 = ['Sex\nREF\nFemale', 'Male']
checkValues1.push(...getCoefData(data.coefficients.terms.sex.categories[1]))
results = checkTableRow(table, 2, checkValues1)
test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`)

testTerm = 'African Ancestry'
const checkValues2 = ['Genetically defined race\nREFEuropean Ancestry', testTerm]
const checkValues2 = ['Genetically defined race\nREF\nEuropean Ancestry', testTerm]
checkValues2.push(...getCoefData(data.coefficients.terms.genetic_race.categories[testTerm]))
results = checkTableRow(table, 3, checkValues2)
test.equal(results, true, `Should render all ${testTerm} data in ${tableLabel}`)
Expand Down
59 changes: 29 additions & 30 deletions client/plots/regression.results.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ export class RegressionResults {
*/
for (const i of this.parent.inputs.independent.inputLst) {
if (!i.term) continue
if (i.term.term.id == tid || i.term.term.name == tid) return i
if (i.term.term && i.term.term.snps) {
// is a snplst or snplocus term with .snps[]
for (const snp of i.term.term.snps) {
Expand Down Expand Up @@ -186,6 +185,7 @@ export class RegressionResults {
}
}
}
if (i.term.term.id == tid || i.term.term.name == tid) return i
}
// given tid does not match with an Input
// can be an ancestry PC which is automatically added by serverside and not recorded on client
Expand Down Expand Up @@ -603,7 +603,9 @@ function setRenderers(self) {
const [samplesize_ref, samplesize_c] = cols.shift().split('/')
const [eventcnt_ref, eventcnt_c] = cols.shift().split('/')
if (isfirst) {
const refGrpDiv = termNameTd.select('.sjpcb-regression-results-refGrp')
const variableBottomDiv = termNameTd.select('.sjpcb-coef-variable-bottom')
variableBottomDiv.style('align-items', 'baseline')
const refGrpDiv = variableBottomDiv.selectAll('div').filter((d, i) => i === 1)
refGrpDiv.append('div').html(`n=${samplesize_ref}<br>events=${eventcnt_ref}`)
}
td.append('div').style('font-size', '.8em').html(`n=${samplesize_c}<br>events=${eventcnt_c}`)
Expand Down Expand Up @@ -846,7 +848,9 @@ function setRenderers(self) {
const [samplesize_ref, samplesize_c] = cols.shift().split('/')
const [eventcnt_ref, eventcnt_c] = cols.shift().split('/')
if (isfirst) {
const refGrpDiv = termNameTd.select('.sjpcb-regression-results-refGrp')
const variableBottomDiv = termNameTd.select('.sjpcb-coef-variable-bottom')
variableBottomDiv.style('align-items', 'baseline')
const refGrpDiv = variableBottomDiv.selectAll('div').filter((d, i) => i === 1)
refGrpDiv.append('div').html(`n=${samplesize_ref}<br>events=${eventcnt_ref}`)
}
td.append('div').style('font-size', '.8em').html(`n=${samplesize_c}<br>events=${eventcnt_c}`)
Expand Down Expand Up @@ -1399,42 +1403,37 @@ function fillTdName(td, name) {
}
}
function fillCoefficientTermname(tw, td) {
// fill column 1 <td> using term name, may also show refGrp and reference allele
// fill column 1 <td> using term name
fillTdName(td, tw.term.name || tid)
// fill refGrp or effect allele, if applicable
const hasRefGrp = 'refGrp' in tw && tw.refGrp != refGrp_NA && tw.q.mode != 'spline'
if (hasRefGrp || tw.effectAllele) {
// has refGrp or effect allele
// display beneath term name
const bottomDiv = td
.append('div')
.attr('class', 'sjpcb-coef-variable-bottom')
.style('display', 'flex')
.style('align-items', 'center')
.style('margin-top', '2px')
.style('font-size', '.8em')

if (tw.q.mode != 'spline' && 'refGrp' in tw && tw.refGrp != refGrp_NA) {
// do not display ref for spline variable
const refGrpDiv = td.append('div').style('margin-top', '2px').style('font-size', '.8em')
let label
if (hasRefGrp) {
label = tw.term.values && tw.term.values[tw.refGrp] ? tw.term.values[tw.refGrp].label : tw.refGrp
} else {
label = tw.effectAllele
}

refGrpDiv
bottomDiv
.append('div')
.style('display', 'inline-block')
.style('vertical-align', 'top')
.style('padding', '1px 5px')
.style('border', '1px solid #aaa')
.style('border-radius', '10px')
.style('font-size', '.7em')
.text('REF')
.text(hasRefGrp ? 'REF' : 'EFFECT ALLELE')

refGrpDiv
.append('div')
.attr('class', 'sjpcb-regression-results-refGrp')
.style('display', 'inline-block')
.style('vertical-align', 'top')
.style('margin-left', '3px')
.text(tw.term.values && tw.term.values[tw.refGrp] ? tw.term.values[tw.refGrp].label : tw.refGrp)
}

if (tw.effectAllele) {
// only for snplst term
td.append('div')
.style('font-size', '.8em')
.style('opacity', 0.6)
.html(
'<span style="padding:1px 5px;border:1px solid #aaa;border-radius:10px;font-size:.7em">EFFECT ALLELE</span> ' +
tw.effectAllele +
'</span>'
)
bottomDiv.append('div').style('padding', '1px 3px').text(label)
}
}

Expand Down
Loading