Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JBrowse: enable callbacks in style options #2442

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions tools/jbrowse/jbrowse.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,12 +690,16 @@ def traverse_to_option_parent(self, splitKey, outputTrackConfig):
assert isinstance(trackConfigSubDict, dict), 'Config element {} is not a dict'.format(trackConfigSubDict)
return trackConfigSubDict

def revert_mapped_chars_in_string(self, stringValue, mapped_chars):
for char, mapped_char in mapped_chars.items():
stringValue = stringValue.replace(mapped_char, char)
return stringValue

def get_formatted_option(self, valType2ValDict, mapped_chars):
assert isinstance(valType2ValDict, dict) and len(valType2ValDict.items()) == 1
for valType, value in valType2ValDict.items():
if valType == "text":
for char, mapped_char in mapped_chars.items():
value = value.replace(mapped_char, char)
self.revert_mapped_chars_in_string(value, mapped_chars)
elif valType == "integer":
value = int(value)
elif valType == "float":
Expand All @@ -713,17 +717,6 @@ def set_custom_track_options(self, customTrackConfig, outputTrackConfig, mapped_

def process_annotations(self, track):
category = track['category'].replace('__pd__date__pd__', TODAY)
outputTrackConfig = {
'style': {
'label': track['style'].get('label', 'description'),
'className': track['style'].get('className', 'feature'),
'description': track['style'].get('description', ''),
},
'overridePlugins': track['style'].get('overridePlugins', False) == 'True',
'overrideDraggable': track['style'].get('overrideDraggable', False) == 'True',
'maxHeight': track['style'].get('maxHeight', '600'),
'category': category,
}

mapped_chars = {
'>': '__gt__',
Expand All @@ -739,10 +732,21 @@ def process_annotations(self, track):
"": '__cn__'
}

outputTrackConfig = {
'style': {
'label': self.revert_mapped_chars_in_string(track['style'].get('label', 'description'), mapped_chars),
'className': track['style'].get('className', 'feature'),
'description': self.revert_mapped_chars_in_string(track['style'].get('description', ''), mapped_chars),
},
'overridePlugins': track['style'].get('overridePlugins', False) == 'True',
'overrideDraggable': track['style'].get('overrideDraggable', False) == 'True',
'maxHeight': track['style'].get('maxHeight', '600'),
'category': category,
}

for i, (dataset_path, dataset_ext, track_human_label, extra_metadata) in enumerate(track['trackfiles']):
# Unsanitize labels (element_identifiers are always sanitized by Galaxy)
for key, value in mapped_chars.items():
track_human_label = track_human_label.replace(value, key)
self.revert_mapped_chars_in_string(track_human_label, mapped_chars)

log.info('Processing %s / %s', category, track_human_label)
outputTrackConfig['key'] = track_human_label
Expand Down Expand Up @@ -814,8 +818,7 @@ def process_annotations(self, track):
self.add_rest(track['conf']['options']['rest']['url'], outputTrackConfig)
elif dataset_ext == 'sparql':
sparql_query = track['conf']['options']['sparql']['query']
for key, value in mapped_chars.items():
sparql_query = sparql_query.replace(value, key)
self.revert_mapped_chars_in_string(sparql_query, mapped_chars)
self.add_sparql(track['conf']['options']['sparql']['url'], sparql_query, outputTrackConfig)
else:
log.warn('Do not know how to handle %s', dataset_ext)
Expand Down
26 changes: 26 additions & 0 deletions tools/jbrowse/jbrowse.xml
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,32 @@ $trackxml &&
<param name="uglyTestingHack" value="enabled" />
<output name="output" file="track_config/test.xml" lines_diff="30"/>
</test>
<!-- test callbacks in style options -->
<test>
<param name="reference_genome|genome_type_select" value="history"/>
<param name="reference_genome|genome" value="merlin.fa"/>
<param name="gencode" value="11" />
<param name="standalone" value="Data Directory" />

<repeat name="track_groups">
<param name="category" value="With callbacks in style options" />
<repeat name="data_tracks">
<conditional name="data_format">
<param name="data_format_select" value="gene_calls"/>
<param name="annotation" value="gff3/1.gff"/>
<conditional name="match_part">
<param name="match_part_select" value="false"/>
</conditional>
<section name="jbstyle">
<param name="style_label" value="function(featureObject,value) { return featureObject.parent().get('id')}"/>
<param name="style_description" value="function(featureObject,value) { return featureObject.parent().get('note')}"/>
</section>
</conditional>
</repeat>
</repeat>
<param name="uglyTestingHack" value="enabled" />
<output name="output" file="style_config/test.xml" lines_diff="16"/>
</test>
<test>
<param name="reference_genome|genome_type_select" value="history"/>
<param name="reference_genome|genome" value="merlin.fa"/>
Expand Down
2 changes: 1 addition & 1 deletion tools/jbrowse/macros.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</requirements>
</xml>
<token name="@DATA_DIR@">\$GALAXY_JBROWSE_SHARED_DIR</token>
<token name="@WRAPPER_VERSION@">galaxy3</token>
<token name="@WRAPPER_VERSION@">galaxy4</token>
<token name="@ATTRIBUTION@"><![CDATA[
**Attribution**

Expand Down
106 changes: 106 additions & 0 deletions tools/jbrowse/test-data/style_config/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0"?>
<root>
<metadata>
<gencode>11</gencode>
<genomes>
<genome path="/tmp/tmpWtvfKr/files/000/dataset_17.dat">
<metadata>
<dataset id="27ee89e2e3d631e0" hid="1"
size="171.6 KB"
edam_format="format_1929"
file_ext="fasta" />
<history id="7b55dbb89df8f4e5"
user_email="[email protected]"
user_id="2"
display_name="test_history"/>
<metadata
dbkey="?"
data_lines="2881"
sequences="1"
/>
<tool
tool_id="upload1"
tool_version="1.1.6"
/>
</metadata>
</genome>
</genomes>
<general>
<defaultLocation></defaultLocation>
<trackPadding>20</trackPadding>

<shareLink>true</shareLink>
<aboutDescription></aboutDescription>
<show_tracklist>true</show_tracklist>
<show_nav>true</show_nav>
<show_overview>true</show_overview>
<show_menu>true</show_menu>
<hideGenomeOptions>false</hideGenomeOptions>
</general>
<galaxyUrl>http://localhost</galaxyUrl>
</metadata>
<tracks>
<track cat="With callbacks in style options" format="gene_calls" visibility="default_off">
<files>
<trackFile path="/tmp/tmpWtvfKr/files/000/dataset_18.dat" ext="gff3" label="1.gff">
<metadata>
<dataset id="61f03d5eef6f1538" hid="2"
size="2.3 KB"
edam_format="format_1975"
file_ext="gff3" />
<history id="7b55dbb89df8f4e5"
user_email="[email protected]"
user_id="2"
display_name="test_history"/>
<metadata
dbkey="?"
data_lines="27"
comment_lines="19"
columns="9"
delimiter="__tc__"
attributes="6"
/>
<tool
tool_id="upload1"
tool_version="1.1.6"
/>
</metadata>
</trackFile>
</files>

<options>
<style>
<overridePlugins>False</overridePlugins>
<overrideDraggable>False</overrideDraggable>
<className>feature</className>
<description>function(featureObject,value) { return featureObject.parent().get('note')}</description>
<label>function(featureObject,value) { return featureObject.parent().get('id')}</label>
<height>10px</height>
<maxHeight>600</maxHeight>
</style>
<scaling>
<method>ignore</method>
<scheme>
<color>__auto__</color>
</scheme>
</scaling>
<menus>
</menus>
<custom_config>
</custom_config>

<gff>
<trackType>NeatHTMLFeatures/View/Track/NeatFeatures</trackType>
<index>false</index>
</gff>
</options>
</track>
</tracks>
<plugins
ComboTrackSelector=""
Bookmarks=""
GCContent=""
BlastView="True"
theme=""
/>
</root>