X-Git-Url: http://woldlab.caltech.edu/gitweb/?a=blobdiff_plain;f=htsworkflow%2Fsubmission%2Fsubmission.py;h=897053fbc148477c108d232635958db45488dfc5;hb=1000ba383f47a9c3ab422f4552b3725038c96541;hp=640443557f8d50a574816ce33ba417de35054da5;hpb=1bd93f14d964adb1f63cf2d6bf61a3ff0168d55b;p=htsworkflow.git diff --git a/htsworkflow/submission/submission.py b/htsworkflow/submission/submission.py index 6404435..897053f 100644 --- a/htsworkflow/submission/submission.py +++ b/htsworkflow/submission/submission.py @@ -11,7 +11,7 @@ from htsworkflow.util.rdfhelp import \ dump_model, \ fromTypedNode, \ get_model, \ - stripNamespace, \ + strip_namespace, \ toTypedNode from htsworkflow.util.rdfns import * from htsworkflow.util.hashfile import make_md5sum @@ -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): @@ -57,6 +60,13 @@ class Submission(object): pathname = os.path.abspath(os.path.join(analysis_dir, filename)) self.construct_file_attributes(analysis_dir, libNode, pathname) + def analysis_nodes(self, result_map): + """Return an iterable of analysis nodes + """ + for result_dir in result_map.values(): + an_analysis = self.get_submission_node(result_dir) + yield an_analysis + def construct_file_attributes(self, analysis_dir, libNode, pathname): """Looking for the best extension The 'best' is the longest match @@ -114,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'], @@ -122,7 +133,7 @@ class Submission(object): RDF.Statement(fileNode, libraryOntology['library'], libNode)) - + LOGGER.debug("Done.") def make_file_node(self, pathname, submissionNode): @@ -164,7 +175,7 @@ class Submission(object): except ValueError: # currently its just ignore it if the fastq name parser fails return - + terms = [('flowcell', libraryOntology['flowcell_id']), ('lib_id', libraryOntology['library_id']), ('lane', libraryOntology['lane_number']), @@ -176,6 +187,23 @@ class Submission(object): 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 set_attributes = set((libraryOntology['has_lane'], @@ -320,6 +348,8 @@ class Submission(object): 'Small RNA (non-multiplexed)',] paired = ['Barcoded Illumina', 'Multiplexing', + 'NEBNext Multiplexed', + 'NEBNext Small RNA', 'Nextera', 'Paired End (non-multiplexed)', 'Dual Index Illumina',] @@ -360,7 +390,7 @@ def list_submissions(model): query = RDF.SPARQLQuery(query_body) rdfstream = query.execute(model) for row in rdfstream: - s = stripNamespace(submissionLog, row['submission']) + s = strip_namespace(submissionLog, row['submission']) if s[-1] in ['#', '/', '?']: s = s[:-1] yield s