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

Error in if (tvar < 0) { : argument is of length zero #101

Open
lydiayliu opened this issue Mar 31, 2023 · 0 comments
Open

Error in if (tvar < 0) { : argument is of length zero #101

lydiayliu opened this issue Mar 31, 2023 · 0 comments
Assignees

Comments

@lydiayliu
Copy link

Error in if (tvar < 0) { : argument is of length zero
Calls: run_clonal_ASCAT -> recalc_psi_t -> is.segment.clonal -> <Anonymous>
Execution halted

As the error suggests, it happens in fit.copy.number -> run_clonal_ASCAT -> recalc_psi_t -> is.segment.clonal

After a long debugging session, I believe the cause of the issue is that somehow in is.segment.clonal, the segment is calculated to have negative nMajor even after nMinor gets adjusted to 0.01.

battenberg/R/clonal_ascat.R

Lines 384 to 403 in 4368667

# check for big shifts in nMajor - if there's a big shift, we shouldn't trust a clonal call
nMajor.saved = nMajor
## to make sure we're always in a positive square:
#if(nMajor < 0) {
# nMajor = 0.01
#}
#
#if(nMinor < 0) {
# nMinor = 0.01
#}
#DCW - increase nMajor and nMinor together, to avoid impossible combinations (with negative subclonal fractions)
if(nMinor<0){
if(BAFreq==1){
#avoid calling infinite copy number
nMajor = 1000
}else{
nMajor = nMajor + BAFreq * (0.01 - nMinor) / (1-BAFreq)
}
nMinor = 0.01
}

This results in the following two values
test.BAF_levels = c(NA, NA)
whichclosestlevel.test = integer(0)
going in to the function where the error accors
calc_Pvalue_t_twotailed( BAF.size, BAFreq, BAF.sd, test.BAF_levels[whichclosestlevel.test], maxdist_BAF)

calc_Pvalue_t_twotailed <-function( sample_size, sample_mean, sample_SD, mu_pop, max_dist) # kjd 18-12-2013
{
tvar = ( sample_mean - mu_pop ) * sqrt( sample_size ) / sample_SD
if( tvar < 0 )
{
lower_tail_prob = pt( tvar , df = sample_size - 1 , lower.tail = TRUE )
}else
{
lower_tail_prob = 1 - pt( tvar , df = sample_size - 1 , lower.tail = TRUE )
}
pval = 2 * lower_tail_prob
#DCW 250314
if(abs(sample_mean - mu_pop)<max_dist){
pval = 1
}
return( pval )
}

The error gets triggered, because tvar cannot be calculated as mu_pop is logical(0)

I'm trying to resolve this issue by adding a new condition that sets pval = 0 if length(test.BAF_levels[whichclosestlevel.test]) == 0

battenberg/R/clonal_ascat.R

Lines 433 to 440 in 4368667

#270713 - problem caused by segments with constant BAF (usually 1 or 2)
if(BAF.sd==0){
pval=0
}else{
#pval[i] = t.test(BAFreq,alternative="two.sided",mu=BAF_levels[whichclosestlevel])$p.value
#pval = t.test(BAFreq,alternative="two.sided",mu=test.BAF_levels[whichclosestlevel.test])$p.value
pval = calc_Pvalue_t_twotailed( BAF.size, BAFreq, BAF.sd, test.BAF_levels[whichclosestlevel.test], maxdist_BAF)
}

@jcesar101 jcesar101 self-assigned this May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants