Skip to content

Commit

Permalink
groundwork comparative heatmap
Browse files Browse the repository at this point in the history
  • Loading branch information
proost committed Nov 29, 2017
1 parent 33ec725 commit 82b9f84
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ networks and more across different species. A public version including seven pla
publicly available RNASeq samples (from the [SRA](https://www.ncbi.nlm.nih.gov/sra)) is available
[here](http://conekt.mpimp-golm.mpg.de/pub/).

Here you can find **Tutorials** how to use the public version along with the source-code and build instructions that
allow you to host your own instance with other species or in-house data.
Here you can find **tutorials** how to use the public version along with the **source-code** and build instructions that
allow you to **host your own instance** with other species or in-house data.

Tutorials
---------
Expand Down
20 changes: 20 additions & 0 deletions conekt/controllers/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from conekt.models.expression.profiles import ExpressionProfile
from conekt.models.relationships.sequence_cluster import SequenceCoexpressionClusterAssociation
from conekt.models.sequences import Sequence
from conekt.models.trees import Tree
from conekt.models.expression.cross_species_profile import CrossSpeciesExpressionProfile

heatmap = Blueprint('heatmap', __name__)

Expand Down Expand Up @@ -93,6 +95,24 @@ def heatmap_main():
return render_template("expression_heatmap.html", form=form, example=example)


@heatmap.route('/comparative/tree/<int:tree_id>')
@heatmap.route('/comparative/tree/<int:tree_id>/<option>')
@cache.cached()
def heatmap_comparative_tree(tree_id, option='raw'):
tree = Tree.query.get_or_404(tree_id)
sequences = tree.sequences
sequence_ids = [s.id for s in sequences]

heatmap_data = CrossSpeciesExpressionProfile().get_heatmap(*sequence_ids, option=option)

print(heatmap_data)

return render_template("expression_heatmap.html", order=heatmap_data['order'],
profiles=heatmap_data['heatmap_data'],
zlog=1 if option == 'zlog' else 0,
raw=1 if option == 'raw' else 0)


@heatmap.route('/inchlib/j/<cluster_id>.json')
@cache.cached()
def heatmap_inchlib_json(cluster_id):
Expand Down
42 changes: 36 additions & 6 deletions conekt/models/expression/cross_species_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,31 @@ def get_data(self, *sequence_ids):

parsed_profile = {
"order": self.conditions,
"data": {c: max(current_profile["data"][c]) if c in current_profile["data"].keys() else None
"data": {},
"raw_data": {c: max(current_profile["data"][c]) if c in current_profile["data"].keys() else None
for c in self.conditions}
}

# detect low expressed genes before normalization
low_expressed = all(
[value < 10 for value in parsed_profile["data"].values() if value is not None])
[value < 10 for value in parsed_profile["raw_data"].values() if value is not None])

# normalize profile
min_value = min([i if i is not None else 0 for i in parsed_profile["data"].values()])
max_value = max([i if i is not None else 0 for i in parsed_profile["data"].values()])
min_value = min([i if i is not None else 0 for i in parsed_profile["raw_data"].values()])
max_value = max([i if i is not None else 0 for i in parsed_profile["raw_data"].values()])

if max_value > 0:
for c in self.conditions:
if parsed_profile["data"][c] is not None:
parsed_profile["data"][c] = parsed_profile["data"][c]/max_value
if parsed_profile["raw_data"][c] is not None:
parsed_profile["data"][c] = parsed_profile["raw_data"][c]/max_value
else:
parsed_profile["data"][c] = None

converted_profiles.append(
{
"sequence_id": p.sequence_id,
"sequence_name": p.sequence.name if p.sequence is not None else None,
"shortest_alias": p.sequence.shortest_alias if p.sequence is not None else None,
"species_id": p.species_id,
"low_expressed": 1 if low_expressed else 0,
"profile": parsed_profile,
Expand All @@ -67,3 +72,28 @@ def get_data(self, *sequence_ids):
)

return converted_profiles

def get_heatmap(self, *sequence_ids, option='raw'):
data = self.get_data(*sequence_ids)

output = {
'order': [],
'heatmap_data': []
}

for d in data:
if "profile" in d.keys() and "order" in d["profile"].keys():
output['order'] = d["profile"]["order"]
break

key = 'raw_data' if option == 'raw' else 'data'

for d in data:
output['heatmap_data'].append({
'sequence_id': d['sequence_id'],
'name': d['sequence_name'],
'shortest_alias': d['shortest_alias'],
'values': {k: v if v is not None else '-' for k,v in d['profile'][key].items()}
})

return output

0 comments on commit 82b9f84

Please sign in to comment.