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
20 changes: 10 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ All types of contributions are encouraged and valued. See the [Table of Contents
## Code of Conduct

This project and everyone participating in it is governed by the
[profet Code of Conduct](https://github.com/alan-turing-institute/profetblob/master/CODE_OF_CONDUCT.md).
[profet Code of Conduct](https://github.com/ccpem/profetblob/master/CODE_OF_CONDUCT.md).
By participating, you are expected to uphold this code. Please report unacceptable behavior
to <>.


## I Have a Question

> If you want to ask a question, we assume that you have read the available [Documentation](https://github.com/alan-turing-institute/profet).
> If you want to ask a question, we assume that you have read the available [Documentation](https://github.com/ccpem/profet).

Before you ask a question, it is best to search for existing [Issues](https://github.com/alan-turing-institute/profet/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.
Before you ask a question, it is best to search for existing [Issues](https://github.com/ccpem/profet/issues) that might help you. In case you have found a suitable issue and still need clarification, you can write your question in this issue. It is also advisable to search the internet for answers first.

If you then still feel the need to ask a question and need clarification, we recommend the following:

- Open an [Issue](https://github.com/alan-turing-institute/profet/issues/new).
- Open an [Issue](https://github.com/ccpem/profet/issues/new).
- Provide as much context as you can about what you're running into.
- Provide project and platform versions (nodejs, npm, etc), depending on what seems relevant.

Expand All @@ -61,8 +61,8 @@ We will then take care of the issue as soon as possible.
A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible.

- Make sure that you are using the latest version.
- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://github.com/alan-turing-institute/profet). If you are looking for support, you might want to check [this section](#i-have-a-question)).
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/alan-turing-institute/profetissues?q=label%3Abug).
- Determine if your bug is really a bug and not an error on your side e.g. using incompatible environment components/versions (Make sure that you have read the [documentation](https://github.com/ccpem/profet). If you are looking for support, you might want to check [this section](#i-have-a-question)).
- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug or error in the [bug tracker](https://github.com/ccpem/profetissues?q=label%3Abug).
- Also make sure to search the internet (including Stack Overflow) to see if users outside of the GitHub community have discussed the issue.
- Collect information about the bug:
- Stack trace (Traceback)
Expand All @@ -76,7 +76,7 @@ A good bug report shouldn't leave others needing to chase you up for more inform

We use GitHub issues to track bugs and errors. If you run into an issue with the project:

- Open an [Issue](https://github.com/alan-turing-institute/profet/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
- Open an [Issue](https://github.com/ccpem/profet/issues/new). (Since we can't be sure at this point whether it is a bug or not, we ask you not to talk about a bug yet and not to label the issue.)
- Explain the behavior you would expect and the actual behavior.
- Please provide as much context as possible and describe the *reproduction steps* that someone else can follow to recreate the issue on their own. This usually includes your code. For good bug reports you should isolate the problem and create a reduced test case.
- Provide the information you collected in the previous section.
Expand All @@ -95,14 +95,14 @@ This section guides you through submitting an enhancement suggestion for profet,
#### Before Submitting an Enhancement

- Make sure that you are using the latest version.
- Read the [documentation](https://github.com/alan-turing-institute/profet) carefully and find out if the functionality is already covered.
- Perform a [search](https://github.com/alan-turing-institute/profet/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
- Read the [documentation](https://github.com/ccpem/profet) carefully and find out if the functionality is already covered.
- Perform a [search](https://github.com/ccpem/profet/issues) to see if the enhancement has already been suggested. If it has, add a comment to the existing issue instead of opening a new one.
- Find out whether your idea fits with the scope and aims of the project. It's up to you to make a strong case to convince the project's developers of the merits of this feature. Keep in mind that we want features that will be useful to the majority of our users and not just a small subset. If you're just targeting a minority of users, consider writing an add-on/plugin library.

<!-- omit in toc -->
#### How Do I Submit a Good Enhancement Suggestion?

Enhancement suggestions are tracked as [GitHub issues](https://github.com/alan-turing-institute/profet/issues).
Enhancement suggestions are tracked as [GitHub issues](https://github.com/ccpem/profet/issues).

- Use a **clear and descriptive title** for the issue to identify the suggestion.
- Provide a **step-by-step description of the suggested enhancement** in as many details as possible.
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ A Python 3 **pro**tein structure **fet**cher. Retrieves the cif or pdb files fr
[![PyPI version shields.io](https://img.shields.io/pypi/v/profet.svg)](https://pypi.python.org/pypi/profet/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/profet.svg)](https://pypi.python.org/pypi/profet/)

[![Building](https://github.com/alan-turing-institute/profet/actions/workflows/python-package.yml/badge.svg)](https://github.com/alan-turing-institute/profet/actions/workflows/python-package.yml)
[![Publishing](https://github.com/alan-turing-institute/profet/actions/workflows/python-publish.yml/badge.svg)](https://github.com/alan-turing-institute/profet/actions/workflows/python-publish.yml)
[![Documentation](https://github.com/alan-turing-institute/profet/actions/workflows/sphinx.yml/badge.svg)](https://github.com/alan-turing-institute/profet/actions/workflows/sphinx.yml)
[![Building](https://github.com/ccpem/profet/actions/workflows/python-package.yml/badge.svg)](https://github.com/ccpem/profet/actions/workflows/python-package.yml)
[![Publishing](https://github.com/ccpem/profet/actions/workflows/python-publish.yml/badge.svg)](https://github.com/ccpem/profet/actions/workflows/python-publish.yml)
[![Documentation](https://github.com/ccpem/profet/actions/workflows/sphinx.yml/badge.svg)](https://github.com/ccpem/profet/actions/workflows/sphinx.yml)

## Dependencies

Expand Down Expand Up @@ -38,7 +38,7 @@ pip install profet
To install the development version, which contains the latest features and fixes, install directly from GitHub using:

```sh
pip install git+git://github.com/alan-turing-institute/profet
pip install git+git://github.com/ccpem/profet
```

To test the installation, you need to have pytest and pytest-cov packagages installed which can be done as follows.
Expand Down Expand Up @@ -128,11 +128,11 @@ a .pdb file. The file will be cached in the "~/.pdb" directory for future use.

## Documentation

You can find more documentation including a description of the python api [here](https://alan-turing-institute.github.io/profet/).
You can find more documentation including a description of the python api [here](https://ccpem.github.io/profet/).

## Issues and Feature Requests

If you run into an issue, or if you find a workaround for an existing issue, we would very much appreciate it if you could post your question or code as a [GitHub issue](https://github.com/alan-turing-institute/profet/issues).
If you run into an issue, or if you find a workaround for an existing issue, we would very much appreciate it if you could post your question or code as a [GitHub issue](https://github.com/ccpem/profet/issues).

## Contributions

Expand Down
2 changes: 1 addition & 1 deletion docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fixes, install directly from GitHub using:

.. code-block:: bash

pip install git+git://github.com/alan-turing-institute/profet`
pip install git+git://github.com/ccpem/profet`

Test the installation, navigate to the root directory and run

Expand Down
18 changes: 13 additions & 5 deletions profet/alphafold.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from requests_html import HTMLSession
import requests
from bs4 import BeautifulSoup
from .enums import FileType


class Alphafold_DB:
Expand Down Expand Up @@ -40,11 +41,13 @@ def check_structure(self, uniprot_id: str) -> bool:

"""
uniprot_id = uniprot_id.upper()
url = self.make_url(uniprot_id, "pdb")
url = self.make_url(uniprot_id, FileType.pdb)
r = requests.get(url)
return r.status_code != 404

def get_file_url(self, uniprot_id: str, filetype: str = "cif") -> str:
def get_file_url(
self, uniprot_id: str, filetype: FileType = FileType.cif
) -> str:
"""
Get file url relative to an id from the the Alphafold entry page

Expand All @@ -56,6 +59,7 @@ def get_file_url(self, uniprot_id: str, filetype: str = "cif") -> str:
The URL of the file to download

"""
filetype = FileType(filetype)

# Do we recognise the filetpye, otherwise raise an exception.
if filetype in ["pdb", "cif"]:
Expand All @@ -77,7 +81,9 @@ def get_file_url(self, uniprot_id: str, filetype: str = "cif") -> str:
# Return the URL
return url["href"]

def make_url(self, uniprot_id: str, filetype: str = "cif") -> str:
def make_url(
self, uniprot_id: str, filetype: FileType = FileType.cif
) -> str:
"""
Make the URL for the protein

Expand All @@ -89,6 +95,7 @@ def make_url(self, uniprot_id: str, filetype: str = "cif") -> str:
The URL of the file to download

"""
filetype = FileType(filetype)

uniprot_id = uniprot_id.upper()
af_id = "AF-" + uniprot_id + "-F1"
Expand All @@ -101,15 +108,15 @@ def make_url(self, uniprot_id: str, filetype: str = "cif") -> str:
+ "-model_v"
+ str(version)
+ "."
+ filetype
+ filetype.name
)

return url

def get_pdb(
self,
uniprot_id: str,
filetype: str = "cif",
filetype: FileType = FileType.cif,
) -> tuple:
"""
Returns pdb/cif as strings, saves to file if requested.
Expand All @@ -123,6 +130,7 @@ def get_pdb(
Tuple containing the filename and file from the database

"""
filetype = FileType(filetype)
# af_id = self.df.loc[self.df['Uniprot_ID'] == uniprot_id.upper()]["AF_ID"].to_numpy()[0]
# version = self.df.loc[self.df['Uniprot_ID'] == uniprot_id.upper()]["version"].to_numpy()[0]
# af_id = "AF-"+uniprot_id+"-F1"
Expand Down
13 changes: 10 additions & 3 deletions profet/cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
from .enums import FileType


class PDBFileCache(object):
Expand Down Expand Up @@ -35,7 +36,7 @@ def __init__(self, directory: str = None):
# The manifest filename
self.manifest = os.path.join(self.directory, "manifest.txt")

def path(self, uniprot_id: str, filetype: str = "cif") -> str:
def path(self, uniprot_id: str, filetype: FileType = FileType.cif) -> str:
"""
Get the proposed path

Expand All @@ -47,6 +48,7 @@ def path(self, uniprot_id: str, filetype: str = "cif") -> str:
The absolute path

"""
filetype = FileType(filetype)
assert filetype in ["pdb", "cif"]
return os.path.join(self.directory, uniprot_id.lower()) + "." + filetype

Expand All @@ -64,7 +66,7 @@ def find(self, uniprot_id: str) -> list:
return [
filename
for filename in [
self.path(uniprot_id, filetype) for filetype in ["pdb", "cif"]
self.path(uniprot_id, filetype) for filetype in FileType
]
if os.path.exists(filename)
]
Expand Down Expand Up @@ -137,7 +139,11 @@ def items(self):
yield uniprot_id, self.path(uniprot_id, filetype[1:])

def _update_manifest(
self, uniprot_id: str, fileorigin: str, filetype: str, filename: str
self,
uniprot_id: str,
fileorigin: str,
filetype: FileType,
filename: str,
):
"""
Update the manifest file
Expand All @@ -149,6 +155,7 @@ def _update_manifest(
filename: The filename

"""
filetype = FileType(filetype)

# Read the current manifest
if os.path.exists(self.manifest):
Expand Down
6 changes: 6 additions & 0 deletions profet/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum


class FileType(str, Enum):
pdb = "pdb"
cif = "cif"
15 changes: 10 additions & 5 deletions profet/pdb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from urllib.request import urlretrieve
from rcsbapi.search import TextQuery
from .enums import FileType


class PDB_DB:
Expand Down Expand Up @@ -50,7 +51,9 @@ def check_structure(self, uniprot_id: str) -> bool:
return True
return False

def make_url(self, uniprot_id: str, filetype: str = "pdb") -> str:
def make_url(
self, uniprot_id: str, filetype: FileType = FileType.pdb
) -> str:
"""
Make the URL for the protein

Expand All @@ -63,14 +66,15 @@ def make_url(self, uniprot_id: str, filetype: str = "pdb") -> str:

"""

filetype = FileType(filetype)
uniprot_id = uniprot_id.upper()
url = f"https://files.rcsb.org/download/{uniprot_id}.{filetype}"
url = f"https://files.rcsb.org/download/{uniprot_id}.{filetype.name}"
return url

def get_pdb(
self,
uniprot_id: str,
filetype: str = "cif",
filetype: FileType = FileType.cif,
) -> tuple:
"""
Returns pdb/cif as strings, saves to file if requested
Expand All @@ -84,6 +88,7 @@ def get_pdb(

"""

filetype = FileType(filetype)
if not self.results:
self.results = [self.uniprot_id_to_pdb_id(uniprot_id)]

Expand All @@ -97,9 +102,9 @@ def get_pdb(
filedata = file.read()
except Exception:
if filetype == "pdb":
filetype = "cif"
filetype = FileType.cif
else:
filetype = "pdb"
filetype = FileType.pdb
url = self.make_url(pdb_id, filetype)
filename, result = urlretrieve(url)
with open(filename) as file:
Expand Down
9 changes: 6 additions & 3 deletions profet/profet.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .pdb import PDB_DB
from .cache import PDBFileCache
from .cleaver import Cleaver
from .enums import FileType
import os


Expand Down Expand Up @@ -54,7 +55,7 @@ def cache(self) -> PDBFileCache:
def file_from_db(
self,
prot_id: str,
filetype: str = "cif",
filetype: FileType = FileType.cif,
db: str = "pdb",
) -> tuple:
"""
Expand All @@ -69,14 +70,15 @@ def file_from_db(
Tuple containing the filename and file from the database

"""
filetype = FileType(filetype)
return {"pdb": self.pdb.get_pdb, "alphafold": self.alpha.get_pdb}[db](
prot_id, filetype=filetype
)

def get_file(
self,
uniprot_id: str,
filetype: str = "cif",
filetype: FileType = FileType.cif,
filesave: bool = False,
db: str = "pdb",
) -> tuple:
Expand All @@ -96,6 +98,7 @@ def get_file(
2. File from the database, or None if it is not available in any database.

"""
filetype = FileType(filetype)

# Get the PDB cache
cache = PDBFileCache(directory=self.save_directory)
Expand Down Expand Up @@ -211,7 +214,7 @@ def remove(
"""
# Get the PDB cache
cache = PDBFileCache(directory=self.save_directory)
identifier, _, _ = self.pdb.get_pdb(uniprot_id, filetype="cif")
identifier, _, _ = self.pdb.get_pdb(uniprot_id, filetype=FileType.cif)
if uniprot_id in cache:
filename = cache[uniprot_id]
signal_list = self.Cleaver.signal_residuenumbers_requester(
Expand Down
Loading