Skip to content

Dreycey/reviewer feedback #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions PhageScanner/main/database_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import re
from abc import ABC, abstractmethod
from enum import Enum
from typing import List
from typing import Generator, Any

import requests
from bs4 import BeautifulSoup
Expand Down Expand Up @@ -223,7 +223,7 @@ def get_phanns_query(query, extra=""):
modified_query += extra
return modified_query

def esearch(self, query, batch_size=10000) -> List[str]:
def esearch(self, query, batch_size=10000) -> Generator[Any, Any, Any]:
"""Return a list of URIs.

Description:
Expand Down
29 changes: 28 additions & 1 deletion PhageScanner/main/feature_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import numpy as np
from Bio.SeqUtils.ProtParam import ProteinAnalysis
from keras.preprocessing.sequence import pad_sequences

from PhageScanner.main.exceptions import (
IncorrectValueError,
Expand Down Expand Up @@ -51,6 +52,7 @@ class FeatureExtractorNames(Enum):
onehot = "SEQUENTIALONEHOT"
pcp = "PCP"
chemfeatures = "CHEMFEATURES"
integerencoding = "INTEGERENCODING"

@classmethod
def get_extractor(cls, name, parameters: Optional[Dict]):
Expand All @@ -68,6 +70,7 @@ def get_extractor(cls, name, parameters: Optional[Dict]):
cls.onehot.value: SequentialOneHot,
cls.pcp.value: PCPExtractor,
cls.chemfeatures.value: ChemFeatureExtractor,
cls.integerencoding.value: IntegerEncoding
}

# instantiate the class
Expand Down Expand Up @@ -495,7 +498,7 @@ class SequentialOneHot(ProteinFeatureExtraction):
def __init__(self, parameters: Optional[Dict] = None):
"""Instantiate tokenization extract method."""
self.aa2index = {aa: ind for ind, aa in enumerate(self.canonical_amino_acids)}
self.matrix_length = 1000
self.matrix_length = 2000

def extract_features(self, protein: str):
"""Obtain an tokenization of the protein sequence."""
Expand Down Expand Up @@ -563,6 +566,30 @@ def extract_features(self, protein: str):

return hash_vec

class IntegerEncoding(ProteinFeatureExtraction):
"""Extraction method for obtaining an integer encoding for a protein."""

def __init__(self, parameters: Optional[Dict] = None):
"""Instantiate CTD extract method."""
codes = ['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L',
'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y']

aa_dict = {}
for index, val in enumerate(codes):
aa_dict[val] = index+1

self.aa_dict = aa_dict

def extract_features(self, protein: str, max_length=1000):
""" Integer encoding for a protein. """
integer_encoding = []
for amino_acid in protein:
integer_encoding.append(self.aa_dict.get(amino_acid, 0))

return pad_sequences([integer_encoding],
maxlen=max_length,
padding='post',
truncating='post')[0]

class CTDExtractor(ProteinFeatureExtraction):
"""Extraction method for obtaining Composition-transition-distribution (CTD)"""
Expand Down
Loading
Loading