Start developing GEO SOFT submission tool.
[htsworkflow.git] / htsworkflow / submission / geo.py
1 import logging
2
3 import RDF
4
5 from htsworkflow.submission.submission import Submission
6
7 from htsworkflow.util.rdfhelp import \
8      fromTypedNode, \
9      submissionOntology
10
11 from django.conf import settings
12 from django.template import Context, loader
13
14 LOGGER = logging.getLogger(__name__)
15
16 class GEOSubmission(Submission):
17     def __init__(self, name, model):
18         super(GEOSubmission, self).__init__(name, model)
19
20     def make_soft(self, result_map):
21         samples = []
22         for lib_id, result_dir in result_map.items():
23             an_analysis = self.get_submission_node(result_dir)
24             samples.append(self.get_sample_metadata(an_analysis))
25
26         soft_template = loader.get_template('geo_submission.soft')
27         context = Context({
28             'samples': samples
29         })
30         print str(soft_template.render(context))
31
32     def check_for_name(self, analysis_node):
33         name = fromTypedNode(
34             self.model.get_target(analysis_node,
35                                   submissionOntology['name']))
36         if name is None:
37             logger.error("Need name for %s" % (str(analysis_node)))
38             return False
39         else:
40             return True
41
42     def get_sample_metadata(self, analysis_node):
43         """Gather information for filling out sample section of a SOFT file
44         """
45         query_template = loader.get_template('geo_submission.sparql')
46
47         context = Context({
48             'submission': str(analysis_node.uri),
49             })
50
51         formatted_query = query_template.render(context)
52         query = RDF.SPARQLQuery(str(formatted_query))
53         rdfstream = query.execute(self.model)
54         results = []
55         for r in rdfstream:
56             results.append(r)
57         return results