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

sample table generation #4

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/pep/config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pep_version: 2.0.0
sample_table: "samples.csv"
sample_table: "UHGG_human-gut-v2-0_genomes.csv"
6 changes: 0 additions & 6 deletions config/pep/samples.csv

This file was deleted.

2 changes: 1 addition & 1 deletion workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ include: "rules/download.smk"
rule all:
input:
expand(
"results/test/{sample}.gff.gz",
"results/test/{sample}.gff",
sample = get_samples(),
),

Expand Down
2 changes: 1 addition & 1 deletion workflow/rules/download.smk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

rule download_rule:
output:
"results/test/{sample}.gff.gz",
"results/test/{sample}.gff",
log:
"logs/test/{sample}.log",
params:
Expand Down
33 changes: 30 additions & 3 deletions workflow/scripts/mgnify_api.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,47 @@
# Sample table assembly from the UHGG Human Gut v2.0 catalogue

import pandas as pd
import requests
import time
import threading
# No threading, no sleep
# could not implement time and threading... yet!


download_URL = "https://www.ebi.ac.uk/metagenomics/api/v1/genome-catalogues/human-gut-v2-0/genomes?format=json"


r = requests.get(download_URL)
data = r.json()
pages_total = data["meta"]["pagination"]["pages"]
IDs = list()

for i in range(1, pages_total + 1):
limiter_for_testing = pages_total - 2 # integrating a limiter to test for only 2 pages (not all, for management/testing reason)



for i in range(1, pages_total + 1 - limiter_for_testing): # limiter_for_testing needs to be taken out for final code
current_URL = download_URL + "&page=" + str(i)
r = requests.get(current_URL)
data = r.json()
innerscope = data["data"]
for result in innerscope:
IDs.append(result["id"])

print(IDs)

download_links_list = list()
for ID in IDs:
download_request_raw = requests.get("https://www.ebi.ac.uk/metagenomics/api/v1/genomes/" + str(ID) + "/downloads")
download_request = download_request_raw.json()
innerscope = download_request["data"]
for element in innerscope:
if ".gff" in element["links"]["self"]:
download_links_list.append(element["links"]["self"])

data_frame = {
"sample_name": IDs,
"url": download_links_list
}

df = pd.DataFrame(data_frame)

df.to_csv("/local/work/ata/gut-brain-modules/config/pep/UHGG_human-gut-v2-0_genomes.csv", index = False) # path can be rewritten with snakemake concepts