Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.pyc
.cache
birdy.egg-info
birdy.log
build
Expand Down
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python
python:
- "3.5"
env:
- TOX_ENV=flake8
- TOX_ENV=py27
- TOX_ENV=py33
- TOX_ENV=py34
- TOX_ENV=py35
install:
- pip install tox
script:
- tox -e $TOX_ENV
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include LICENCE
include README.md
include requirements.txt
include requirements-dev.txt
include tox.ini
recursive-include tests *
recursive-include scripts *
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Birdy

all: install

install:
python setup.py install

install-dev:
pip install -r requirements-dev.txt
python setup.py develop

clean:
find . -name '*.pyc' -delete
find . -name '__pycache__' -type d | xargs rm -fr

distclean: clean
rm -fr *.egg *.egg-info/

test:
venv/bin/py.test -vs tests/
21 changes: 21 additions & 0 deletions birdy/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
Python2/3 compatibility library
"""
import os


def makedirs(path, exist_ok=False):
"""Compatibility layer for os.makedirs"""
# Python 3
try:
os.makedirs(path, exist_ok=exist_ok)
except TypeError:
# Python 2
try:
os.makedirs(path)
except OSError as e:
# We do not care if the directory already exists
if e.errno == 17 and exist_ok is True:
pass
else:
raise
2 changes: 1 addition & 1 deletion birdy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
DSSP_ID_URL = 'ftp://' + DSSP_FTP_HOST + DSSP_FTP_PATH + '{id}.dssp'

# -- InterProScan
INTERPRO_IDS_URL = 'ftp://ftp.ebi.ac.uk/pub/databases/interpro/Current/interpro.xml.gz' # NOPEP8
INTERPRO_IDS_URL = 'ftp://ftp.ebi.ac.uk/pub/databases/interpro/current/interpro.xml.gz' # NOPEP8
INTERPRO_ID_URL = 'http://www.ebi.ac.uk/interpro/entry/{id}/proteins-matched?export={fmt}' # NOPEP8
INTERPRO_MAX_PROTEIN_COUNT = 50

Expand Down
8 changes: 4 additions & 4 deletions birdy/converter/clustal.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def generate_clustal_set(output_path, formats, input_ids=None, use_cache=True):
use_cache=use_cache
)

alignements = []
alignments = []
for ipro in output_files:
alignements += [clustalw(ipro)]
alignments += [clustalw(ipro)]
logging.info(
"{} files have been aligned with clustalw".format(len(alignements))
"{} files have been aligned with clustalw".format(len(alignments))
)

logging.info("CLUSTAL | Execution time was {:.3f} s".format(t.secs))

return alignements
return alignments
9 changes: 5 additions & 4 deletions birdy/fetcher/dssp.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import logging
import os.path
import sys
import urllib.request

from ftplib import FTP
from six.moves.urllib import request

from .. import config
from ..compat import makedirs
from ..utils import get_random_ids, Timer


Expand All @@ -32,7 +33,7 @@ def get_dssp_ids(use_cache=True):
logging.info("Updating DSSP ids cache...")

# Create cache directory if it does not exists
os.makedirs(config.IDS_LIST_CACHE_ROOT, exist_ok=True)
makedirs(config.IDS_LIST_CACHE_ROOT, exist_ok=True)

# Fetch ids
ftp = FTP(config.DSSP_FTP_HOST)
Expand Down Expand Up @@ -78,12 +79,12 @@ def fetch_dssp(ID, output_path='.'):
fmt_path = os.path.join(output_path, fmt)
output_file = os.path.join(fmt_path, filename)

os.makedirs(fmt_path, exist_ok=True)
makedirs(fmt_path, exist_ok=True)

url = config.DSSP_ID_URL.format(id=ID)

try:
urllib.request.urlretrieve(url, output_file)
request.urlretrieve(url, output_file)
except:
logging.error(
"Cannot fetch id {id} from the CMBI. "
Expand Down
9 changes: 5 additions & 4 deletions birdy/fetcher/interpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import os
import os.path
import requests
import urllib.request
import xmltodict

from gzip import GzipFile
from six.moves.urllib import request

from .. import config
from ..compat import makedirs
from ..exceptions import NetworkError
from ..utils import get_random_ids, Timer

Expand All @@ -32,7 +33,7 @@ def get_interpro_ids(use_cache=True):
logging.info("Updating interpro ids cache. This may take minutes...")

# Create cache directory if it does not exists
os.makedirs(config.IDS_LIST_CACHE_ROOT, exist_ok=True)
makedirs(config.IDS_LIST_CACHE_ROOT, exist_ok=True)

ids = []

Expand All @@ -56,7 +57,7 @@ def select_interpro_entries(path, item):

# Attention, tricky part
# We stream ftp response in a GzipFile that is streamed by xmltodict
with urllib.request.urlopen(config.INTERPRO_IDS_URL) as f:
with request.urlopen(config.INTERPRO_IDS_URL) as f:
xmltodict.parse(
GzipFile(fileobj=f),
item_depth=2,
Expand Down Expand Up @@ -100,7 +101,7 @@ def fetch_interpro(ID, fmt='fasta', output_path='.'):

output_file = os.path.join(output_path, filename)

os.makedirs(output_path, exist_ok=True)
makedirs(output_path, exist_ok=True)

url = config.INTERPRO_ID_URL.format(id=ID, fmt=fmt)

Expand Down
5 changes: 3 additions & 2 deletions birdy/fetcher/kegg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests

from .. import config
from ..compat import makedirs
from ..exceptions import NetworkError
from ..utils import get_random_ids, Timer

Expand Down Expand Up @@ -32,7 +33,7 @@ def get_kegg_ids(db, use_cache=True):
logging.info("Updating KEGG ids cache for {} database...".format(db))

# Create cache directory if it does not exists
os.makedirs(config.KEGG_IDS_LIST_CACHE_ROOT, exist_ok=True)
makedirs(config.KEGG_IDS_LIST_CACHE_ROOT, exist_ok=True)

url = config.KEGG_API_URL.format(
operation='list', argument=db
Expand Down Expand Up @@ -83,7 +84,7 @@ def fetch_kegg(ID, db, output_path='.'):
db_fmt_path = os.path.join(output_path, fmt, db)
output_file = os.path.join(db_fmt_path, filename)

os.makedirs(db_fmt_path, exist_ok=True)
makedirs(db_fmt_path, exist_ok=True)

url = config.KEGG_API_URL.format(operation='get', argument=ID)

Expand Down
3 changes: 2 additions & 1 deletion birdy/fetcher/ncbi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from Bio_Eutils import Entrez

from .. import config
from ..compat import makedirs
from ..exceptions import ConfigurationError
from ..utils import get_random_ids, Timer

Expand Down Expand Up @@ -52,7 +53,7 @@ def fetch_ncbi(ID, db, fmt='fasta', output_path='.'):
db_fmt_path = os.path.join(output_path, fmt, db)
output_file = os.path.join(db_fmt_path, filename)

os.makedirs(db_fmt_path, exist_ok=True)
makedirs(db_fmt_path, exist_ok=True)

handle = Entrez.efetch(db=db, id=ID, rettype=fmt, retmode="text")
response = handle.read()
Expand Down
9 changes: 5 additions & 4 deletions birdy/fetcher/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import os.path
import requests
import sys
import urllib.request
from six.moves.urllib import request


from .. import config
from ..compat import makedirs
from ..exceptions import NetworkError, UnsupportedFormatError
from ..utils import get_random_ids, Timer

Expand All @@ -33,7 +34,7 @@ def get_pdb_ids(use_cache=True):
logging.info("Updating PDB ids cache...")

# Create cache directory if it does not exists
os.makedirs(config.IDS_LIST_CACHE_ROOT, exist_ok=True)
makedirs(config.IDS_LIST_CACHE_ROOT, exist_ok=True)

# Fetch PDB ids
response = requests.get(config.PDB_IDS_URL)
Expand Down Expand Up @@ -88,12 +89,12 @@ def fetch_pdb(ID, fmt='pdb', output_path='.'):
fmt_path = os.path.join(output_path, fmt)
output_file = os.path.join(fmt_path, filename)

os.makedirs(fmt_path, exist_ok=True)
makedirs(fmt_path, exist_ok=True)

url = config.PDB_ID_URL.format(fmt=fmt, idx=ID[1:3], filename=filename)

try:
urllib.request.urlretrieve(url, output_file)
request.urlretrieve(url, output_file)
except:
logging.error(
"Cannot fetch id {id} from the PDB. Request url was: {url}".format(
Expand Down
11 changes: 8 additions & 3 deletions birdy/wrappers/clustalw.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,23 @@ def clustalw(filename):
filename: a multi-fasta file path

Returns:
the output alignement filename
the output alignment filename
"""
logging.info("Will align {} file with clustalw".format(filename))

base, ext = os.path.splitext(filename)
log_filename = '{base}.{ext}'.format(base=base, ext='log')

cmd = '{bin} {filename}'.format(bin=config.CLUSTALW, filename=filename)
cmd = '{bin} {filename}'.format(
bin=config.CLUSTALW,
filename=os.path.basename(filename)
)

try:
with open(log_filename, "w+") as log_file:
subprocess.call(cmd, stdout=log_file, shell=True)
subprocess.call(
cmd, stdout=log_file, shell=True, cwd=os.path.dirname(filename)
)
except:
logging.error('Clustal alignment failed. Command was: {}'.format(cmd))
logging.debug(sys.exc_info()[0])
Expand Down
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@

# lint
flake8==2.4.1

# tests
pytest
pytest-runner
tox
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ Bio-Eutils>=1.65
docopt>=0.6.1
requests>=2.7.0
schema>=0.3.1
six>=1.10.0
xmltodict>=0.9.2
Empty file added tests/__init__.py
Empty file.
Loading