Skip to content

Commit

Permalink
ENH Set macrel/{__version__} as user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
luispedro committed Jun 28, 2024
1 parent 0ab399b commit 3fd5e41
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 16 deletions.
15 changes: 10 additions & 5 deletions macrel/ampsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
import logging

from macrel.utils import open_output
from macrel.macrel_version import __version__

REQUESTS_HEADER = {
'User-Agent': f'macrel/{__version__} (python-requests)'
}

def get_cache_directory(args):
'''Get cache directory'''
Expand Down Expand Up @@ -40,7 +45,7 @@ def maybe_download_ampsphere_mmseqs(args):
AMPSPHERE_MMSEQS2_URL = 'https://ampsphere-api.big-data-biology.org/v1/downloads/AMPSphere_latest.mmseqsdb.tar.xz'
with tempfile.TemporaryDirectory() as tmpdir:
tfile = path.join(tmpdir, 'AMPSphere_latest.mmseqsdb.tar.xz')
r = requests.get(AMPSPHERE_MMSEQS2_URL, stream=True)
r = requests.get(AMPSPHERE_MMSEQS2_URL, stream=True, headers=REQUESTS_HEADER)
with open(tfile, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
Expand Down Expand Up @@ -111,7 +116,7 @@ def maybe_download_ampsphere_faa(args):
if args.no_download_database:
return None
URL = 'https://zenodo.org/records/6511404/files/AMPSphere_v.2022-03.faa.gz?download=1'
r = requests.get(URL, stream=True)
r = requests.get(URL, stream=True, headers=REQUESTS_HEADER)
with open_output(target, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
Expand Down Expand Up @@ -144,15 +149,15 @@ def get_ampsphere_exact_match_local(args, seqs):
def get_ampsphere_exact_match(seq, query_name):
'''Get exact match from AMPSphere API'''
URL = f'https://ampsphere-api.big-data-biology.org/v1/search/sequence-match?query={seq}'
response = requests.get(URL)
response = requests.get(URL, headers=REQUESTS_HEADER)
data = response.json()
return pd.DataFrame.from_dict({query_name : data}, orient='index')

def get_ampsphere_mmseqs_match(seq, query_name):
'''Get MMSeqs2 match from AMPSphere API'''
query = f'>{query_name}\n{seq}'
URL = f'https://ampsphere-api.big-data-biology.org/v1/search/mmseqs?query={query}'
response = requests.get(URL)
response = requests.get(URL, headers=REQUESTS_HEADER)
data = response.json()
return pd.DataFrame.from_dict(data)\
.drop("alignment_strings", axis=1)\
Expand All @@ -162,7 +167,7 @@ def get_ampsphere_hmmer_match(seq, query_name):
'''Get HMMER match from AMPSphere API'''
query = f'>{query_name}\n{seq}'
URL = f'https://ampsphere-api.big-data-biology.org/v1/search/hmmer?query={query}'
response = requests.get(URL)
response = requests.get(URL, headers=REQUESTS_HEADER)
data = response.json()
if not data:
return pd.DataFrame()
Expand Down
2 changes: 1 addition & 1 deletion macrel/macrel_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.4.0'
__version__ = '1.5.0.dev0'
2 changes: 1 addition & 1 deletion tests/contigs.cluster/expected.prediction
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
Access Sequence AMP_family AMP_probability Hemolytic Hemolytic_probability
smORF_2 RFLIKMVKVNLMNGKLIRKISLM CLP 0.634 Hemo 0.871
smORF_19 FFNDGKGTIYYGIKKYFRIYF CLP 0.673 Hemo 0.822
2 changes: 1 addition & 1 deletion tests/contigs.nosmorfs/expected.percontigs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
# Macrel calculated for the sample a density of 0.000 AMPs / Mbp.
contig length ORFs smORFs AMPs
scaffold2530_2_MH0058 1324 1 0 0
2 changes: 1 addition & 1 deletion tests/contigs.nosmorfs/expected.prediction
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
Access Sequence AMP_family AMP_probability Hemolytic Hemolytic_probability
2 changes: 1 addition & 1 deletion tests/contigs/expected.percontigs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
# Macrel calculated for the sample a density of 45.062 AMPs / Mbp.
contig length ORFs smORFs AMPs
C4060843_1_MH0058 518 1 1 0
Expand Down
2 changes: 1 addition & 1 deletion tests/contigs/expected.prediction
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
Access Sequence AMP_family AMP_probability Hemolytic Hemolytic_probability
scaffold75334_1_MH0058_1 RFLIKMVKVNLMNGKLIRKISLM CLP 0.634 Hemo 0.871
scaffold33693_17_MH0058_2 FFNDGKGTIYYGIKKYFRIYF CLP 0.673 Hemo 0.822
2 changes: 1 addition & 1 deletion tests/peptides/expected.prediction
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
Access Sequence AMP_family AMP_probability Hemolytic Hemolytic_probability
AP00002|AMP YVPLPNVPQPGRRPFPTFPGQGPFNPKIKWPQGY CLP 0.861 Hemo 0.663
AP00007|AMP GNNRPVYIPQPRPPHPRL CLP 0.970 Hemo 0.515
Expand Down
2 changes: 1 addition & 1 deletion tests/reads.se/expected.percontigs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
# Macrel calculated for the sample a density of 59.743 AMPs / Mbp.
contig length ORFs smORFs AMPs
k47_0 3379 4 2 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reads.se/expected.prediction
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
Access Sequence AMP_family AMP_probability Hemolytic Hemolytic_probability
k47_10_1 RFLIKMVKVNLMNGKLIRKISLM CLP 0.634 Hemo 0.871
k47_11_1 FFNDGKGTIYYGIKKYFRIYF CLP 0.673 Hemo 0.822
2 changes: 1 addition & 1 deletion tests/reads/expected.percontigs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
# Macrel calculated for the sample a density of 57.627 AMPs / Mbp.
contig length ORFs smORFs AMPs
k77_11 1303 2 1 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reads/expected.prediction
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Prediction from macrel v1.4.0
# Prediction from macrel v1.5.0.dev0
Access Sequence AMP_family AMP_probability Hemolytic Hemolytic_probability
k77_12_1 RFLIKMVKVNLMNGKLIRKISLM CLP 0.634 Hemo 0.871
k77_15_1 FFNDGKGTIYYGIKKYFRIYF CLP 0.673 Hemo 0.822

0 comments on commit 3fd5e41

Please sign in to comment.