File: rebase_update.py

package info (click to toggle)
python-biopython 1.85%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 126,372 kB
  • sloc: xml: 1,047,995; python: 332,722; ansic: 16,944; sql: 1,208; makefile: 140; sh: 81
file content (64 lines) | stat: -rw-r--r-- 2,130 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
#
#      Restriction Analysis Libraries.
#      Copyright (C) 2004. Frederic Sohm.
#
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.
#
"""Update the Rebase EMBOSS files and NCBI LinkOut files.

These two sets of files are used by ``ranacompiler.py`` to build the updated
``Restriction_Dictionary.py`` module for ``Bio.Restriction``.

"""

import os
from datetime import date
from urllib.request import urlcleanup
from urllib.request import urlretrieve

# Rebase ftp location, do not modify these addresses:
ftp_Rebase = "ftp://ftp.neb.com/"
ftp_emb_e = ftp_Rebase + "pub/rebase/emboss_e.###"
ftp_emb_s = ftp_Rebase + "pub/rebase/emboss_s.###"
ftp_emb_r = ftp_Rebase + "pub/rebase/emboss_r.###"
ftp_bairoch = ftp_Rebase + "pub/rebase/bairoch.###"

# Generate 'time stamp' of type ymm to add to Rebase file names.
# This is the 3 digit number REBASE release number (e.g. 312).
# The first digit is the last digit of the year (e.g. 3 for 2013)
# and the two last the month (e.g. 12 for December)
release_number = date.today().strftime("%y%m")[1:]

# Replace '###' with the 'time stamp'
files = [
    x.replace("###", release_number)
    for x in [ftp_emb_e, ftp_emb_s, ftp_emb_r, ftp_bairoch]
]


def get_files():
    """Download Rebase and LinkOut files."""
    print(f"Preparing to download {len(files)} files")
    for file in files:
        print(f"copying {file}")
        fn = os.path.basename(file)
        filename = os.path.join(os.getcwd(), fn)
        print(f"to {filename}")
        try:
            urlretrieve(file, filename)
            urlcleanup()
        except OSError as e:
            print(e)
            print(
                "Download of Rebase files failed. Please download the files "
                f'"emboss_e.{release_number}", "emboss_s.{release_number}", "emboss_r.{release_number}", and "bairoch.{release_number}" manually '
                "from: ftp://ftp.neb.com/pub/rebase."
            )
            return


if __name__ == "__main__":
    get_files()