-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #179 from monarch-initiative/Feature_counts
Create Protein table so users can see list of protein features and coordinates
- Loading branch information
Showing
13 changed files
with
297 additions
and
3,838 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,79 @@ | ||
import typing | ||
|
||
from dataclasses import dataclass | ||
|
||
from jinja2 import Environment, PackageLoader | ||
from collections import namedtuple | ||
|
||
from genophenocorr.model import Cohort | ||
from genophenocorr.model.genome import Region | ||
from ._protein_visualizable import ProteinVisualizable | ||
|
||
@dataclass(frozen=False) | ||
class Feature: | ||
""" | ||
A private dataclass for representing a table row. | ||
Any edits to the dataclass must also be followed by an update of the Jinja template. | ||
""" | ||
name: str | ||
type: str | ||
region: Region | ||
variant_count: int | ||
|
||
|
||
class ProteinViewable: | ||
""" | ||
Class to create a pretty HTML table to display the protein information in the Jupyter notebook. | ||
""" | ||
def __init__(self) -> None: | ||
environment = Environment(loader=(PackageLoader('genophenocorr.view', 'templates'))) | ||
self._cohort_template = environment.get_template("protein.html") | ||
|
||
def process(self, cohort: Cohort, pvis: ProteinVisualizable) -> str: | ||
""" | ||
Summarize the data regarding the protein into a HTML table. | ||
Args: | ||
cohort (Cohort): the cohort of patients being analyzed | ||
pvis (ProteinVisualizable): The class that collects data from the UniProt API for a given protein ID | ||
Returns: | ||
str: an HTML document for showing in Jupyter notebook | ||
""" | ||
context = self._prepare_context(cohort, pvis) | ||
return self._cohort_template.render(context) | ||
|
||
def _prepare_context(self, cohort: Cohort, pvis: ProteinVisualizable) -> typing.Mapping[str, typing.Any]: | ||
protein_id = pvis.protein_id | ||
|
||
protein_features = [] | ||
|
||
for i in range(len(pvis.protein_feature_names)): | ||
feature = Feature( | ||
name=pvis.protein_feature_names[i], | ||
type=pvis.protein_feature_types[i], | ||
region=Region(pvis.protein_feature_starts[i], pvis.protein_feature_ends[i]), | ||
variant_count=0, | ||
) | ||
protein_features.append(feature) | ||
|
||
for feature in protein_features: | ||
count = 0 | ||
for var in cohort.all_variants(): | ||
tx_anno = var.get_tx_anno_by_tx_id(pvis.transcript_id) | ||
if tx_anno is not None: | ||
location = tx_anno.protein_effect_location | ||
if location is not None and location.overlaps_with(feature.region): | ||
count += 1 | ||
|
||
feature.variant_count = count | ||
|
||
final_protein_features = sorted(protein_features, key=lambda f: f.region.start) | ||
|
||
return { | ||
'protein_id': protein_id, | ||
'protein_label': pvis.protein_metadata.label, | ||
'protein_features': final_protein_features | ||
} | ||
|
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,86 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Cohort</title> | ||
<style>table { | ||
border-collapse: collapse; | ||
margin: 25px 0; | ||
font-size: 0.9em; | ||
font-family: sans-serif; | ||
min-width: 400px; | ||
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15); | ||
} | ||
|
||
|
||
.table .column-1 { | ||
text-align: left; | ||
} | ||
th { | ||
background-color: LightSkyBlue; | ||
border: 1px solid #dddddd; | ||
text-align: left; | ||
padding: 5px; | ||
font-weight: bold; | ||
font-size: 120%; | ||
} | ||
|
||
|
||
tr { | ||
border: 1px solid #dddddd; | ||
} | ||
|
||
td { | ||
padding: 5px; | ||
font-weight: bold; | ||
} | ||
|
||
tr:nth-child(even) { | ||
background-color: #f2f2f2; | ||
} | ||
|
||
.table td,tr { | ||
text-align: left; | ||
} | ||
|
||
.table td:first-child, tr:first-child { | ||
text-align: left; | ||
} | ||
|
||
caption { | ||
caption-side: top; | ||
text-align: left; | ||
padding-bottom: 10px; | ||
font-weight: bold; | ||
} | ||
|
||
</style> | ||
</head> | ||
|
||
<body> | ||
<h1>genophenocorr protein analysis</h1> | ||
<p>The UniProt API successfully returned protein information for ID: {{ protein_id }}</p> | ||
<p>Protein Name: {{ protein_label }}</p> | ||
<table> | ||
<caption style="color:black;"> | ||
<h3>Protein Features</h3> | ||
</caption> | ||
<tbody> | ||
<tr class="strng"> | ||
<th>Feature Name</th> | ||
<th>Feature Type</th> | ||
<th>Feature Coordinates</th> | ||
<th>Variants in Feature</th> | ||
</tr> | ||
{% for feat in protein_features %} | ||
<tr> | ||
<td>{{ feat.name }}</td> | ||
<td>{{ feat.type }}</td> | ||
<td>{{ feat.region.start }} - {{ feat.region.end }}</td> | ||
<td>{{ feat.variant_count }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</body> | ||
</html> |
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