Skip to content
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 @@
.DS_Store
@eaDir

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
2 changes: 1 addition & 1 deletion modelseedpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
c_handler.setFormatter(c_format)
logger.addHandler(c_handler)
if config.get("logging","log_file") == "yes":
f_handler = logging.FileHandler(config.get("logging","filename"),mode="w")
f_handler = logging.FileHandler(config.get("logging","filename"), mode="a")
f_handler.setLevel(logging_hash[config.get("logging","file_level")])
f_format = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
f_handler.setFormatter(f_format)
Expand Down
222 changes: 132 additions & 90 deletions modelseedpy/core/msatpcorrection.py

Large diffs are not rendered by default.

47 changes: 37 additions & 10 deletions modelseedpy/core/msgenome.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import logging
logger = logging.getLogger(__name__)

import re
import copy # !!! the import is never used
from cobra.core.dictlist import DictList

logger = logging.getLogger(__name__)


def normalize_role(s):
Expand All @@ -13,15 +12,12 @@ def normalize_role(s):
s = re.sub('[\W_]+', '', s)
return s

#Static factory functions:

#def build_from_kbase_gto:


def read_fasta(f, split='|', h_func=None):
with open(f, 'r') as fh:
return parse_fasta_str(fh.read(), split, h_func)


def parse_fasta_str(faa_str, split='|', h_func=None):
features = []
seq = None
Expand All @@ -48,23 +44,54 @@ def parse_fasta_str(faa_str, split='|', h_func=None):


class MSFeature:

def __init__(self, feature_id, sequence, description=None):
self.id = feature_id; self.seq = sequence
"""

@param feature_id: identifier for the protein coding feature
@param sequence: protein sequence
@param description: description of the feature
"""

self.id = feature_id
self.seq = sequence
self.description = description # temporary replace with proper parsing
self.ontology_terms = {}
self.aliases = []

def add_ontology_term(self, ontology_term, value):
"""
Add functional term to the feature

@param ontology_term: type of the ontology (e.g., RAST, EC)
@param value: value for the ontology (e.g., pyruvate kinase)
"""
if ontology_term not in self.ontology_terms:
self.ontology_terms[ontology_term] = []
if value not in self.ontology_terms[ontology_term]:
self.ontology_terms[ontology_term].append(value)


class MSGenome:

def __init__(self):
self.features = DictList()

def add_features(self, feature_list: list):
"""

:param feature_list:
:return:
"""
duplicates = list(filter(lambda o: o.id in self.features, feature_list))
if len(duplicates) > 0:
raise ValueError(f"unable to add features {duplicates} already present in the genome")

for f in feature_list:
f._genome = self

self.features += feature_list

@staticmethod
def from_fasta(filename, contigs=0, split='|', h_func=None): # !!! the contigs argument is never used
genome = MSGenome()
Expand All @@ -83,10 +110,10 @@ def from_protein_sequences_hash(sequences):
return genome

def alias_hash(self):
return {alias:gene for gene in self.features for alias in gene.aliases}
return {alias: gene for gene in self.features for alias in gene.aliases}

def search_for_gene(self,query):
def search_for_gene(self, query):
if query in self.features:
return self.features.get_by_id(query)
aliases = self.alias_hash()
return aliases[query] if query in aliases else None
return aliases[query] if query in aliases else None
6 changes: 5 additions & 1 deletion modelseedpy/core/msgenomeclassifier.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from modelseedpy.ml.predict_phenotype import create_indicator_matrix
from modelseedpy.core.msgenome import MSGenome


class MSGenomeClassifier:
Expand All @@ -22,7 +23,10 @@ def extract_features_from_genome(genome, ontology_term):
return {'genome': list(features)}

def classify(self, genome_or_roles, ontology_term='RAST'):
if isinstance(genome_or_roles,"MSGenome"):
"""
param genome_or_roles:
"""
if isinstance(genome_or_roles, MSGenome):
genome_or_roles = self.extract_features_from_genome(genome_or_roles, ontology_term)
indicator_df, master_role_list = create_indicator_matrix(genome_or_roles, self.features)
predictions_numerical = self.model.predict(indicator_df[master_role_list].values)
Expand Down
7 changes: 5 additions & 2 deletions modelseedpy/core/msmedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

logger = logging.getLogger(__name__)


class MediaCompound:

def __init__(self, compound_id, lower_bound, upper_bound, concentration=None):
Expand All @@ -23,16 +24,18 @@ def minFlux(self):


class MSMedia:
def __init__(self, media_id):

def __init__(self, media_id, name=""):
self.id = media_id
self.name = name
self.mediacompounds = DictList()

@staticmethod
def from_dict(media_dict):
"""
Either dict with exchange bounds (example: {'cpd00027': (-10, 1000)}) or
just absolute value of uptake (example: {''cpd00027': 10})
:param d:
:param media_dict:
:return:
"""
media = MSMedia('media')
Expand Down
5 changes: 4 additions & 1 deletion modelseedpy/fbapkg/gapfillingpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ def extend_model_with_template_metabolites(self, template, index='0'):
for template_compound in template.compcompounds:
compartment = template_compound.compartment
compartment_index = "0" if compartment == 'e' else index
cobra_metabolite = self.convert_template_compound(template_compound, compartment_index, template) # TODO: move function out
cobra_metabolite = template_compound.to_metabolite(compartment_index)
#cobra_metabolite = self.convert_template_compound(template_compound, compartment_index, template) # TODO: move function out
if cobra_metabolite.id not in self.model.metabolites and cobra_metabolite.id not in new_metabolites:
new_metabolites[cobra_metabolite.id] = cobra_metabolite
#self.model.add_metabolites([cobra_metabolite])
Expand All @@ -302,6 +303,8 @@ def extend_model_with_template_metabolites(self, template, index='0'):

# Possible new function to add to the KBaseFBAModelToCobraBuilder to extend a model with a template for gapfilling for a specific index
def extend_model_with_template_for_gapfilling(self, template, index):
logger.debug(f'extend model with template: {template}, index: {index}')

new_reactions = {}
new_penalties = dict()

Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"matplotlib >= 3.0.0",
"pyeda"
],
tests_require=[
"pytest",
],
project_urls={
'Documentation': 'https://modelseedpy.readthedocs.io/en/stable/',
'Issues': 'https://github.com/ModelSEED/ModelSEEDpy/issues',
Expand Down
Loading