Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/_run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
required: true
type: string
jobs:
pre-commit:
run-tests:
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 5 additions & 2 deletions nbs_tests/model/model_interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@
"outputs": [],
"source": [
"from peptdeep.model.ms2 import pDeepModel\n",
"from peptdeep.pretrained_models import MODEL_ZIP_FILE_PATH"
"from peptdeep.pretrained_models import MODEL_ZIP_FILE_PATH\n",
"from peptdeep.pretrained_models import download_models"
]
},
{
Expand Down Expand Up @@ -660,9 +661,11 @@
}
],
"source": [
"download_models()\n",
"ms2_model = pDeepModel()\n",
"ms2_model.build_from_py_codes(\n",
" MODEL_ZIP_FILE_PATH, 'generic/ms2.pth.model.py', \n",
" MODEL_ZIP_FILE_PATH,\n",
" 'generic/ms2.pth.model.py',\n",
" include_model_params_yaml=True\n",
")\n",
"\n",
Expand Down
15 changes: 11 additions & 4 deletions peptdeep/pretrained_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def is_model_zip(downloaded_zip):
return any(x == "generic/ms2.pth" for x in zip.namelist())


def download_models(url: str = MODEL_URL, target_path: str = MODEL_ZIP_FILE_PATH):
def download_models(
url: str = MODEL_URL, target_path: str = MODEL_ZIP_FILE_PATH, overwrite: bool = True
):
"""
Parameters
----------
Expand All @@ -77,30 +79,35 @@ def download_models(url: str = MODEL_URL, target_path: str = MODEL_ZIP_FILE_PATH
Defaults to :data:`peptdeep.pretrained_models.MODEL_ZIP_FILE_PATH`

overwrite : bool, optional
overwirte old model files.
overwrite old model files.
Defaults to True.

Raises
------
FileNotFoundError
If remote url is not accessible.
"""
if not overwrite and os.path.exists(target_path):
raise FileExistsError(f"Model file already exists: {target_path}")

if not os.path.isfile(url):
logging.info(f"Downloading {url} ...")
try:
os.makedirs(os.path.dirname(target_path), exist_ok=True)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure why this did not come up earlier

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, because the HOME dir has been created before using downloading?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch.

context = ssl._create_unverified_context()
requests = urllib.request.urlopen(url, context=context, timeout=10)
with open(target_path, "wb") as f:
f.write(requests.read())
except (socket.timeout, urllib.error.URLError, urllib.error.HTTPError):
except Exception as e:
raise FileNotFoundError(
"Downloading model failed! Please download the "
f'zip or tar file by yourself from "{url}",'
" and use \n"
f'"peptdeep --install-model /path/to/{LOCAL_MODAL_ZIP_NAME}.zip"\n'
" to install the models"
)
) from e
else:
os.makedirs(os.path.dirname(target_path), exist_ok=True)
shutil.copy(url, target_path)
logging.info(f"The pretrained models had been downloaded in {target_path}")

Expand Down
1 change: 0 additions & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ torch==2.5.1
tqdm==4.67.1
numba==0.60.0
psutil==6.1.0
biopython==1.84
transformers==4.47.0
scikit-learn==1.6.0
lxml==5.3.0
Expand Down
1 change: 0 additions & 1 deletion requirements/requirements_gui.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

streamlit==1.40.2
streamlit-aggrid==1.0.5
1 change: 0 additions & 1 deletion requirements/requirements_gui_loose.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@

streamlit>=1.23.0 # test: tolerate_version
streamlit-aggrid
1 change: 0 additions & 1 deletion requirements/requirements_loose.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ torch
tqdm
numba
psutil
biopython
transformers
scikit-learn
lxml
Expand Down
Loading