comparison doc/_build/html/_modules/hubArchiveCreator.html @ 20:40469b265ddb draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 3af31e043f5b82636015c18e013d2f22ce6c9077-dirty
author yating-l
date Fri, 20 Jan 2017 17:12:03 -0500
parents
children
comparison
equal deleted inserted replaced
19:0152500d9acd 20:40469b265ddb
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
4
5 <html xmlns="http://www.w3.org/1999/xhtml">
6 <head>
7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8
9 <title>hubArchiveCreator &#8212; HubArchiveCreator 2.3 documentation</title>
10
11 <link rel="stylesheet" href="../_static/classic.css" type="text/css" />
12 <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
13
14 <script type="text/javascript">
15 var DOCUMENTATION_OPTIONS = {
16 URL_ROOT: '../',
17 VERSION: '2.3',
18 COLLAPSE_INDEX: false,
19 FILE_SUFFIX: '.html',
20 HAS_SOURCE: true
21 };
22 </script>
23 <script type="text/javascript" src="../_static/jquery.js"></script>
24 <script type="text/javascript" src="../_static/underscore.js"></script>
25 <script type="text/javascript" src="../_static/doctools.js"></script>
26 <script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
27 <link rel="index" title="Index" href="../genindex.html" />
28 <link rel="search" title="Search" href="../search.html" />
29 <link rel="top" title="HubArchiveCreator 2.3 documentation" href="../index.html" />
30 <link rel="up" title="Module code" href="index.html" />
31 </head>
32 <body role="document">
33 <div class="related" role="navigation" aria-label="related navigation">
34 <h3>Navigation</h3>
35 <ul>
36 <li class="right" style="margin-right: 10px">
37 <a href="../genindex.html" title="General Index"
38 accesskey="I">index</a></li>
39 <li class="right" >
40 <a href="../py-modindex.html" title="Python Module Index"
41 >modules</a> |</li>
42 <li class="nav-item nav-item-0"><a href="../index.html">HubArchiveCreator 2.3 documentation</a> &#187;</li>
43 <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Module code</a> &#187;</li>
44 </ul>
45 </div>
46
47 <div class="document">
48 <div class="documentwrapper">
49 <div class="bodywrapper">
50 <div class="body" role="main">
51
52 <h1>Source code for hubArchiveCreator</h1><div class="highlight"><pre>
53 <span></span><span class="ch">#!/usr/bin/python</span>
54 <span class="c1"># -*- coding: utf8 -*-</span>
55
56 <span class="sd">&quot;&quot;&quot;</span>
57 <span class="sd">This Galaxy tool permits to prepare your files to be ready for</span>
58 <span class="sd">Assembly Hub visualization.</span>
59 <span class="sd">Program test arguments:</span>
60 <span class="sd">hubArchiveCreator.py -g test-data/augustusDbia3.gff3 -f test-data/dbia3.fa -d . -u ./tools -o output.html</span>
61 <span class="sd">&quot;&quot;&quot;</span>
62
63 <span class="kn">import</span> <span class="nn">argparse</span>
64 <span class="kn">import</span> <span class="nn">collections</span>
65 <span class="kn">import</span> <span class="nn">json</span>
66 <span class="kn">import</span> <span class="nn">logging</span>
67 <span class="kn">import</span> <span class="nn">os</span>
68 <span class="kn">import</span> <span class="nn">sys</span>
69
70 <span class="c1"># Internal dependencies</span>
71 <span class="kn">from</span> <span class="nn">Bam</span> <span class="k">import</span> <span class="n">Bam</span>
72 <span class="kn">from</span> <span class="nn">BedSimpleRepeats</span> <span class="k">import</span> <span class="n">BedSimpleRepeats</span>
73 <span class="kn">from</span> <span class="nn">Bed</span> <span class="k">import</span> <span class="n">Bed</span>
74 <span class="kn">from</span> <span class="nn">BigWig</span> <span class="k">import</span> <span class="n">BigWig</span>
75 <span class="kn">from</span> <span class="nn">util.Fasta</span> <span class="k">import</span> <span class="n">Fasta</span>
76 <span class="kn">from</span> <span class="nn">util.Filters</span> <span class="k">import</span> <span class="n">TraceBackFormatter</span>
77 <span class="kn">from</span> <span class="nn">Gff3</span> <span class="k">import</span> <span class="n">Gff3</span>
78 <span class="kn">from</span> <span class="nn">Gtf</span> <span class="k">import</span> <span class="n">Gtf</span>
79 <span class="kn">from</span> <span class="nn">Psl</span> <span class="k">import</span> <span class="n">Psl</span>
80 <span class="kn">from</span> <span class="nn">TrackHub</span> <span class="k">import</span> <span class="n">TrackHub</span>
81
82 <span class="c1"># TODO: Verify each subprocessed dependency is accessible [gff3ToGenePred, genePredToBed, twoBitInfo, faToTwoBit, bedToBigBed, sort</span>
83
84
85 <span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">argv</span><span class="p">):</span>
86 <span class="c1"># Command Line parsing init</span>
87 <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">(</span><span class="n">description</span><span class="o">=</span><span class="s1">&#39;Create a foo.txt inside the given folder.&#39;</span><span class="p">)</span>
88
89 <span class="c1"># Reference genome mandatory</span>
90 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;-f&#39;</span><span class="p">,</span> <span class="s1">&#39;--fasta&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Fasta file of the reference genome&#39;</span><span class="p">)</span>
91
92 <span class="c1"># GFF3 Management</span>
93 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--gff3&#39;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">&#39;append&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;GFF3 format&#39;</span><span class="p">)</span>
94
95 <span class="c1"># GTF Management</span>
96 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--gtf&#39;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">&#39;append&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;GTF format&#39;</span><span class="p">)</span>
97
98 <span class="c1"># Bed4+12 (TrfBig)</span>
99 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--bedSimpleRepeats&#39;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">&#39;append&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Bed4+12 format, using simpleRepeats.as&#39;</span><span class="p">)</span>
100
101 <span class="c1"># Generic Bed (Blastx transformed to bed)</span>
102 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--bed&#39;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">&#39;append&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Bed generic format&#39;</span><span class="p">)</span>
103
104 <span class="c1"># BigWig Management</span>
105 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--bigwig&#39;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">&#39;append&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;BigWig format&#39;</span><span class="p">)</span>
106
107 <span class="c1"># Bam Management</span>
108 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--bam&#39;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">&#39;append&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Bam format&#39;</span><span class="p">)</span>
109
110 <span class="c1"># Psl Management</span>
111 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--psl&#39;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">&#39;append&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Psl format&#39;</span><span class="p">)</span>
112
113 <span class="c1"># TODO: Check if the running directory can have issues if we run the tool outside</span>
114 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;-d&#39;</span><span class="p">,</span> <span class="s1">&#39;--directory&#39;</span><span class="p">,</span>
115 <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Running tool directory, where to find the templates. Default is running directory&#39;</span><span class="p">)</span>
116 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;-u&#39;</span><span class="p">,</span> <span class="s1">&#39;--ucsc_tools_path&#39;</span><span class="p">,</span>
117 <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Directory where to find the executables needed to run this tool&#39;</span><span class="p">)</span>
118 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;-e&#39;</span><span class="p">,</span> <span class="s1">&#39;--extra_files_path&#39;</span><span class="p">,</span>
119 <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Name, in galaxy, of the output folder. Where you would want to build the Track Hub Archive&#39;</span><span class="p">)</span>
120 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;-o&#39;</span><span class="p">,</span> <span class="s1">&#39;--output&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Name of the HTML summarizing the content of the Track Hub Archive&#39;</span><span class="p">)</span>
121
122 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;-j&#39;</span><span class="p">,</span> <span class="s1">&#39;--data_json&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Json containing the metadata of the inputs&#39;</span><span class="p">)</span>
123
124 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--user_email&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Email of the user who launched the Hub Archive Creation&#39;</span><span class="p">)</span>
125
126 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--genome_name&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;UCSC Genome Browser assembly ID&#39;</span><span class="p">)</span>
127
128 <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s1">&#39;--debug_mode&#39;</span><span class="p">,</span> <span class="n">action</span><span class="o">=</span><span class="s1">&#39;store_true&#39;</span><span class="p">,</span> <span class="n">help</span><span class="o">=</span><span class="s1">&#39;Allow more details about the errors&#39;</span><span class="p">)</span>
129
130 <span class="c1"># Begin init variables</span>
131
132 <span class="n">toolDirectory</span> <span class="o">=</span> <span class="s1">&#39;.&#39;</span>
133 <span class="n">extra_files_path</span> <span class="o">=</span> <span class="s1">&#39;.&#39;</span>
134
135 <span class="c1"># Get the args passed in parameter</span>
136 <span class="n">args</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
137
138 <span class="n">extra_files_path</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">extra_files_path</span>
139 <span class="n">toolDirectory</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">directory</span>
140
141 <span class="c1">#### Logging management ####</span>
142 <span class="c1"># If we are in Debug mode, also print in stdout the debug dump</span>
143
144 <span class="n">configure_logger</span><span class="p">(</span><span class="n">extra_files_path</span><span class="o">=</span><span class="n">extra_files_path</span><span class="p">,</span> <span class="n">debug</span><span class="o">=</span><span class="n">args</span><span class="o">.</span><span class="n">debug_mode</span><span class="p">)</span>
145
146 <span class="c1">#### END Logging management ####</span>
147
148 <span class="n">array_inputs_reference_genome</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">fasta</span><span class="p">)</span>
149
150 <span class="c1"># TODO: Replace these with the object Fasta</span>
151 <span class="n">input_fasta_file</span> <span class="o">=</span> <span class="n">array_inputs_reference_genome</span><span class="p">[</span><span class="s2">&quot;false_path&quot;</span><span class="p">]</span>
152 <span class="n">input_fasta_file_name</span> <span class="o">=</span> <span class="n">sanitize_name_input</span><span class="p">(</span><span class="n">array_inputs_reference_genome</span><span class="p">[</span><span class="s2">&quot;name&quot;</span><span class="p">])</span>
153 <span class="n">genome_name</span> <span class="o">=</span> <span class="n">sanitize_name_input</span><span class="p">(</span><span class="n">args</span><span class="o">.</span><span class="n">genome_name</span><span class="p">)</span>
154
155 <span class="n">reference_genome</span> <span class="o">=</span> <span class="n">Fasta</span><span class="p">(</span><span class="n">input_fasta_file</span><span class="p">,</span>
156 <span class="n">input_fasta_file_name</span><span class="p">,</span> <span class="n">genome_name</span><span class="p">)</span>
157
158 <span class="n">user_email</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">user_email</span>
159
160
161 <span class="c1"># TODO: Use a class to have a better management of the structure of these inputs</span>
162 <span class="c1"># These inputs are populated in the Galaxy Wrapper xml and are in this format:</span>
163 <span class="c1"># ARRAY[DICT{FILE_PATH: DICT{NAME: NAME_VALUE, EXTRA_DATA: EXTRA_DATA_VALUE}}]</span>
164 <span class="c1"># EXTRA_DATA could be anything, for example the index of a BAM =&gt; {&quot;index&quot;, FILE_PATH}</span>
165 <span class="n">array_inputs_bam</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">bam</span>
166 <span class="n">array_inputs_bed_generic</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">bed</span>
167 <span class="n">array_inputs_bed_simple_repeats</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">bedSimpleRepeats</span>
168 <span class="n">array_inputs_bigwig</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">bigwig</span>
169 <span class="n">array_inputs_gff3</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">gff3</span>
170 <span class="n">array_inputs_gtf</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">gtf</span>
171 <span class="n">array_inputs_psl</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">psl</span>
172
173 <span class="n">outputFile</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">output</span>
174
175 <span class="n">json_inputs_data</span> <span class="o">=</span> <span class="n">args</span><span class="o">.</span><span class="n">data_json</span>
176
177 <span class="n">inputs_data</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">json_inputs_data</span><span class="p">)</span>
178 <span class="c1"># We remove the spaces in [&quot;name&quot;] of inputs_data</span>
179 <span class="n">sanitize_name_inputs</span><span class="p">(</span><span class="n">inputs_data</span><span class="p">)</span>
180
181 <span class="c1"># TODO: Check here all the binaries / tools we need. Exception if missing</span>
182
183 <span class="c1"># Create the Track Hub folder</span>
184 <span class="n">trackHub</span> <span class="o">=</span> <span class="n">TrackHub</span><span class="p">(</span><span class="n">reference_genome</span><span class="p">,</span> <span class="n">user_email</span><span class="p">,</span> <span class="n">outputFile</span><span class="p">,</span> <span class="n">extra_files_path</span><span class="p">,</span> <span class="n">toolDirectory</span><span class="p">)</span>
185
186 <span class="n">all_datatype_dictionary</span> <span class="o">=</span> <span class="p">{}</span>
187
188 <span class="k">for</span> <span class="p">(</span><span class="n">inputs</span><span class="p">,</span> <span class="n">datatype_class</span><span class="p">)</span> <span class="ow">in</span> <span class="p">[</span>
189 <span class="p">(</span><span class="n">array_inputs_bam</span><span class="p">,</span> <span class="n">Bam</span><span class="p">),</span>
190 <span class="p">(</span><span class="n">array_inputs_bed_generic</span><span class="p">,</span> <span class="n">Bed</span><span class="p">),</span>
191 <span class="p">(</span><span class="n">array_inputs_bigwig</span><span class="p">,</span> <span class="n">BigWig</span><span class="p">),</span>
192 <span class="p">(</span><span class="n">array_inputs_bed_simple_repeats</span><span class="p">,</span> <span class="n">BedSimpleRepeats</span><span class="p">),</span>
193 <span class="p">(</span><span class="n">array_inputs_gff3</span><span class="p">,</span> <span class="n">Gff3</span><span class="p">),</span>
194 <span class="p">(</span><span class="n">array_inputs_gtf</span><span class="p">,</span> <span class="n">Gtf</span><span class="p">),</span>
195 <span class="p">(</span><span class="n">array_inputs_psl</span><span class="p">,</span> <span class="n">Psl</span><span class="p">)]:</span>
196 <span class="k">if</span> <span class="n">inputs</span><span class="p">:</span>
197 <span class="n">all_datatype_dictionary</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">create_ordered_datatype_objects</span><span class="p">(</span><span class="n">datatype_class</span><span class="p">,</span> <span class="n">inputs</span><span class="p">,</span> <span class="n">inputs_data</span><span class="p">))</span>
198
199 <span class="c1"># Create Ordered Dictionary to add the tracks in the tool form order</span>
200 <span class="n">all_datatype_ordered_dictionary</span> <span class="o">=</span> <span class="n">collections</span><span class="o">.</span><span class="n">OrderedDict</span><span class="p">(</span><span class="n">all_datatype_dictionary</span><span class="p">)</span>
201
202 <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;----- End of all_datatype_dictionary processing -----&quot;</span><span class="p">)</span>
203 <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;all_datatype_ordered_dictionary keys are: </span><span class="si">{0}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">all_datatype_ordered_dictionary</span><span class="o">.</span><span class="n">values</span><span class="p">()))</span>
204
205 <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;----- Beginning of Track adding processing -----&quot;</span><span class="p">)</span>
206 <span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">datatypeObject</span> <span class="ow">in</span> <span class="n">all_datatype_ordered_dictionary</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
207 <span class="n">trackHub</span><span class="o">.</span><span class="n">addTrack</span><span class="p">(</span><span class="n">datatypeObject</span><span class="o">.</span><span class="n">track</span><span class="o">.</span><span class="n">trackDb</span><span class="p">)</span>
208 <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;----- End of Track adding processing -----&quot;</span><span class="p">)</span>
209
210 <span class="c1"># We process all the modifications to create the zip file</span>
211 <span class="c1">#trackHub.createZip()</span>
212
213 <span class="c1"># We terminate le process and so create a HTML file summarizing all the files</span>
214 <span class="n">trackHub</span><span class="o">.</span><span class="n">terminate</span><span class="p">()</span>
215
216 <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;#### End of HubArchiveCreator Debug Mode: Bye! ####&#39;</span><span class="p">)</span>
217
218 <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
219
220
221 <div class="viewcode-block" id="sanitize_name_input"><a class="viewcode-back" href="../code.html#hubArchiveCreator.sanitize_name_input">[docs]</a><span class="k">def</span> <span class="nf">sanitize_name_input</span><span class="p">(</span><span class="n">string_to_sanitize</span><span class="p">):</span>
222 <span class="sd">&quot;&quot;&quot;</span>
223 <span class="sd"> Sanitize the string passed in parameter by replacing &#39;/&#39; and &#39; &#39; by &#39;_&#39;</span>
224
225 <span class="sd"> :param string_to_sanitize:</span>
226 <span class="sd"> :return :</span>
227
228 <span class="sd"> :Example:</span>
229
230 <span class="sd"> &gt;&gt;&gt; sanitize_name_input(&#39;this/is an//example&#39;)</span>
231 <span class="sd"> this_is_an__example</span>
232 <span class="sd"> &quot;&quot;&quot;</span>
233 <span class="k">return</span> <span class="n">string_to_sanitize</span> \
234 <span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="s2">&quot;_&quot;</span><span class="p">)</span> \
235 <span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="p">,</span> <span class="s2">&quot;_&quot;</span><span class="p">)</span></div>
236
237
238 <div class="viewcode-block" id="sanitize_name_inputs"><a class="viewcode-back" href="../code.html#hubArchiveCreator.sanitize_name_inputs">[docs]</a><span class="k">def</span> <span class="nf">sanitize_name_inputs</span><span class="p">(</span><span class="n">inputs_data</span><span class="p">):</span>
239 <span class="sd">&quot;&quot;&quot;</span>
240 <span class="sd"> Sanitize value of the keys &quot;name&quot; of the dictionary passed in parameter.</span>
241
242 <span class="sd"> Because sometimes output from Galaxy, or even just file name, from user inputs, have spaces.</span>
243 <span class="sd"> Also, it can contain &#39;/&#39; character and could break the use of os.path function.</span>
244
245 <span class="sd"> :param inputs_data: dict[string, dict[string, string]]</span>
246 <span class="sd"> &quot;&quot;&quot;</span>
247 <span class="k">for</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">inputs_data</span><span class="p">:</span>
248 <span class="n">inputs_data</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">sanitize_name_input</span><span class="p">(</span><span class="n">inputs_data</span><span class="p">[</span><span class="n">key</span><span class="p">][</span><span class="s2">&quot;name&quot;</span><span class="p">])</span></div>
249
250
251 <div class="viewcode-block" id="create_ordered_datatype_objects"><a class="viewcode-back" href="../code.html#hubArchiveCreator.create_ordered_datatype_objects">[docs]</a><span class="k">def</span> <span class="nf">create_ordered_datatype_objects</span><span class="p">(</span><span class="n">ExtensionClass</span><span class="p">,</span> <span class="n">array_inputs</span><span class="p">,</span> <span class="n">inputs_data</span><span class="p">):</span>
252 <span class="sd">&quot;&quot;&quot;</span>
253 <span class="sd"> Function which executes the creation all the necessary files / folders for a special Datatype, for TrackHub</span>
254 <span class="sd"> and update the dictionary of datatype</span>
255
256 <span class="sd"> :param ExtensionClass:</span>
257 <span class="sd"> :param array_inputs:</span>
258 <span class="sd"> :param inputs_data:</span>
259 <span class="sd"> :type ExtensionClass: Datatype</span>
260 <span class="sd"> :type array_inputs: list[string]</span>
261 <span class="sd"> :type inputs_data: dict</span>
262 <span class="sd"> :rtype: dict</span>
263 <span class="sd"> &quot;&quot;&quot;</span>
264
265 <span class="n">datatype_dictionary</span> <span class="o">=</span> <span class="p">{}</span>
266
267 <span class="c1"># TODO: Optimize this double loop</span>
268 <span class="k">for</span> <span class="n">input_false_path</span> <span class="ow">in</span> <span class="n">array_inputs</span><span class="p">:</span>
269 <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">data_value</span> <span class="ow">in</span> <span class="n">inputs_data</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
270 <span class="k">if</span> <span class="n">key</span> <span class="o">==</span> <span class="n">input_false_path</span><span class="p">:</span>
271 <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;input_false_path: &quot;</span> <span class="o">+</span> <span class="n">input_false_path</span><span class="p">)</span>
272 <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s2">&quot;data_value: &quot;</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">data_value</span><span class="p">))</span>
273 <span class="n">extensionObject</span> <span class="o">=</span> <span class="n">ExtensionClass</span><span class="p">(</span><span class="n">input_false_path</span><span class="p">,</span> <span class="n">data_value</span><span class="p">)</span>
274 <span class="n">datatype_dictionary</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">data_value</span><span class="p">[</span><span class="s2">&quot;order_index&quot;</span><span class="p">]:</span> <span class="n">extensionObject</span><span class="p">})</span>
275 <span class="k">return</span> <span class="n">datatype_dictionary</span></div>
276
277 <span class="k">def</span> <span class="nf">configure_logger</span><span class="p">(</span><span class="n">extra_files_path</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">debug</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
278 <span class="k">if</span> <span class="ow">not</span> <span class="n">extra_files_path</span><span class="p">:</span>
279 <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;Extra files path is not set. Stopping the application&quot;</span><span class="p">)</span>
280
281
282 <span class="c1"># All case log: log everything in a .log file</span>
283 <span class="n">logger_file_name</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">__name__</span><span class="p">,</span> <span class="s1">&#39;.log&#39;</span><span class="p">])</span>
284 <span class="n">logging_file_path</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">extra_files_path</span><span class="p">,</span> <span class="n">logger_file_name</span><span class="p">)</span>
285
286 <span class="n">logging</span><span class="o">.</span><span class="n">basicConfig</span><span class="p">(</span><span class="n">filename</span><span class="o">=</span><span class="n">logging_file_path</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span>
287
288 <span class="n">log_stdout</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">)</span>
289 <span class="k">if</span> <span class="ow">not</span> <span class="n">debug</span><span class="p">:</span>
290 <span class="n">configure_logger_user</span><span class="p">(</span><span class="n">log_stdout</span><span class="p">)</span>
291 <span class="k">else</span><span class="p">:</span>
292 <span class="n">configure_logger_dev</span><span class="p">(</span><span class="n">log_stdout</span><span class="p">)</span>
293
294 <span class="c1"># stderr configuration</span>
295 <span class="n">configure_logger_stderr</span><span class="p">()</span>
296
297 <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;#### Welcome in HubArchiveCreator Debug Mode ####</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
298
299 <div class="viewcode-block" id="configure_logger_user"><a class="viewcode-back" href="../code.html#hubArchiveCreator.configure_logger_user">[docs]</a><span class="k">def</span> <span class="nf">configure_logger_user</span><span class="p">(</span><span class="n">log_stdout</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
300 <span class="sd">&quot;&quot;&quot;</span>
301 <span class="sd"> User Logger is defined as following:</span>
302 <span class="sd"> - User needs to have WARN, ERROR and CRITICAL but well formatted / without traceback</span>
303 <span class="sd"> in STDOUT</span>
304 <span class="sd"> - Still access to full, brute and traceback for errors</span>
305 <span class="sd"> in STDERR</span>
306 <span class="sd"> - And further access to debug if needed</span>
307 <span class="sd"> in .log</span>
308
309 <span class="sd"> &quot;&quot;&quot;</span>
310
311 <span class="k">if</span> <span class="ow">not</span> <span class="n">log_stdout</span><span class="p">:</span>
312 <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;No log_stdout given. Stopping the application&quot;</span><span class="p">)</span>
313
314 <span class="c1"># stdout for INFO / WARN / ERROR / CRITICAL</span>
315 <span class="n">log_stdout</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">INFO</span><span class="p">)</span>
316
317 <span class="n">formatter</span> <span class="o">=</span> <span class="n">TraceBackFormatter</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">%(message)s</span><span class="s1">&#39;</span><span class="p">)</span>
318
319 <span class="n">log_stdout</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">formatter</span><span class="p">)</span>
320
321 <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">log_stdout</span><span class="p">)</span></div>
322
323 <div class="viewcode-block" id="configure_logger_dev"><a class="viewcode-back" href="../code.html#hubArchiveCreator.configure_logger_dev">[docs]</a><span class="k">def</span> <span class="nf">configure_logger_dev</span><span class="p">(</span><span class="n">log_stdout</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
324 <span class="sd">&quot;&quot;&quot;</span>
325 <span class="sd"> Dev Logger is defined as following:</span>
326 <span class="sd"> - Dev needs to have WARN, ERROR and CRITICAL but well formatted / without traceback, in stdout</span>
327 <span class="sd"> - Still access to full, brute and traceback in stderr for errors</span>
328 <span class="sd"> - And further access to debug if needed</span>
329
330 <span class="sd"> &quot;&quot;&quot;</span>
331 <span class="k">if</span> <span class="ow">not</span> <span class="n">log_stdout</span><span class="p">:</span>
332 <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s2">&quot;No log_stdout given. Stopping the application&quot;</span><span class="p">)</span>
333 <span class="n">log_format</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%(message)s</span><span class="s1">&#39;</span>
334
335 <span class="c1"># stdout and stderr and both identical for INFO / WARN / ERROR / CRITICAL</span>
336 <span class="n">log_stdout</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">)</span>
337
338 <span class="n">formatter</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="n">log_format</span><span class="p">)</span>
339
340 <span class="n">log_stdout</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">formatter</span><span class="p">)</span>
341
342 <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">log_stdout</span><span class="p">)</span></div>
343
344 <div class="viewcode-block" id="configure_logger_stderr"><a class="viewcode-back" href="../code.html#hubArchiveCreator.configure_logger_stderr">[docs]</a><span class="k">def</span> <span class="nf">configure_logger_stderr</span><span class="p">():</span>
345 <span class="sd">&quot;&quot;&quot;</span>
346 <span class="sd"> Configure what should be logged in stderr</span>
347 <span class="sd"> &quot;&quot;&quot;</span>
348 <span class="n">log_error</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stderr</span><span class="p">)</span>
349 <span class="n">log_error</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">ERROR</span><span class="p">)</span>
350 <span class="n">log_error_format</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%(message)s</span><span class="s1">&#39;</span>
351
352 <span class="n">formatter_error</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="n">log_error_format</span><span class="p">)</span>
353
354 <span class="n">log_error</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">formatter_error</span><span class="p">)</span>
355
356 <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">()</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">log_error</span><span class="p">)</span></div>
357
358 <span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
359 <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
360 <span class="n">main</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">)</span>
361 </pre></div>
362
363 </div>
364 </div>
365 </div>
366 <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
367 <div class="sphinxsidebarwrapper">
368 <div id="searchbox" style="display: none" role="search">
369 <h3>Quick search</h3>
370 <form class="search" action="../search.html" method="get">
371 <div><input type="text" name="q" /></div>
372 <div><input type="submit" value="Go" /></div>
373 <input type="hidden" name="check_keywords" value="yes" />
374 <input type="hidden" name="area" value="default" />
375 </form>
376 </div>
377 <script type="text/javascript">$('#searchbox').show(0);</script>
378 </div>
379 </div>
380 <div class="clearer"></div>
381 </div>
382 <div class="related" role="navigation" aria-label="related navigation">
383 <h3>Navigation</h3>
384 <ul>
385 <li class="right" style="margin-right: 10px">
386 <a href="../genindex.html" title="General Index"
387 >index</a></li>
388 <li class="right" >
389 <a href="../py-modindex.html" title="Python Module Index"
390 >modules</a> |</li>
391 <li class="nav-item nav-item-0"><a href="../index.html">HubArchiveCreator 2.3 documentation</a> &#187;</li>
392 <li class="nav-item nav-item-1"><a href="index.html" >Module code</a> &#187;</li>
393 </ul>
394 </div>
395 <div class="footer" role="contentinfo">
396 &#169; Copyright 2016, Remi Marenco.
397 Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.8.
398 </div>
399 </body>
400 </html>