Skip to content

Commit

Permalink
Port trail_threshold_variability to flatpages
Browse files Browse the repository at this point in the history
Also changed generated/ static subdir to g/.
  • Loading branch information
jmuhlich committed Sep 22, 2015
1 parent 2849613 commit 9c53f4c
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ src/onetime/makepng
src/onetime/makesvg
data/networks/xgmml
.deploy
django/*/static/*/generated
django/*/static/*/g
6 changes: 5 additions & 1 deletion django/hmslincs_server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
url(r'^db/logout/$', logout_page, name='logout'),
url(r'^db/', include('db.urls')),

(r'^(?P<url>explore/pathway/)$', 'django.contrib.flatpages.views.flatpage'),
(r'^(?P<url>explore/pathway/)$',
'django.contrib.flatpages.views.flatpage'),

(r'^(?P<url>explore/trail-threshold-variability/)$',
'django.contrib.flatpages.views.flatpage'),

(r'^explore/responses/$', 'django.views.generic.simple.direct_to_template',
{'template': 'responses/index.html'}),
Expand Down
4 changes: 2 additions & 2 deletions django/pathway/management/commands/buildstatic_pathway.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def generate_images_and_index(options):
app_dir = Path(__file__).absolute().ancestor(3)
data_dir = app_dir.child('resources')
static_dir = app_dir.child('static', 'pathway')
out_dir_image = static_dir.child('generated')
out_dir_image = static_dir.child('g')
out_dir_image.mkdir()
pathway_image_filename = 'pathway.jpg'

Expand Down Expand Up @@ -232,7 +232,7 @@ def generate_images_and_index(options):
# fix up <img> attribs
del img.attrib['usemap']
img.attrib['id'] = 'pathway-img'
img.attrib['src'] = '%spathway/generated/%s' % (django.conf.settings.STATIC_URL,
img.attrib['src'] = '%spathway/g/%s' % (django.conf.settings.STATIC_URL,
pathway_image_filename)
img.attrib['width'] = str(pathway_image.size[0])
img.attrib['height'] = str(pathway_image.size[1])
Expand Down
2 changes: 1 addition & 1 deletion django/pathway/templates/pathway/compound_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</td>
<td class="signature">
{% if sd.signature %}
<img src="{{ STATIC_URL }}pathway/generated/signature-{{ signature.target_name|slugify }}-{{ sd.drug|slugify }}.png"
<img src="{{ STATIC_URL }}pathway/g/signature-{{ signature.target_name|slugify }}-{{ sd.drug|slugify }}.png"
width="250" height="20">
{% endif %}
</td>
Expand Down
4 changes: 2 additions & 2 deletions django/pathway/templates/pathway/signature.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ <h3>Inhibitors of
<td colspan="3"></td>
<td class="signature">
{% if signature.show_scale %}
<img src="{{ STATIC_URL }}pathway/generated/scale-{{ signature.target_name|slugify }}.png" width="250" height="20">
<img src="{{ STATIC_URL }}pathway/g/scale-{{ signature.target_name|slugify }}.png" width="250" height="20">
{% endif %}
</td>
</tr>
Expand All @@ -57,7 +57,7 @@ <h3>Inhibitors of
<tr>
{% for index, cell_line in row %}
<td>
<img src="{{ STATIC_URL }}pathway/generated/legend-cell-line-{{ index }}.png" width="14" height="14">
<img src="{{ STATIC_URL }}pathway/g/legend-cell-line-{{ index }}.png" width="14" height="14">
<a href="/db/cells/{{ cell_line.cell_id }}/">{{ cell_line.name }}</a>
</td>
{% endfor %}
Expand Down
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,12 @@
import wand.image
import django.conf
from django.template.loader import render_to_string
from django.core.management.base import BaseCommand, CommandError
from django.contrib.flatpages.models import FlatPage
from django.contrib.sites.models import Site
from optparse import make_option



# Read RESOURCE_PATH from environ, or default to something that works for me.
resource_path_s = os.environ.get(
'RESOURCE_PATH',
'/home/jmuhlich/Dropbox (HMS-LSP)/Roux Hafner TRAIL_DISC_paper/website/')
resource_path = unipath.Path(resource_path_s)
hmslincs_path = unipath.Path(__file__).ancestor(2)

docroot_path = hmslincs_path.child(
'temp', 'docroot', 'explore', 'trail-threshold-variability')

img_src_path = resource_path.child('figures')
img_dest_path = docroot_path.child('img')
popup_dest_path = img_dest_path.child('popup')
schematic_dest_path = img_dest_path.child('schematic')

data_src_path = resource_path.child('data')
data_dest_path = docroot_path.child('data')

base_url = '/explore/trail-threshold-variability/'

table = [{'name': u'Modulation of DISC activity (k)',
'schematic_page': 1,
'treatment_map': [('TRAIL', '', 1), ('Mapatumumab', '', 52),
Expand Down Expand Up @@ -71,11 +54,50 @@
schematic_target_width = 230 * 2


def main(argv):
class Command(BaseCommand):
help = 'Builds the static assets and html chunks'
option_list = BaseCommand.option_list + (
make_option('-n', '--no-images', action='store_true', default=False,
help='Skip building images'),
make_option('-d', '--no-data', action='store_true', default=False,
help='Skip building data download files'),
make_option('-r', '--resource-path',
default=('/home/jmuhlich/Dropbox (HMS-LSP)/'
'Roux Hafner TRAIL_DISC_paper/website/'),
help=('Path to resource files (contains "figures" and '
'"data" directories)'))
)

def handle(self, *args, **options):

url = '/explore/trail-threshold-variability/'
content = build_static(options)

page, created = FlatPage.objects.get_or_create(url=url)
page.title = ('Fractional killing arises from cell-to-cell '
'variability in overcoming a caspase activity threshold')
page.content = content
page.template_name = 'trail_threshold_variability/base.html'
page.sites.clear()
page.sites.add(Site.objects.get_current())
page.save()


argparser = argparse.ArgumentParser(
description='Build trail_threshold_variability app resources.')
args = argparser.parse_args()
def build_static(options):

app_path = unipath.Path(__file__).absolute().ancestor(3)
static_path = app_path.child('static', 'trail_threshold_variability')
generated_path = static_path.child('g')
generated_path.mkdir()

resource_path = unipath.Path(options['resource_path'])

img_src_path = resource_path.child('figures')
popup_dest_path = generated_path.child('popup')
schematic_dest_path = generated_path.child('schematic')

data_src_path = resource_path.child('data')
data_dest_path = generated_path.child('data')

treatment_reverse_map = {}
for s_idx, section in enumerate(table):
Expand Down Expand Up @@ -131,54 +153,52 @@ def main(argv):

# Assemble data for template and render html.
data = {'table': table,
'data_rel_url': docroot_path.rel_path_to(data_dest_path),
'STATIC_URL': django.conf.settings.STATIC_URL,
'BASE_URL': base_url,
}
docroot_path.mkdir(parents=True)
render_template('trail_threshold_variability/index.html', data,
docroot_path, 'index.html')

# Resize and copy popup images.
popup_dest_path.mkdir(parents=True)
for dose in doses:
dest_path = popup_dest_path.child(dose['img_filename'])
with wand.image.Image(filename=dose['img_path']) as img, \
open(dest_path, 'w') as f:
scale = float(popup_target_width) / img.width
target_size = [int(round(d * scale)) for d in img.size]
img.resize(*target_size, blur=1.5)
img.compression_quality = 20
img.format = 'JPEG'
img.save(file=f)
dest_path.chmod(0o644)
# Extract and copy schematic images.
schematic_dest_path.mkdir(parents=True)
schematic_path = img_src_path.child('schematics', 'Trajectories_schematics.pdf')
with wand.image.Image(filename=schematic_path, resolution=500) as img:
for section in table:
page_number = section['schematic_page']
page = wand.image.Image(image=img.sequence[page_number])
page.alpha_channel = False
scale = float(schematic_target_width) / page.width
target_size = [int(round(d * scale)) for d in page.size]
page.resize(*target_size)
page.compression_quality = 100
page.format = 'JPEG'
filename = '{}.jpg'.format(page_number)
dest_path = schematic_dest_path.child(filename)
page.save(filename=dest_path)
content = render_to_string('trail_threshold_variability/index.html', data)

if not options['no_images']:
# Resize and copy popup images.
popup_dest_path.mkdir()
for dose in doses:
dest_path = popup_dest_path.child(dose['img_filename'])
with wand.image.Image(filename=dose['img_path']) as img, \
open(dest_path, 'w') as f:
scale = float(popup_target_width) / img.width
target_size = [int(round(d * scale)) for d in img.size]
img.resize(*target_size, blur=1.5)
img.compression_quality = 20
img.format = 'JPEG'
img.save(file=f)
dest_path.chmod(0o644)
# Extract and copy schematic images.
schematic_dest_path.mkdir()
schematic_path = img_src_path.child('schematics', 'Trajectories_schematics.pdf')
with wand.image.Image(filename=schematic_path, resolution=500) as img:
for section in table:
page_number = section['schematic_page']
page = wand.image.Image(image=img.sequence[page_number])
page.alpha_channel = False
scale = float(schematic_target_width) / page.width
target_size = [int(round(d * scale)) for d in page.size]
page.resize(*target_size)
page.compression_quality = 100
page.format = 'JPEG'
filename = '{}.jpg'.format(page_number)
dest_path = schematic_dest_path.child(filename)
page.save(filename=dest_path)
dest_path.chmod(0o644)

if not options['no_data']:
# Copy data download files.
data_dest_path.mkdir(parents=True)
for filename in data_filenames:
src_path = data_src_path.child(filename)
dest_path = data_dest_path.child(filename)
src_path.copy(dest_path)
dest_path.chmod(0o644)
# Copy data download files.
data_dest_path.mkdir(parents=True)
for filename in data_filenames:
src_path = data_src_path.child(filename)
dest_path = data_dest_path.child(filename)
src_path.copy(dest_path)
dest_path.chmod(0o644)

globals().update(locals())
return 0
return content


def as_css_identifier(s):
Expand All @@ -190,15 +210,3 @@ def as_css_identifier(s):
the values returned from this function to sidestep the issue entirely.
"""
return re.sub(r'[^a-z0-9-]', '-', s, flags=re.IGNORECASE)


def render_template(template_name, data, dirname, basename):
"Render a template with data to a file specified by dirname and basename."
out_filename = unipath.Path(dirname, basename)
content = render_to_string(template_name, data)
with codecs.open(out_filename, 'w', 'utf-8') as out_file:
out_file.write(content)


if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "base_flatpage.html" %}

{% block requirejs %}
<script>
require.config({
paths: {
ttv: 'trail_threshold_variability/js',
},
});
require( [ 'ttv/main' ] );
</script>
{% endblock %}

{% block head_extra %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}ext/jquery-ui/1.11.4/jquery-ui.min.css"/>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}trail_threshold_variability/css/style.css"/>
{% endblock %}

{% block contentclass %}fullwidth{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
{% extends "base.html" %}

{% load trail_threshold_variability %}

{% block requirejs %}
<script>
require.config({
paths: {
ttv: 'trail_threshold_variability/js',
},
});
require( [ 'ttv/main' ] );
</script>
{% endblock %}

{% block head_extra %}
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}ext/jquery-ui/1.11.4/jquery-ui.min.css"/>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}trail_threshold_variability/css/style.css"/>
{% endblock %}

{% block title %}
Fractional killing arises from cell-to-cell variability in overcoming a
caspase activity threshold - {{ block.super }}
{% endblock %}

{% block contentclass %}fullwidth{% endblock %}

{% block body %}

<h1>Fractional killing arises from cell-to-cell variability in overcoming a
caspase activity threshold</h1>

Expand Down Expand Up @@ -100,15 +73,15 @@ <h2>Treatment/dose lookup table</h2>
</td>
{% for dose in treatment.doses %}
<td class="lookup-table-hotspot cell-{{ dose.id }}">
<a href="img/popup/{{ dose.img_filename }}">{{ dose.amount }}</a>
<a href="{{ STATIC_URL }}trail_threshold_variability/g/popup/{{ dose.img_filename }}">{{ dose.amount }}</a>
</td>
{% endfor %}
{% if forloop.first %}
{% if section.num_padding_columns %}
<td class="padding" colspan="{{ section.num_padding_columns }}"></td>
{% endif %}
<td>
<img src="img/schematic/{{ section.schematic_page }}.jpg"
<img src="{{ STATIC_URL }}trail_threshold_variability/g/schematic/{{ section.schematic_page }}.jpg"
class="schematic" width="250">
</td>
{% endif %}
Expand Down Expand Up @@ -139,7 +112,7 @@ <h2 id="downloads">Available data, signatures and software</h2>
<td>Data and signatures</td>
<td>All single-cell raw data, smoothed trajectories, and fitted parameters
for each replicate for each treatment condition in HeLa cells.</td>
<td><a href="{{ data_rel_url}}/All_SingleCell_data.zip">Download (.zip)</a></td>
<td><a href="{{ STATIC_URL }}trail_threshold_variability/g/data/All_SingleCell_data.zip">Download (.zip)</a></td>
</tr>
<tr>
<td>Signatures</td>
Expand All @@ -148,21 +121,19 @@ <h2 id="downloads">Available data, signatures and software</h2>
for download through the
<a href="http://lincs.hms.harvard.edu/db/datasets/20232/">HMS LINCS Database</a>.
</em></td>
<td><a href="{{ data_rel_url}}/Aggregate_SingleCell_results.tsv">Download (.tsv)</a></td>
<td><a href="{{ STATIC_URL }}trail_threshold_variability/g/data/Aggregate_SingleCell_results.tsv">Download (.tsv)</a></td>
</tr>
<tr>
<td>Data and signatures</td>
<td>Population-based viability and C8 activity results for Apomab, Apomab
+ anti-Fc, and TRAIL treatments in several other cancer cell lines with
varying sensitivities to TRAIL.</td>
<td><a href="{{ data_rel_url}}/Results_other_lines.zip">Download (.zip)</a></td>
<td><a href="{{ STATIC_URL }}trail_threshold_variability/g/data/Results_other_lines.zip">Download (.zip)</a></td>
</tr>
<tr>
<td>Software</td>
<td>The MATLAB code for the image processing routines developed for this
project.</td>
<td><a href="{{ data_rel_url}}/scripts.zip">Download (.zip)</a></td>
<td><a href="{{ STATIC_URL }}trail_threshold_variability/g/data/scripts.zip">Download (.zip)</a></td>
</tr>
</table>

{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="lookup-table-popup cell-{{ dose.id }}">
<a class="media-ondemand" href="img/popup/{{ dose.img_filename }}">Single-cell
<a class="media-ondemand" href="{{ STATIC_URL }}trail_threshold_variability/g/popup/{{ dose.img_filename }}">Single-cell
data summary for {{ treatment.name_main }}
@ {{ dose.amount }} {{ treatment.unit }}
{% if treatment.name_other %}
Expand Down

0 comments on commit 9c53f4c

Please sign in to comment.