Skip to content

Commit

Permalink
[#69] Added begging of function for connection all together, decorato…
Browse files Browse the repository at this point in the history
…r for params and func to get regex which need to be fixed to concatenate lists
  • Loading branch information
rglsk committed Sep 25, 2014
1 parent a1f12bc commit efce8dc
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/shmir/data/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def generate_regexp_all(cls):

db_session.commit()

@classmethod
def get_all_regexp(cls):
return [bone.regex for bone in db_session.query(cls).all()]

@classmethod
def get_mirna(cls, name=None):
if name:
Expand Down
13 changes: 13 additions & 0 deletions src/shmir/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import json

from shmir.utils import json_error
from shmir.designer import errors


def require_json(require_data=True, required_data_words=None,
Expand Down Expand Up @@ -63,3 +64,15 @@ def jsonify(f):
def wrapped(*args, **kwargs):
return dumps(f(*args, **kwargs))
return wrapped


def param(name, g_type, description, default=None, required=False):
def wrapper(func):
def wrapped(**kwargs):
if not kwargs[name]:
if required:
raise errors.InputException('{} is required'.format(name))
kwargs[name] = g_type(default)
return func(**kwargs)
return wrapped
return wrapper
45 changes: 45 additions & 0 deletions src/shmir/designer/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from shmir import cache
from shmir.data import (
models,
ncbi_api,
)
from shmir.decorators import param
from shmir.designer.validators import calculate_gc_content


def create_cache_key(*args):
return ':'.join(args)


@param('transcript_name', str, 'Name of transcript', required=True)
@param('min_gc', int, 'Minimum of GC content', default=40)
@param('max_gc', int, 'Maximum of GC content', default=60)
@param('max_offtarget', int, 'Maximum offtarget, minimum is 0', default=10)
@param('mirna_name', str, 'miRNA name of Backbone', default=None)
@param(
'stymulators', bool, 'Bool if immuno stimulators are wanted', default=False
)
def connection(
transcript_name, min_gc, max_gc, max_offtarget, mirna_name, stymulators
):
sequence = '?'
cg_content = calculate_gc_content(sequence)

cache_key = create_cache_key(
transcript_name,
cg_content,
mirna_name,
max_offtarget,
str(stymulators)
)

sequence = cache.get(cache_key) # TODO: check if get take cache by key xD

if not sequence:
sequence = ncbi_api.get_mRNA(transcript_name)

backbones = models.Backbone.get_mirna(mirna_name)
if not isinstance(backbones, list):
backbones = [backbones]

all_regex = models.Backbone.get_all_regexp()

0 comments on commit efce8dc

Please sign in to comment.