ramiromagno/gwasrapidd

How do I export `my_associations` to a table file, separated by tabs

Closed this issue · 8 comments

library(gwasrapidd)
child_traits <- gwasrapidd::get_child_efo("EFO_0004515")$EFO_0004515
child_traits_in_gwas_cat <- all_traits[child_traits]
my_associations <- get_associations(efo_id = c("EFO_0004515", child_traits_in_gwas_cat@traits$efo_id))
my_associations1 <- my_associations 
write.table(my_associations,"muscle measurement.txt",quote = FALSE)

error 
Error in as.data.frame.default(x[[i]], optional = TRUE) : 
  cannot coerce class ‘structure("associations", package = "gwasrapidd")’ to a data.frame

I would like to obtain information on the location of snp loci

Your my_associations object contains the tables. This is explain in the documentation: https://rmagno.eu/gwasrapidd/reference/associations-class.html.

Each of these gives you an individual data frame:

  • my_associations@associations
  • my_associations@loci
  • my_associations@risk_alleles
  • my_associations@genes
  • my_associations@ensembl_ids
  • my_associations@entrez_ids

For example, you can do:

write.table(my_associations@risk_alleles,"muscle measurement.txt",quote = FALSE)

image
image
I have a problem. The exported location information is different from the GWAS catalog page
I want to get the specific chromosome number and the corresponding position information

The column locus_id is not the genomic location as indicated in Location in the web app. Again, see the documentation that clarifies the meaning of each column: https://rmagno.eu/gwasrapidd/reference/associations-class.html.

To actually get genomic coordinates for your variants, see this similar question: #31.

Dear ramiromagno,

Thank you very much for developing this excellent tool, my R language is not very good, I am not sure how to modify the code, to get the coordinate information I want, can you help me, thank you

library(gwasrapidd)

study_id <- "GCST004132"
associations <- get_associations(study_id = study_id)
variants <- get_variants(study_id = study_id)

genes <- associations@genes %>%
dplyr::group_by(association_id, locus_id) %>%
dplyr::summarise(gene_name = paste(gene_name, collapse = ' '), .groups = 'drop')

association_results <-
associations@associations %>%
dplyr::select(association_id, pvalue, beta_number, or_per_copy_number) %>%
dplyr::left_join(associations@risk_alleles, by = 'association_id') %>%
dplyr::left_join(genes, by = c('association_id', 'locus_id')) %>%
dplyr::left_join(variants@variants, by = c('variant_id')) %>%
dplyr::transmute(
study_id = study_id,
association_id = association_id,
ID = variant_id,
CHROM = chromosome_name,
POS = chromosome_position,
risk_allele = risk_allele,
gene_name = gene_name,
P = pvalue,
beta = beta_number,
OR = or_per_copy_number
)

Dear ramiromagno,

Thank you very much for developing this excellent tool, my R language is not very good, I am not sure how to modify the code, to get the coordinate information I want, can you help me, thank you

I have tried to solve this problem, thank you very much for your answer, wish you a happy life!

child_traits <- gwasrapidd::get_child_efo("EFO_0004515")$EFO_0004515
child_traits_in_gwas_cat <- all_traits[child_traits]
associations <- get_associations(efo_id = c("EFO_0004515", child_traits_in_gwas_cat@traits$efo_id))
variants <- get_variants(efo_id = c("EFO_0004515", child_traits_in_gwas_cat@traits$efo_id))

genes <- associations@genes %>%
dplyr::group_by(association_id, locus_id) %>%
dplyr::summarise(gene_name = paste(gene_name, collapse = ' '), .groups = 'drop')

association_results <-
associations@associations %>%
dplyr::select(association_id, pvalue, beta_number, or_per_copy_number) %>%
dplyr::left_join(associations@risk_alleles, by = 'association_id') %>%
dplyr::left_join(genes, by = c('association_id', 'locus_id')) %>%
dplyr::left_join(variants@variants, by = c('variant_id')) %>%
dplyr::transmute(

association_id = association_id,
ID = variant_id,
CHROM = chromosome_name,
POS = chromosome_position,
risk_allele = risk_allele,
gene_name = gene_name,
P = pvalue,
beta = beta_number,
OR = or_per_copy_number

)

write.table(association_results,"muscle measurement.txt",quote = FALSE,,row.names = FALSE,
col.names = FALSE,sep = "\t")

Hi @Zheng19w:

I am not sure if you managed to solve your problem, or whether you still need help. If the latter, just let me know. Otherwise I will close this issue.