Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
grapediadb committed Dec 10, 2018
1 parent dd11dfc commit cc49fac
Show file tree
Hide file tree
Showing 15 changed files with 266 additions and 24 deletions.
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c256c884
dd11dfcb
3 changes: 2 additions & 1 deletion command/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def ws_connect(message):
Group("admin").add(message.reply_channel)
for db in CompendiumDatabase.objects.all():
Group("compendium_" + str(db.id)).add(message.reply_channel)
message.http_session['channel_name'] = message.reply_channel.name
if message.http_session:
message.http_session['channel_name'] = message.reply_channel.name
message.reply_channel.send({"accept": True})


Expand Down
2 changes: 1 addition & 1 deletion command/lib/anno/ontology_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_neighbourhood(self, node_id, level=1):
Q(source_id__in=node_ids) & Q(target_id__in=node_ids))
for e in edges_qr:
edges.append({'data': {
'id': e.id,
'id': 'edge_' + str(e.id),
'source': e.source.id,
'target': e.target.id
}})
Expand Down
13 changes: 13 additions & 0 deletions command/lib/anno/owl_file_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import networkx
from onto2nx import OWLParser, parse_owl

from command.lib.anno.base_parser import BaseParser


class OWLFileParser(BaseParser):
FILE_TYPE_NAME = 'OWL'

def parse(self, filename):
graph = parse_owl(filename)
return networkx.readwrite.cytoscape_data(graph)
7 changes: 4 additions & 3 deletions command/lib/db/compendium/bio_feature_annotation.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from django.db import models

from command.lib.db.compendium.annotation_value import AnnotationValue
from command.lib.db.compendium.bio_feature import BioFeature
from command.lib.db.compendium.ontology_node import OntologyNode


class BioFeatureAnnotation(models.Model):
bio_feature = models.ForeignKey(BioFeature, on_delete=models.CASCADE, default=1, null=False, blank=False)
ontology_node = models.ForeignKey(OntologyNode, on_delete=models.CASCADE, default=1, null=False, blank=False)
annotation_value = models.ForeignKey(AnnotationValue, on_delete=models.CASCADE, null=False, default=1)

class Meta:
unique_together = ('bio_feature', 'ontology_node',)
unique_together = ('bio_feature', 'annotation_value')

def to_dict(self):
fields = ['id', 'bio_feature_id', 'ontology_node_id']
fields = ['id', 'bio_feature_id', 'annotation_value_id']
return {k: self.__dict__[k] for k in fields}
5 changes: 2 additions & 3 deletions command/lib/db/compendium/raw_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

from command.lib.db.compendium.bio_feature_reporter import BioFeatureReporter
from command.lib.db.compendium.sample import Sample
from command.lib.db.compendium.value_type import ValueType


class RawData(models.Model):
sample = models.ForeignKey(Sample, db_index=True, on_delete=models.CASCADE, null=False, default=1)
bio_feature_reporter = models.ForeignKey(BioFeatureReporter, db_index=True, on_delete=models.CASCADE, null=False, default=1)
value = models.FloatField(blank=True, null=True)

class Meta:
unique_together = ("sample", "bio_feature_reporter")
value_type = models.ForeignKey(ValueType, on_delete=models.CASCADE, default=1, null=True, blank=True)

def to_dict(self, reduced=False):
fields = ['id', 'value']
Expand Down
18 changes: 16 additions & 2 deletions command/lib/tasks/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from command.lib.anno.annotation_parser import BaseAnnotationParser
from command.lib.db.admin.compendium_database import CompendiumDatabase
from command.lib.db.compendium.annotation_value import AnnotationValue
from command.lib.db.compendium.bio_feature import BioFeature
from command.lib.db.compendium.bio_feature_annotation import BioFeatureAnnotation
from command.lib.db.compendium.message_log import MessageLog
Expand Down Expand Up @@ -82,11 +83,24 @@ def annotation_task(self, user_id, compendium_id, ontology_id, filename, file_ty
ann_map = dict(OntologyNode.objects.using(compendium.compendium_nick_name).filter(ontology=ontology).values_list('original_id', 'id'))
for chunk in parser.parse(filename):
annotations = []
annotation_values = []
for ann in chunk:
bfa = BioFeatureAnnotation()
if ann[0] in bf_map and ann[1] in ann_map:
ann_val = AnnotationValue(
ontology_node_id=ann_map[ann[1]],
value='True',
value_type='boolean'
)
annotation_values.append(ann_val)
AnnotationValue.objects.using(compendium.compendium_nick_name).bulk_create(annotation_values)
annotation_values_map = dict(AnnotationValue.objects.using(compendium.compendium_nick_name).filter(ontology_node__ontology=ontology).
values_list('ontology_node_id', 'id')
)
for ann in chunk:
if ann[0] in bf_map and ann[1] in ann_map:
bfa = BioFeatureAnnotation()
bfa.bio_feature_id = bf_map[ann[0]]
bfa.ontology_node_id = ann_map[ann[1]]
bfa.annotation_value_id = annotation_values_map[ann_map[ann[1]]]
annotations.append(bfa)
BioFeatureAnnotation.objects.using(compendium.compendium_nick_name).bulk_create(annotations)

Expand Down
9 changes: 7 additions & 2 deletions command/lib/tasks/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def create_ontology_task(self, user_id, compendium_id, ontology_name,
node.ontology = ontology
node.original_id = n['data']['id']
node.json = n['data']
if not ontology.json or 'columns' not in ontology.json:
if not ontology.json or 'columns' not in ontology.json or len(ontology.json['columns']) == 0:
ontology.json = {'columns': [{'text': x.title().replace('_', ' '), 'data_index': x} for x in n['data'].keys() if x != 'id']}
ontology.save(using=compendium.compendium_nick_name)
nodes.append(node)
Expand All @@ -107,12 +107,17 @@ def create_ontology_task(self, user_id, compendium_id, ontology_name,
for c in chunks(structure['elements']['edges'], 10000):
edges = []
for e in c:
e_type = None
if 'key' in e['data']:
e_type = e['data']['key']
elif 'type' in e['data']:
e_type = e['data']['type']
edge = OntologyEdge()
edge.source_id = node_ids[e['data']['source']]
edge.target_id = node_ids[e['data']['target']]
edge.is_directed = True
edge.ontology = ontology
edge.edge_type = e['data']['key']
edge.edge_type = e_type
edges.append(edge)
OntologyEdge.objects.using(compendium.compendium_nick_name).bulk_create(edges)

Expand Down
7 changes: 6 additions & 1 deletion command/lib/utils/database.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from django.db import connection,connections


def create_db(admin_db_name, admin_db_setting, db_name):
def create_db(admin_db_name, admin_db_setting, db_name, db_user):
connections.databases[admin_db_name] = admin_db_setting
cur = connections[admin_db_name].cursor()
cur.execute('CREATE DATABASE ' + db_name)
cur.execute('REVOKE CONNECT ON DATABASE ' + db_name + ' FROM PUBLIC')
cur.execute('GRANT CONNECT ON DATABASE ' + db_name + ' TO ' + db_user)
cur.execute('GRANT ALL ON ALL TABLES IN SCHEMA public TO ' + db_user)
cur.execute('GRANT ALL ON ALL SEQUENCES IN SCHEMA public TO ' + db_user)
cur.execute('GRANT ALL ON ALL FUNCTIONS IN SCHEMA public TO ' + db_user)


def get_database_list():
Expand Down
14 changes: 14 additions & 0 deletions command/lib/utils/init_compendium.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from django.core.management import call_command
from django.db import connections, transaction

from command.lib.db.compendium.annotation_value import AnnotationValue
from command.lib.db.compendium.bio_feature_annotation import BioFeatureAnnotation
from command.lib.db.compendium.normalization import Normalization
from command.lib.db.compendium.normalization_experiment import NormalizationExperiment
Expand All @@ -31,6 +32,7 @@
from command.lib.db.admin.compendium_database import CompendiumDatabase
from command.lib.db.compendium.data_source import DataSource
from command.lib.db.compendium.experiment import Experiment
from command.lib.db.compendium.sample_annotation import SampleAnnotation
from command.lib.db.compendium.status import Status
from command.lib.db.compendium.message_log import MessageLog
from command.lib.db.compendium.platform import Platform
Expand Down Expand Up @@ -140,6 +142,12 @@ def init_compendium(db_id):
pass
call_command('migrate', database=key)
if compendium.compendium_type.name == 'gene_expression':
ValueType(name='I', description='Intensity').save(using=key)
ValueType(name='BG', description='BackGround').save(using=key)
ValueType(name='IBG', description='Intensity Background corrected').save(using=key)
ValueType(name='M', description='M-value, Intensity log-ratio').save(using=key)
ValueType(name='A', description='A-value, Intensity average').save(using=key)
ValueType(name='C', description='Count').save(using=key)
geo_db = DataSource(source_name='GEO',
python_class='command.lib.coll.public_database.GEOPublicDatabase',
is_local=False)
Expand Down Expand Up @@ -185,6 +193,12 @@ def init_compendium(db_id):
status_platform_imported = Status(name='platform_imported', description='Platform is imported')
status_platform_importing.save(using=key)
status_platform_imported.save(using=key)
status_annotated = Status(name='experiment_annotated', description='Experiment samples have been annotated')
status_design_defined = Status(name='experiment_design_defined', description='Experiment design has been defined')
status_normalized = Status(name='experiment_normalized', description='Experiment has been normalized')
status_annotated.save(using=key)
status_design_defined.save(using=key)
status_normalized.save(using=key)
# copy over data from platform type and biological features tables
for plt_type_admin in PlatformTypeAdmin.objects.all():
plt_type = PlatformType()
Expand Down
4 changes: 2 additions & 2 deletions command/lib/views/bio_feature_anno.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def read_bio_feature_anno(channel_name, view, request, user):
b = bf.to_dict()
b['annotation'] = []
for bfa in bf.biofeatureannotation_set.all():
ontology = bfa.ontology_node.ontology
node = bfa.ontology_node
ontology = bfa.annotation_value.ontology_node.ontology
node = bfa.annotation_value.ontology_node
ann = node.to_dict()
ann['ontology'] = ontology.to_dict()
ann['columns'] = ontology.json['columns']
Expand Down
2 changes: 1 addition & 1 deletion command/lib/views/compendium_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def create_compendium(request, *args, **kwargs):
admin_db.compendium_nick_name = values['admin']['username']
admin_db.db_user = values['admin']['username']
admin_db.db_password = values['admin']['password']
create_db(values['admin']['username'], admin_db.get_setting_entry()[1], db.compendium_nick_name)
create_db(values['admin']['username'], admin_db.get_setting_entry()[1], db.compendium_nick_name, db.db_user)
db.save()
init_database_connections()
Group('admin').send({
Expand Down

0 comments on commit cc49fac

Please sign in to comment.