From: Diane Trout Date: Fri, 11 Oct 2013 21:58:46 +0000 (-0700) Subject: Make it possible to set a label on a track. X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=htsworkflow.git;a=commitdiff_plain;h=5cd0308e3ea6aff59ae5cbdb2a9569ffff56984a Make it possible to set a label on a track. This works by setting a term label_template on the filename regex block. that label_template is then expanded by searching for metadata in from the related library for that submission. --- diff --git a/htsworkflow/submission/submission.py b/htsworkflow/submission/submission.py index 12a5154..6268970 100644 --- a/htsworkflow/submission/submission.py +++ b/htsworkflow/submission/submission.py @@ -21,6 +21,9 @@ from htsworkflow.submission.daf import \ ModelException, \ get_submission_uri +from django.conf import settings +from django.template import Context, Template, loader + LOGGER = logging.getLogger(__name__) class Submission(object): @@ -121,6 +124,7 @@ class Submission(object): fileNode = self.make_file_node(pathname, an_analysis) self.add_md5s(filename, fileNode, analysis_dir) self.add_fastq_metadata(filename, fileNode) + self.add_label(file_type, fileNode, libNode) self.model.add_statement( RDF.Statement(fileNode, rdfNS['type'], @@ -182,6 +186,23 @@ class Submission(object): if value is not None: s = RDF.Statement(fileNode, model_term, toTypedNode(value)) self.model.append(s) + + def add_label(self, file_type, file_node, lib_node): + """Add rdfs:label to a file node + """ + #template_term = libraryOntology['label_template'] + template_term = libraryOntology['label_template'] + label_template = self.model.get_target(file_type, template_term) + if label_template: + template = loader.get_template('submission_view_rdfs_label_metadata.sparql') + context = Context({ + 'library': str(lib_node.uri), + }) + for r in self.execute_query(template, context): + context = Context(r) + label = Template(label_template).render(context) + s = RDF.Statement(file_node, rdfsNS['label'], unicode(label)) + self.model.append(s) def _add_library_details_to_model(self, libNode): # attributes that can have multiple values diff --git a/htsworkflow/submission/trackhub_submission.py b/htsworkflow/submission/trackhub_submission.py index 4720737..7a83e87 100644 --- a/htsworkflow/submission/trackhub_submission.py +++ b/htsworkflow/submission/trackhub_submission.py @@ -105,12 +105,17 @@ class TrackHubSubmission(Submission): track_subgroup = self.make_track_subgroups(subgroups, track) + if 'file_label' in track: + track_label = self.sanitize_name(track['file_label']) + else: + track_label = track_name + newtrack = Track( name=track_name, tracktype = str(track['file_type']), url= hub_url + str(track['relative_path']), short_label=str(track['library_id']), - long_label=track_name, + long_label=str(track_label), subgroups=track_subgroup, ) view.add_tracks([newtrack]) @@ -155,12 +160,11 @@ class TrackHubSubmission(Submission): return str(template.render(context)) def make_track_name(self, track): - name = '{}_{}_{}'.format( + return '{}_{}_{}'.format( track['library_id'], track['replicate'], track['output_type'], ) - return name def make_track_subgroups(self, subgroups, track): track_subgroups = {} diff --git a/htsworkflow/templates/submission_view_rdfs_label_metadata.sparql b/htsworkflow/templates/submission_view_rdfs_label_metadata.sparql new file mode 100644 index 0000000..0666e62 --- /dev/null +++ b/htsworkflow/templates/submission_view_rdfs_label_metadata.sparql @@ -0,0 +1,10 @@ +PREFIX htsw: +PREFIX encode3: + +select ?cell_line ?assay ?protocol ?lab +where { + optional { <{{ library }}> htsw:cell_line ?cell_line . } + optional { <{{ library }}> encode3:assay ?assay . } + optional { <{{ library }}> encode3:protocol ?protocol. } + optional { <{{ library }}> encode3:lab ?lab. } +} diff --git a/htsworkflow/templates/trackhub_samples.sparql b/htsworkflow/templates/trackhub_samples.sparql index 19ce7e1..9515274 100644 --- a/htsworkflow/templates/trackhub_samples.sparql +++ b/htsworkflow/templates/trackhub_samples.sparql @@ -1,3 +1,5 @@ +PREFIX rdf: +PREFIX rdfs: PREFIX htswlib: PREFIX submissionOntology: PREFIX ucscDaf: @@ -6,8 +8,7 @@ PREFIX geoSoft: PREFIX cells: PREFIX encode3: -select distinct ?lab_library_id ?library_id ?filename ?relative_path ?output_type ?file_type ?cell ?replicate ?assay ?rna_type ?protocol - +select distinct ?lab_library_id ?library_id ?filename ?relative_path ?output_type ?file_type ?cell ?replicate ?assay ?rna_type ?protocol ?file_label WHERE { ?trackType geoSoft:fileTypeLabel ?file_type ; ucscDaf:output_type ?output_type . @@ -15,6 +16,7 @@ WHERE { ucscDaf:relative_path ?relative_path ; htswlib:library ?library ; a ?trackType . + OPTIONAL { ?file rdfs:label ?file_label . } OPTIONAL { ?library htswlib:library_id ?lab_library_id } OPTIONAL { ?library encode3:library_id ?library_id } OPTIONAL { ?library htswlib:cell_line ?cell . }