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

[BUG]:Failed to connect to api.opengwas.io port 443: Connection refused #580

Open
Suuzh0329 opened this issue Dec 28, 2024 · 4 comments
Open
Labels

Comments

@Suuzh0329
Copy link

Suuzh0329 commented Dec 28, 2024

Error in api_query("user", opengwas_jwt = opengwas_jwt, override_429 = TRUE) :
The following error was encountered in trying to query the MR-Base server:
Error in curl::curl_fetch_memory(url, handle = handle): Couldn't connect to server [api.opengwas.io]: Failed to connect to api.opengwas.io port 443: Connection refused
When I use the package TwoSample MR, it couldn't query the MR-base, could you please grant me the access? Thank you very much!

@Suuzh0329 Suuzh0329 added the bug label Dec 28, 2024
@Suuzh0329 Suuzh0329 changed the title [BUG]: when I use the package TwoSample MR, it couldn't query the MR-base, could you please grant me the access? Thank you very much [BUG]:Failed to connect to api.opengwas.io port 443: Connection refused Dec 28, 2024
@Suuzh0329 Suuzh0329 reopened this Dec 28, 2024
@TheodoreLevitt
Copy link

facing the same issue. Could you please help if you have solve the issues

@MRCIEU MRCIEU deleted a comment from TheodoreLevitt Jan 29, 2025
@TheodoreLevitt
Copy link

@mrciu.. could you please at least let us know if this package is working at all.. even the tutorial is not working ..
Do u think this package is repairable.

Please dont delete comments.. rather answer something so that we can understand....
Everything was working fine and now when i have to submit my thesis...its annoying .. at least if you all comment about the problem ...we user know ...being silent when other users are suffering .. that annoying

@TheodoreLevitt
Copy link

TheodoreLevitt commented Jan 30, 2025

@mrciu .. any suggestion or brief tutorial ?? or is it possible we can access the dataset at FTP ??? we would be thankful if we get any suggestions..

@TheodoreLevitt
Copy link

If others are looking for alternative approaches... This might be one solution but manually you have to download dataset

import numpy as np
import scipy.stats as stats

def two_sample_mr_test(exposure_snps, exposure_betas, exposure_ses,
outcome_snps, outcome_betas, outcome_ses):
# Ensure SNPs are aligned
common_snps = list(set(exposure_snps) & set(outcome_snps))

if len(common_snps) == 0:
    raise ValueError("No common SNPs between exposure and outcome")

# Extract aligned data
aligned_exposure_betas = [exposure_betas[exposure_snps.index(snp)] for snp in common_snps]
aligned_exposure_ses = [exposure_ses[exposure_snps.index(snp)] for snp in common_snps]
aligned_outcome_betas = [outcome_betas[outcome_snps.index(snp)] for snp in common_snps]
aligned_outcome_ses = [outcome_ses[outcome_snps.index(snp)] for snp in common_snps]

# Inverse variance weighted method
weights = 1 / np.array(aligned_outcome_ses)**2
causal_effect = np.sum(weights * np.array(aligned_exposure_betas) * np.array(aligned_outcome_betas)) / np.sum(weights)

# Standard error of causal effect
se_causal_effect = np.sqrt(1 / np.sum(weights))

# Calculate t-statistic and p-value
t_statistic = causal_effect / se_causal_effect
p_value = 2 * (1 - stats.t.cdf(abs(t_statistic), df=len(common_snps)-1))

return causal_effect, se_causal_effect, p_value

Example usage

np.random.seed(42)

Simulated exposure SNPs

exposure_snps = ['rs1', 'rs2', 'rs3', 'rs4', 'rs5']
exposure_betas = [0.1, 0.2, 0.15, 0.18, 0.12]
exposure_ses = [0.05, 0.04, 0.06, 0.05, 0.07]

Simulated outcome SNPs

outcome_snps = ['rs1', 'rs2', 'rs3', 'rs4', 'rs5']
outcome_betas = [0.2, 0.25, 0.18, 0.22, 0.15]
outcome_ses = [0.06, 0.05, 0.07, 0.06, 0.08]

Perform two-sample MR test

causal_effect, se, p_value = two_sample_mr_test(
exposure_snps, exposure_betas, exposure_ses,
outcome_snps, outcome_betas, outcome_ses
)

print("Two-Sample MR Test Results:")
print(f"Causal Effect Estimate: {causal_effect:.4f}")
print(f"Standard Error: {se:.4f}")
print(f"P-value: {p_value:.4f}")
print(f"Significant at 5% level: {p_value < 0.05}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants