SNP order causing an error

177 views
Skip to first unread message

Jeff Kim

unread,
May 16, 2022, 5:09:14 PM5/16/22
to Genomic SEM Users
Hi everyone,

I am running a common factor GWAS and found a peculiar issue/bug. Essentially when I run a set of SNPs in a certain order while parallel=True, it would cause the error:

error calling combine function: <simpleError in match.names(clabs, names(xi)): names do not match previous names>.

Let's say that there are SNP1 and SNP2. When the GWAS is run with order [SNP1,SNP2], the above error is shown. When the order is reversed, the GWAS runs fine with no lavaan warnings or errors in the results. SNP2 runs fine on its own, but when SNP1 is run on its own, it generates a lavaan error:

lavaan WARNING: the optimizer warns that a solution has NOT been found!

When parallel=F, original order produces the optimizer error but the reversed order again runs without any lavaan warnings.

Below is the sample code I ran. The example was run with core=1, but this issue was originally found with core=30. Rest of the GWAS ran successfully without issues.

# reinstall to ensure that we are running the latest GSEM
devtools::install_github("GenomicSEM/GenomicSEM", force=TRUE)
library(GenomicSEM)

LDSC_PATH <- "bugtest/LDSC.RDS"
SUMSTAT_PATH <- "bugtest/bugtest.Sumstats.RDS"
# set input variables
ldsc_res <- readRDS(LDSC_PATH)
aligned_sumstats <- readRDS(SUMSTAT_PATH)

# 1. test with all in initial order
test_defaultorder <- commonfactorGWAS(
covstruc = ldsc_res,
SNPs = aligned_sumstats[1:2,],
cores=1
)
# this causes error calling combine function
# 2. flip the sumstat order
row1 <- aligned_sumstats[1,]
row2 <- aligned_sumstats[2,]
aligned_sumstats_flipped <- rbind(row2, row1)

test_flipped <- commonfactorGWAS(
covstruc = ldsc_res,
SNPs = aligned_sumstats_flipped,
cores=1
)
# this runs successfully (0.927 seconds) with legible results

# 3. just SNP1
test_snp1 <- commonfactorGWAS(
covstruc = ldsc_res,
SNPs = row1,
cores=1
)
# runs with significantly higher runtime (12 seconds) and produces lavaan error

# 4. just SNP2
test_snp2 <- commonfactorGWAS(
covstruc = ldsc_res,
SNPs = row2,
cores=1
)
# runs successfully (0.589 seconds) with legible results that is identical to flipped test above

# 5. parallel flag set to FALSE
test_defaultorder_noparallel <- commonfactorGWAS(
covstruc = ldsc_res,
SNPs = aligned_sumstats[1:2,],
parallel=F
)
# runs with significantly higher runtime (11 seconds) and produces lavaan error
test_flipped_multicore <- commonfactorGWAS(
covstruc = ldsc_res,
SNPs = aligned_sumstats_flipped,
parallel=F
)
# runs successfully (0.89 seconds) with no lavaan errors

Wanted to make sure this was a bug rather an a potential issue with my LDSC results or summary statistics. I can provide the LDSC results, the summary statistics, and Jupyter Notebook of the above code via email. 

Regards,

Jeff

Matthijs van der Zee

unread,
May 17, 2022, 2:16:33 AM5/17/22
to Genomic SEM Users
Hi Jeff,

Could you send me the summary statitistics and code:
m.d.van...@vu.nl
I'll look into it as I can't think of a reason as to why this would happen...

Best,
Matthijs

Op maandag 16 mei 2022 om 23:09:14 UTC+2 schreef kim...@nih.gov:

Jeff Kim

unread,
May 17, 2022, 11:58:28 AM5/17/22
to Genomic SEM Users
Hi Matthijs,

Thanks for looking into it. Just sent it to your email.

Regards,

Jeff

Ryosuke FUJII

unread,
Oct 7, 2022, 7:20:28 PM10/7/22
to Genomic SEM Users
Hi, everyone.

I am facing the same problem as discussed here.
Using the commonfactorGWAS function, we perform it separately for each chromosome.
It is strange that the error message was shown only for chromosome 4:

error calling combine function:
<simpleError in match.names(clabs, names(xi)): names do not match previous names>
Error in `colnames<-`(`*tmp*`, value = colnamesresults) :
  attempt to set 'colnames' on an object with less than two dimensions
Calls: commonfactorGWAS -> colnames<-
Execution halted


For the other chromosomes except for chr4, the codes successfully completed and I got the results.
If you already find a solution to this problem, please let me know.

Best Regards,
Ryo


2022年5月17日火曜日 17:58:28 UTC+2 kim...@nih.gov:

Jeff Kim

unread,
Nov 4, 2022, 5:41:40 PM11/4/22
to Genomic SEM Users
Hi Ryo,

I haven't heard back but have you tried running it with userGWAS instead? I have had better luck with that function. Just define the Common Factor model like:

          CF =~ trait1 + trait2 + trait3

And make sure the trait with the highest loading is the first one on the model. Let me know if this works.

Regards,

Jeff

agro...@gmail.com

unread,
Nov 8, 2022, 4:11:21 PM11/8/22
to Genomic SEM Users
Hi Jeff and Ryo, 

Apologies for the late response! I just got a separate e-mail with someone else running into this same error. My sense is the package was failing out when their was a SNP for which the model failed to converge (which is why it is working for some chromosomes but not others) and it had to do with mismatch in the column naming. This is also why userGWAS was probably working as we have done more maintenance on that particular function relative to commonfactorGWAS.

 I just put in a small update that might fix this issue for commonfactorGWAS if you re-install Genomic SEM and give it a go, but I'm happy to take a look more closely if you are still getting this error. If you could send the exact code you ran, LDSC output, and the chromosome 4 SNPs I can look and see exactly where things are breaking (apologies as I know code and data was sent before with no response but just turning back to google group after a bit if a hiatus today). 

Best, 
  Andrew

Jeff Kim

unread,
Nov 15, 2022, 6:29:31 AM11/15/22
to Genomic SEM Users
Hi Andrew,

I just sent you the email. Let me know if anything is unclear.

Might be a dumb question/suggestion but: have you thought about refactoring commonfactorGWAS so that the function just calls userGWAS with the model generated by write.Model1? Might make the maintenance easier as you can just focus on adjusting userGWAS (and write.Model1 if necessary) rather than trying to keep commonfactorGWAS function in parity with userGWAS.

Regards,

Jeff

agro...@gmail.com

unread,
Nov 15, 2022, 12:52:19 PM11/15/22
to Genomic SEM Users
Hi Jeff, 

Thanks for passing that along! It looks you did a lot of careful troubleshooting to diagnose exactly what was causing the issue. For whatever reason I'm unable to reproduce the error. I responded to your e-mail with the code I ran and an .RData object that includes the sessionInfo from when I ran it. 

The most obvious discrepancy as far as your and my versions of sessionInfo is that you are running under Linux whereas my code was run under MacOS. That said, I also tried running on our computing cluster which runs Linux and still couldn't reproduce the error. Not sure if anything else jumps out at you as different across our sessions? 

I did put in some updates to try and resolve some of the commonfactorGWAS errors a few weeks back. In my experience, R will generally not use the newest installed version of a package unless you restart the session. I'm guessing this isn't the issue given how much attention to detail you've had with this, but is it possible that even though you are installing GenomicSEM at the beginning of your code that these more recent package updates aren't being loaded in? 

Your point about merging commonfactorGWAS and userGWAS for maintenance reasons is well-taken. commonfactorGWAS has some unique aspects beyond just writing out the common factor model (e.g., it also automatically calculated Q_SNP without having to run a follow-up, independent pathways model as with userGWAS). I'll take a look at the code and consider this as a future update (appreciate the suggestion!). 

Best, 
  Andrew

Jeff Kim

unread,
Dec 9, 2022, 12:18:30 PM12/9/22
to Genomic SEM Users
That's fair Andrew. Automatically calculated Q_SNP is quite handy.

As for the bug, I will take a closer look at it and try reproducing it again. The package has been updated since I ran into this bug so maybe it has been fixed anyway? Again, thanks for your help!

Regards,

Jeff

Reply all
Reply to author
Forward
0 new messages