File: rebase_update.py

package info (click to toggle)
python-biopython 1.78%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 65,756 kB
  • sloc: python: 221,141; xml: 178,777; ansic: 13,369; sql: 1,208; makefile: 131; sh: 70
file content (61 lines) | stat: -rw-r--r-- 1,906 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
#!/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.

The Rebase EMBOSS 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 urlretrieve, urlcleanup


# 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.###"

# 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]]


def get_files():
    """Download Rebase 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 "
                '"emboss_e.{0}", "emboss_s.{0}" and "emboss_r.{0}" manually '
                "from: ftp://ftp.neb.com/pub/rebase.".format(release_number)
            )
            return
    return


if __name__ == "__main__":
    get_files()