-
Notifications
You must be signed in to change notification settings - Fork 195
Add checksum verification for ENSEMBL sequence and annotation wrappers #36
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
base: master
Are you sure you want to change the base?
Changes from all commits
f8e4e1e
8e8ecda
33596a4
f33330c
9a3cb75
3f3ff39
4d49205
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
name: ensembl-annotation | ||
description: Download annotation of genomic sites (e.g. transcripts) from ENSEMBL FTP servers, and store them in a single .gtf or .gff3 file. | ||
description: Download annotation of genomic sites (e.g. transcripts) from ENSEMBL FTP servers, and store them in a single .gtf or .gff3 file. After download compare checksums with ENSEMBL FTP 'CHECKSUMS' file. | ||
authors: | ||
- Johannes Köster | ||
- Fritjof Lammers |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,21 +2,45 @@ | |||||
__copyright__ = "Copyright 2019, Johannes Köster" | ||||||
__email__ = "johannes.koester@uni-due.de" | ||||||
__license__ = "MIT" | ||||||
__contributor__= "Johannes Köster, Fritjof Lammers" | ||||||
|
||||||
import sys | ||||||
sys.stderr = open(snakemake.log[0], "w") | ||||||
|
||||||
from ftplib import FTP | ||||||
from io import StringIO | ||||||
from subprocess import run | ||||||
from os.path import basename | ||||||
import csv | ||||||
|
||||||
species = snakemake.params.species.lower() | ||||||
release = snakemake.params.release | ||||||
fmt = snakemake.params.fmt | ||||||
build = snakemake.params.build | ||||||
|
||||||
|
||||||
def verify_checksum(reader): | ||||||
for fields in csv.reader(reader, sep="\t"): | ||||||
cksum = int(fields[0]) | ||||||
filename = fields[2] | ||||||
if filename == basename(snakemake.output[0]): | ||||||
cksum_local = int(run(["sum", snakemake.output[0]], capture_output=True).stdout.strip().split()[0]) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, we should use Pythons internal checksum implementation. |
||||||
if cksum_local == cksum: | ||||||
print("CHECKSUM OK: %s" % snakemake.output[0]) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
exit(0) | ||||||
else: | ||||||
print("CHECKSUM FAILED: %s" % snakemake.output[0]) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
exit(1) | ||||||
else: | ||||||
print("No matching file for CHECKSUM test found", file=sys.stderr) | ||||||
continue | ||||||
|
||||||
suffix = "" | ||||||
if fmt == "gtf": | ||||||
suffix = "gtf.gz" | ||||||
elif fmt == "gff3": | ||||||
suffix = "gff3.gz" | ||||||
|
||||||
|
||||||
with FTP("ftp.ensembl.org") as ftp, open(snakemake.output[0], "wb") as out: | ||||||
ftp.login() | ||||||
ftp.retrbinary( | ||||||
|
@@ -30,3 +54,18 @@ | |||||
), | ||||||
out.write, | ||||||
) | ||||||
|
||||||
checksum_reader = StringIO() | ||||||
ftp.retrlines( | ||||||
"RETR pub/release-{release}/{fmt}/{species}/CHECKSUMS".format( | ||||||
release=release, | ||||||
build=build, | ||||||
species=species, | ||||||
fmt=fmt, | ||||||
species_cap=species.capitalize(), | ||||||
), | ||||||
lambda s, w=checksum_reader.write: w(s + '\n'), | ||||||
# use StringIO instance for callback, add "\n" because ftplib.retrlines omits newlines | ||||||
) | ||||||
|
||||||
verify_checksum(checksum_reader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once this wrapper has been polished, changes should be transferred to the other wrapper in this PR: