annotate hub-archive-creator-1.6/hubArchiveCreator.py @ 1:bfa14bec861c draft default tip

Deleted selected files
author rmarenco
date Fri, 04 Mar 2016 11:20:43 -0500
parents 163b2de763ea
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
1 #!/usr/bin/python
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
2 """
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
3 This Galaxy tool permits to prepare your files to be ready for
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
4 Assembly Hub visualization.
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
5 Program test arguments:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
6 hubArchiveCreator.py -g test_data/augustusDbia3.gff3 -f test_data/dbia3.fa -d . -o output.zip
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
7 """
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
8
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
9 import sys
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
10 import tempfile
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
11 import getopt
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
12 import zipfile
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
13 import subprocess
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
14 import os
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
15 import argparse
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
16
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
17 from mako.template import Template
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
18 from mako.lookup import TemplateLookup
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
19
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
20 # Internal dependencies
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
21 from twoBitCreator import twoBitFileCreator
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
22
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
23 # TODO: REMOVE THIS FROM BEING A GLOBAL VARIABLE
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
24 toolDirectory = '.'
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
25 extra_files_path = '.'
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
26
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
27 def main(argv):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
28 # Command Line parsing init
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
29 parser = argparse.ArgumentParser(description='Create a foo.txt inside the given folder.')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
30
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
31 parser.add_argument('-g', '--gff3', help='Directory where to put the foo.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
32 parser.add_argument('-f', '--fasta', help='Directory where to put the foo.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
33 parser.add_argument('-d', '--directory', help='Directory where to put the foo.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
34 parser.add_argument('-e', '--extra_files_path', help='Directory where to put the foo.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
35 parser.add_argument('-o', '--output', help='Directory where to put the foo.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
36
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
37
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
38 global toolDirectory
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
39 global extra_files_path
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
40 inputGFF3File = ''
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
41 inputFastaFile = ''
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
42
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
43 # Get the args passed in parameter
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
44 args = parser.parse_args()
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
45
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
46 inputGFF3File = open(args.gff3, 'r')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
47 inputFastaFile = open(args.fasta, 'r')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
48
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
49 if args.directory:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
50 toolDirectory = args.directory
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
51 if args.extra_files_path:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
52 extra_files_path = args.extra_files_path
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
53
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
54 outputZip = zipfile.ZipFile(os.path.join(extra_files_path, 'myHub.zip'), 'w')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
55
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
56
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
57 # Create the structure of the Assembly Hub
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
58 # TODO: Merge the following processing into a function as it is also used in twoBitCreator
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
59 baseNameFasta = os.path.basename(inputFastaFile.name)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
60 suffixTwoBit, extensionTwoBit = os.path.splitext(baseNameFasta)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
61 nameTwoBit = suffixTwoBit + '.2bit'
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
62
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
63 rootAssemblyHub = createAssemblyHub(outputZip, twoBitName=nameTwoBit)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
64
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
65 # TODO: See if we need these temporary files as part of the generated files
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
66 genePredFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".genePred")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
67 unsortedBedFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".unsortedBed")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
68 sortedBedFile = tempfile.NamedTemporaryFile(suffix=".sortedBed")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
69 twoBitInfoFile = tempfile.NamedTemporaryFile(bufsize=0)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
70 chromSizesFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".chrom.sizes")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
71
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
72 # gff3ToGenePred processing
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
73 p = subprocess.Popen(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
74 [os.path.join(toolDirectory, 'tools/gff3ToGenePred'),
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
75 inputGFF3File.name,
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
76 genePredFile.name])
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
77 # We need to wait the time gff3ToGenePred terminate so genePredToBed can begin
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
78 # TODO: Check if we should use communicate instead of wait
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
79 p.wait()
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
80
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
81 # genePredToBed processing
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
82 p = subprocess.Popen(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
83 [os.path.join(toolDirectory, 'tools/genePredToBed'),
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
84 genePredFile.name,
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
85 unsortedBedFile.name])
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
86 p.wait()
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
87
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
88 # Sort processing
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
89 p = subprocess.Popen(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
90 ['sort',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
91 '-k'
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
92 '1,1',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
93 '-k'
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
94 '2,2n',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
95 unsortedBedFile.name,
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
96 '-o',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
97 sortedBedFile.name])
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
98 p.wait()
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
99
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
100 mySpecieFolderPath = os.path.join(extra_files_path, "myHub", "dbia3")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
101
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
102 # 2bit file creation from input fasta
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
103 twoBitFile = twoBitFileCreator(inputFastaFile, toolDirectory, mySpecieFolderPath)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
104
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
105 # Generate the chrom.sizes
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
106 # TODO: Isolate in a function
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
107 # We first get the twoBit Infos
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
108 p = subprocess.Popen(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
109 [os.path.join(toolDirectory, 'tools/twoBitInfo'),
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
110 twoBitFile.name,
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
111 'stdout'],
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
112 stdout=subprocess.PIPE,
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
113 stderr=subprocess.PIPE)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
114
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
115 twoBitInfo_out, twoBitInfo_err = p.communicate()
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
116 twoBitInfoFile.write(twoBitInfo_out)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
117
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
118 # Then we get the output to inject into the sort
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
119 # TODO: Check if no errors
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
120 p = subprocess.Popen(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
121 ['sort',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
122 '-k2rn',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
123 twoBitInfoFile.name,
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
124 '-o',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
125 chromSizesFile.name])
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
126 p.wait()
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
127
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
128 # bedToBigBed processing
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
129 # bedToBigBed augustusDbia3.sortbed chrom.sizes augustusDbia3.bb
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
130 # TODO: Find the best to get this path without hardcoding it
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
131 myTrackFolderPath = os.path.join(mySpecieFolderPath, "tracks")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
132 # TODO: Change the name of the bb, to tool + genome + .bb
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
133 myBigBedFilePath = os.path.join(myTrackFolderPath, 'augustusDbia3.bb')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
134 with open(myBigBedFilePath, 'w') as bigBedFile:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
135 p = subprocess.Popen(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
136 [os.path.join(toolDirectory, 'tools/bedToBigBed'),
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
137 sortedBedFile.name,
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
138 chromSizesFile.name,
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
139 bigBedFile.name])
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
140 p.wait()
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
141
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
142 # TODO: Add the .bb file in the zip, at the right place
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
143
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
144 createZip(outputZip, rootAssemblyHub)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
145
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
146 # outputZip.write(sortedBedFile.name)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
147 # TODO: Find the best to get this path without hardcoding it
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
148
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
149 # outputZip.write(bigBedFile.name)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
150 outputZip.close()
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
151
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
152 # Just a test to output a simple HTML
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
153 with open(args.output, 'w') as htmlOutput:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
154 htmlOutput.write('<html>')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
155 htmlOutput.write('<body>')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
156 htmlOutput.write('<p>')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
157 htmlOutput.write('The following generated by Hub Archive Creator:')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
158 htmlOutput.write('</p>')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
159 htmlOutput.write('<ul>')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
160 for root, dirs, files in os.walk(extra_files_path):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
161 # Get all files and get all relative links at the same time
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
162 for file in files:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
163 relDir = os.path.relpath(root, extra_files_path)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
164 htmlOutput.write(str.format('<li><a href="{0}">{1}</a></li>', os.path.join(relDir, file), os.path.join(relDir, file)))
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
165 htmlOutput.write('<ul>')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
166 htmlOutput.write('</body>')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
167 htmlOutput.write('</html>')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
168
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
169 sys.exit(0)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
170
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
171
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
172 def createAssemblyHub(outputZip, twoBitName):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
173 # TODO: Manage to put every fill Function in a file dedicated for reading reasons
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
174 # Create the root directory
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
175 myHubPath = os.path.join(extra_files_path, "myHub")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
176 if not os.path.exists(myHubPath):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
177 os.makedirs(myHubPath)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
178
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
179 # Add the genomes.txt file
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
180 genomesTxtFilePath = os.path.join(myHubPath, 'genomes.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
181 fillGenomesTxt(genomesTxtFilePath, twoBitName)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
182
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
183 # Add the hub.txt file
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
184 hubTxtFilePath = os.path.join(myHubPath, 'hub.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
185 fillHubTxt(hubTxtFilePath)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
186
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
187 # Add the hub.html file
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
188 # TODO: Change the name and get it depending on the specie
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
189 hubHtmlFilePath = os.path.join(myHubPath, 'dbia.html')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
190 fillHubHtmlFile(hubHtmlFilePath)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
191
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
192 # Create the specie folder
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
193 # TODO: Generate the name depending on the specie
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
194 mySpecieFolderPath = os.path.join(myHubPath, "dbia3")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
195 if not os.path.exists(mySpecieFolderPath):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
196 os.makedirs(mySpecieFolderPath)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
197
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
198 # Create the trackDb.txt file in the specie folder
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
199 trackDbTxtFilePath = os.path.join(mySpecieFolderPath, 'trackDb.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
200 fillTrackDbTxtFile(trackDbTxtFilePath)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
201
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
202 # Create the description html file in the specie folder
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
203 descriptionHtmlFilePath = os.path.join(mySpecieFolderPath, 'description.html')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
204 fillDescriptionHtmlFile(descriptionHtmlFilePath)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
205
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
206 # Create the file groups.txt
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
207 # TODO: If not inputs for this, do no create the file
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
208 groupsTxtFilePath = os.path.join(mySpecieFolderPath, 'groups.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
209 fillGroupsTxtFile(groupsTxtFilePath)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
210
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
211 # Create the folder tracks into the specie folder
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
212 tracksFolderPath = os.path.join(mySpecieFolderPath, "tracks")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
213 if not os.path.exists(tracksFolderPath):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
214 os.makedirs(tracksFolderPath)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
215
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
216 return myHubPath
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
217
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
218
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
219 def fillGenomesTxt(genomesTxtFilePath, twoBitName):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
220 # TODO: Think about the inputs and outputs
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
221 # TODO: Manage the template of this file
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
222 # renderer = pystache.Renderer(search_dirs="templates/genomesAssembly")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
223 pathTemplate = os.path.join(toolDirectory, 'templates/genomesAssembly')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
224 mylookup = TemplateLookup(directories=[pathTemplate], output_encoding='utf-8', encoding_errors='replace')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
225 mytemplate = mylookup.get_template("layout.txt")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
226 with open(genomesTxtFilePath, 'w') as genomesTxtFile:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
227 # Write the content of the file genomes.txt
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
228 twoBitPath = os.path.join('dbia3/', twoBitName)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
229 htmlMakoRendered = mytemplate.render(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
230 genomeName="dbia3",
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
231 trackDbPath="dbia3/trackDb.txt",
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
232 groupsPath="dbia3/groups.txt",
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
233 genomeDescription="March 2013 Drosophilia biarmipes unplaced genomic scaffold",
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
234 twoBitPath=twoBitPath,
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
235 organismName="Drosophilia biarmipes",
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
236 defaultPosition="contig1",
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
237 orderKey="4500",
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
238 scientificName="Drosophilia biarmipes",
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
239 pathAssemblyHtmlDescription="dbia3/description.html"
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
240 )
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
241 genomesTxtFile.write(htmlMakoRendered)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
242
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
243
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
244 def fillHubTxt(hubTxtFilePath):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
245 # TODO: Think about the inputs and outputs
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
246 # TODO: Manage the template of this file
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
247 mylookup = TemplateLookup(directories=[os.path.join(toolDirectory, 'templates/hubTxt')], output_encoding='utf-8', encoding_errors='replace')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
248 mytemplate = mylookup.get_template('layout.txt')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
249 with open(hubTxtFilePath, 'w') as genomesTxtFile:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
250 # Write the content of the file genomes.txt
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
251 htmlMakoRendered = mytemplate.render(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
252 hubName='dbiaOnly',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
253 shortLabel='dbia',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
254 longLabel='This hub only contains dbia with the gene predictions',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
255 genomesFile='genomes.txt',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
256 email='rmarenco@gwu.edu',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
257 descriptionUrl='dbia.html'
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
258 )
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
259 genomesTxtFile.write(htmlMakoRendered)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
260
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
261
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
262 def fillHubHtmlFile(hubHtmlFilePath):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
263 # TODO: Think about the inputs and outputs
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
264 # TODO: Manage the template of this file
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
265 # renderer = pystache.Renderer(search_dirs="templates/hubDescription")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
266 # t = Template(templates.hubDescription.layout.html)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
267 mylookup = TemplateLookup(directories=[os.path.join(toolDirectory, 'templates/hubDescription')], output_encoding='utf-8', encoding_errors='replace')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
268 mytemplate = mylookup.get_template("layout.txt")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
269 with open(hubHtmlFilePath, 'w') as hubHtmlFile:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
270 # Write the content of the file genomes.txt
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
271 # htmlPystached = renderer.render_name(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
272 # "layout",
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
273 # {'specie': 'Dbia',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
274 # 'toolUsed': 'Augustus',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
275 # 'ncbiSpecieUrl': 'http://www.ncbi.nlm.nih.gov/genome/3499',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
276 # 'genomeID': '3499',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
277 # 'SpecieFullName': 'Drosophila biarmipes'})
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
278 htmlMakoRendered = mytemplate.render(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
279 specie='Dbia',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
280 toolUsed='Augustus',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
281 ncbiSpecieUrl='http://www.ncbi.nlm.nih.gov/genome/3499',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
282 genomeID='3499',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
283 specieFullName='Drosophila biarmipes'
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
284 )
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
285 # hubHtmlFile.write(htmlPystached)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
286 hubHtmlFile.write(htmlMakoRendered)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
287
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
288
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
289 def fillTrackDbTxtFile(trackDbTxtFilePath):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
290 # TODO: Modify according to the files passed in parameter
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
291 mylookup = TemplateLookup(directories=[os.path.join(toolDirectory, 'templates/trackDb')], output_encoding='utf-8', encoding_errors='replace')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
292 mytemplate = mylookup.get_template("layout.txt")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
293 with open(trackDbTxtFilePath, 'w') as trackDbFile:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
294 htmlMakoRendered = mytemplate.render(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
295 trackName='augustusTrack',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
296 trackDataURL='Augustus_dbia3',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
297 shortLabel='a_dbia',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
298 longLabel='tracks/augustusDbia3.bb',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
299 trackType='bigBed 12 +',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
300 visibility='dense'
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
301 )
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
302 trackDbFile.write(htmlMakoRendered)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
303
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
304
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
305 def fillDescriptionHtmlFile(descriptionHtmlFilePath):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
306 # TODO: Think about the inputs and outputs
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
307 # TODO: Manage the template of this file
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
308 mylookup = TemplateLookup(directories=[os.path.join(toolDirectory, 'templates/specieDescription')], output_encoding='utf-8', encoding_errors='replace')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
309 mytemplate = mylookup.get_template("layout.txt")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
310 with open(descriptionHtmlFilePath, 'w') as descriptionHtmlFile:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
311 # Write the content of the file genomes.txt
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
312 htmlMakoRendered = mytemplate.render(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
313 specieDescription='This is the description of the dbia',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
314 )
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
315 descriptionHtmlFile.write(htmlMakoRendered)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
316
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
317
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
318 def fillGroupsTxtFile(groupsTxtFilePath):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
319 mylookup = TemplateLookup(directories=[os.path.join(toolDirectory, 'templates/groupsTxt')], output_encoding='utf-8', encoding_errors='replace')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
320 mytemplate = mylookup.get_template("layout.txt")
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
321 with open(groupsTxtFilePath, 'w') as groupsTxtFile:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
322 # Write the content of groups.txt
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
323 # groupsTxtFile.write('name map')
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
324 htmlMakoRendered = mytemplate.render(
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
325 mapName='map',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
326 labelMapping='Mapping',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
327 prioriy='2',
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
328 isClosed='0'
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
329 )
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
330 # groupsTxtFile.write(htmlMakoRendered)
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
331
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
332
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
333 def createZip(myZip, folder):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
334 for root, dirs, files in os.walk(folder):
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
335 # Get all files and construct the dir at the same time
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
336 for file in files:
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
337 myZip.write(os.path.join(root, file))
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
338
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
339 if __name__ == "__main__":
163b2de763ea Upload the full hubArchiveCreator archive
rmarenco
parents:
diff changeset
340 main(sys.argv)