Skip to content

Commit

Permalink
Merge pull request #152 from ElDeveloper/issue_121_and_144
Browse files Browse the repository at this point in the history
Changes for comparison plots
  • Loading branch information
antgonza committed Aug 5, 2013
2 parents 41b6d68 + 4f71302 commit 227a0e9
Show file tree
Hide file tree
Showing 7 changed files with 548 additions and 121 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@ Emperor 0.9.1 (changes since Emperor 0.9.0 go here)
* Export to SVG your visualization.
* Emperor now relies on QIIME 1.7.0.
* Added option `--number_of_segments` to control the quality of all spheres
* Add color pickers for connecting bars in coordinate comparison plots.
* Add option to select a master set of coordinates when making a comparison plot.

*Bug Fixes*

* Fixes recenter camera not working.
* Category names are sorted alphabetically.
* Category names with non-alphanumeric characters are colored correctly now.
* Biplots checkbox now accurately reflects status of biplot visiblity rather than opposite.
* Comparison bars checkbox now accurately reflects status of the visiblity rather than opposite.
* Scaling by percent explained now works with vectors and coordinate comparison plots.
* Fixed bug where only the first bars in coordinate comparison plots could be hidden.

Emperor 0.9.0 (14 May 2013)
===========================
Expand Down
36 changes: 28 additions & 8 deletions emperor/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,16 @@ def format_vectors_to_js(mapping_file_data, mapping_file_headers, coords_data,

return ''.join(js_vectors_string)

def format_comparison_bars_to_js(coords_data, coords_headers, clones):
def format_comparison_bars_to_js(coords_data, coords_headers, clones,
is_serial_comparison=True):
"""Format coordinates data to create a comparison plot
Inputs:
coords_data: numpy array with the replicated coordinates
cooreds_headers: list with the headers for each of replicated coordinates
clones: number of replicates in the coords_data and coords_headers
is_serial_comparison: whether the samples will be connected one after the
other (True) or all will originate in the first set of coordinates.
Outputs:
Javascript object that contains the data for the comparison plot
Expand All @@ -323,11 +326,19 @@ def format_comparison_bars_to_js(coords_data, coords_headers, clones):
length.
AssertionError if the number of clones doesn't concord with the samples
being presented.
Unless the value of clones is > 0 this function will return an empty
javascript object initialization.
"""

js_comparison_string = []
js_comparison_string.append('\nvar g_comparisonPositions = new Array();\n')

if is_serial_comparison:
js_comparison_string.append('var g_isSerialComparisonPlot = true;\n')
else:
js_comparison_string.append('var g_isSerialComparisonPlot = false;\n')

if clones:
headers_length = len(coords_headers)

Expand Down Expand Up @@ -367,6 +378,9 @@ def format_emperor_html_footer_string(has_biplots=False, has_ellipses=False,
has_biplots: whether the plot has biplots or not
has_ellipses: whether the plot has ellipses or not
has_vectors: whether the plot has vectors or not
has_edges: whether the plot has edges between samples (comparison plot)
This function will remove unnecessary GUI elements from index.html to avoid
confusions i. e. showing an ellipse opacity slider when there are no
Expand All @@ -378,6 +392,7 @@ def format_emperor_html_footer_string(has_biplots=False, has_ellipses=False,
optional_strings.append(if_(has_biplots, _BIPLOT_SPHERES_COLOR_SELECTOR,''))
optional_strings.append(if_(has_biplots, _BIPLOT_VISIBILITY_SELECTOR, ''))
optional_strings.append(if_(has_biplots, _TAXA_LABELS_SELECTOR, ''))
optional_strings.append(if_(has_edges, _EDGES_COLOR_SELECTOR, ''))
optional_strings.append(if_(has_ellipses, _ELLIPSE_OPACITY_SLIDER, ''))
optional_strings.append(if_(has_vectors, _VECTORS_OPACITY_SLIDER, ''))
optional_strings.append(if_(has_edges, _EDGES_VISIBILITY_SELECTOR, ''))
Expand Down Expand Up @@ -454,10 +469,15 @@ def format_emperor_html_footer_string(has_biplots=False, has_ellipses=False,
_EDGES_VISIBILITY_SELECTOR = """
<br>
<form name="edgesvisibility">
<input type="checkbox" onClick="toggleEdgesVisibility()">Edges Visibility</input>
<input type="checkbox" onClick="toggleEdgesVisibility()" checked>Edges Visibility</input>
</form>
<br>"""

_EDGES_COLOR_SELECTOR = """
<tr><td><div id="edgecolorselector_a" class="colorbox" name="edgecolorselector_a"></div></td><td title="edgecolor_a">Edge Color Selector A</td></tr>
<tr><td><div id="edgecolorselector_b" class="colorbox" name="edgecolorselector_b"></div></td><td title="edgecolor_b">Edge Color Selector B</td></tr>
"""

_EMPEROR_FOOTER_HTML_STRING ="""document.getElementById("logo").style.display = 'none';
document.getElementById("logotable").style.display = 'none';
Expand Down Expand Up @@ -566,16 +586,16 @@ def format_emperor_html_footer_string(has_biplots=False, has_ellipses=False,
<table>
<tr><td><div id="axeslabelscolor" class="colorbox" name="axeslabelscolor"></div></td><td title="Axes Labels Color">Axes Labels Color</td></tr>
<tr><td><div id="axescolor" class="colorbox" name="axescolor"></div></td><td title="Axes Color Title">Axes Color</td></tr>
<tr><td><div id="rendererbackgroundcolor" class="colorbox" name="rendererbackgroundcolor"></div></td><td title="Background Color Title">Background Color</td></tr>
<tr><td><div id="rendererbackgroundcolor" class="colorbox" name="rendererbackgroundcolor"></div></td><td title="Background Color Title">Background Color</td></tr>%s
</table>
<br>
<form name="settingsoptionscolor">
<input type="checkbox" onchange="toggleContinuousAndDiscreteColors(this)" id="discreteorcontinuouscolors" name="discreteorcontinuouscolors"> Use gradient colors</input>
</form>
<div id="pcoaviewoptions" class="">
<br>
<input id="reset" class="button" type="submit" value="Recenter Camera" style="" onClick="resetCamera()">
<br>%s%s%s
<br>
<br>
<form name="settingsoptionscolor">
<input type="checkbox" onchange="toggleContinuousAndDiscreteColors(this)" id="discreteorcontinuouscolors" name="discreteorcontinuouscolors"> Use gradient colors</input>
</form>%s%s%s
<br>
<label for="sphereopacity" class="text">Sphere Opacity</label>
<label id="sphereopacity" class="slidervalue"></label>
Expand Down
39 changes: 38 additions & 1 deletion emperor/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
__email__ = "yoshiki89@gmail.com"
__status__ = "Development"


from numpy import zeros
from re import compile, search

def sort_taxa_table_by_pcoa_coords(coords_header, otu_table, otu_header):
"""Sort and match the samples in the otu table and in the coordinates data
Expand Down Expand Up @@ -48,3 +48,40 @@ def sort_taxa_table_by_pcoa_coords(coords_header, otu_table, otu_header):
sorted_otu_headers.append(element)

return sorted_otu_headers, sorted_otu_table

def sort_comparison_filenames(coord_fps):
"""Pass in a list of file names and sort them using the suffix
Input:
coord_fps: list of filenames with the format something_something_qX.txt
where X is the index of the file.
Output:
Returns a sorted version of the list that was passed in where the strings
are sorted according to the suffix they have, if the string doesn't have
a suffix it will be added to the beginning of the list.
"""

if coord_fps == []:
return []

def _get_suffix(fp):
"""Gets the number in the suffix for a string using a regex"""
# any alphanumeric set of characters proceeded by a 'q', a number, a dot
# & a txt extension at the end of the line. Take for example
# bray_curtis_q1.txt or unifrac_q11.txt
re = compile(r'(\w+)_q([0-9]+).txt$')
tmatch = search(re, fp)

try:
number = tmatch.group(2)
# if the regex doesn't match then put it at the beginning
except (IndexError, AttributeError):
number = -1

return float(number)

# the key function retrieves the suffix number for the function to sort
# according to it's floating point representation i. e. the cast to float
return sorted(coord_fps, key=_get_suffix)

Loading

0 comments on commit 227a0e9

Please sign in to comment.