ramiromagno / gwasrapidd

gwasrapidd: an R package to query, download and wrangle GWAS Catalog data
https://rmagno.eu/gwasrapidd/
Other
89 stars 15 forks source link

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

Closed Zheng19w closed 10 months ago

Zheng19w commented 10 months ago
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

ramiromagno commented 10 months ago

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:

For example, you can do:

write.table(my_associations@risk_alleles,"muscle measurement.txt",quote = FALSE)
Zheng19w commented 10 months ago

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

ramiromagno commented 10 months ago

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: https://github.com/ramiromagno/gwasrapidd/issues/31.

Zheng19w commented 10 months ago

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 )

Zheng19w commented 10 months ago

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

Zheng19w commented 10 months ago

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

Zheng19w commented 10 months ago

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")

ramiromagno commented 10 months ago

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.