Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix celery worker and enable back improved tests
- Loading branch information
1 parent
1444c00
commit e832163
Showing
8 changed files
with
158 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import codecs | ||
import pickle | ||
|
||
|
||
def pickle_as_str(obj): | ||
return codecs.encode(pickle.dumps(obj, protocol=0), 'base64').decode() | ||
|
||
|
||
def unpickle_str(text): | ||
return pickle.loads(codecs.decode(text.encode(), 'base64')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from flask import request | ||
|
||
from helpers.filters import FilterManager, Filter | ||
from models import Mutation, Protein | ||
from search.gene import search_feature_engines | ||
|
||
search_features = [engine.name for engine in search_feature_engines] | ||
|
||
|
||
class Feature: | ||
"""Target class for feature filtering""" | ||
pass | ||
|
||
|
||
class Search: | ||
pass | ||
|
||
|
||
class SearchViewFilters(FilterManager): | ||
|
||
def __init__(self, **kwargs): | ||
|
||
available_features = search_features | ||
active_features = set(available_features) - {'summary'} | ||
|
||
filters = [ | ||
# Why default = False? Due to used widget: checkbox. | ||
# It is not possible to distinguish between user not asking for | ||
# all mutations (so sending nothing in post, since un-checking it | ||
# will cause it to be skipped in the form) or user doing nothing | ||
|
||
# Why or? Take a look on table: | ||
# is_ptm show all muts (by default only ptm) include? | ||
# 0 0 0 | ||
# 0 1 1 | ||
# 1 0 1 | ||
# 1 1 1 | ||
Filter( | ||
Mutation, 'is_ptm', comparators=['or'], | ||
default=False | ||
), | ||
Filter( | ||
Protein, 'has_ptm_mutations', comparators=['eq'], | ||
as_sqlalchemy=True | ||
), | ||
Filter( | ||
Feature, 'name', comparators=['in'], | ||
default=list(active_features), | ||
choices=available_features, | ||
), | ||
Filter( | ||
Search, 'query', comparators=['eq'], | ||
), | ||
] | ||
super().__init__(filters) | ||
self.update_from_request(request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import pickle | ||
from typing import Dict | ||
|
||
from app import celery | ||
from helpers.pickle import pickle_as_str, unpickle_str | ||
from search.mutation import MutationSearch | ||
|
||
from search.filters import SearchViewFilters | ||
|
||
|
||
class SearchTask: | ||
|
||
def __init__(self, vcf_file, textarea_query: str, filter_manager: SearchViewFilters, dataset_uri=None): | ||
self.vcf_file = vcf_file | ||
self.textarea_query = textarea_query | ||
self.filter_manager = filter_manager | ||
self.dataset_uri = dataset_uri | ||
|
||
def serialize(self) -> Dict: | ||
return { | ||
'vcf_file': self.vcf_file, | ||
'textarea_query': self.textarea_query, | ||
'filter_manager': pickle_as_str(self.filter_manager), | ||
'dataset_uri': self.dataset_uri | ||
} | ||
|
||
@classmethod | ||
def from_serialized(cls, vcf_file, textarea_query, filter_manager, dataset_uri): | ||
filter_manager = unpickle_str(filter_manager) | ||
|
||
if not isinstance(filter_manager, SearchViewFilters): | ||
# print('This weird issue again... Retrying') | ||
filter_manager = pickle.loads(filter_manager) | ||
|
||
return cls( | ||
vcf_file, | ||
textarea_query, | ||
filter_manager, | ||
dataset_uri | ||
) | ||
|
||
|
||
@celery.task | ||
def search_task(task_data): | ||
task = SearchTask.from_serialized(**task_data) | ||
mutation_search = MutationSearch(task.vcf_file, task.textarea_query, task.filter_manager) | ||
return pickle_as_str(mutation_search), task.dataset_uri |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters