annotate TrackHub.py @ 7:5d5fdcb798da draft

planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
author yating-l
date Fri, 20 Apr 2018 13:51:23 -0400
parents 237707a6b74d
children 43a700afd457
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
1 #!/usr/bin/env python
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
2
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
3 import os
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
4 import subprocess
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
5 import shutil
3
eda851e52060 planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 479fc6490e24ca0e5034ae6c3579882e97e095e6-dirty
yating-l
parents: 2
diff changeset
6 import zipfile
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
7 import json
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
8 import tempfile
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
9 import logging
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
10 from mako.lookup import TemplateLookup
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
11
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
12 from datatypes.Datatype import Datatype
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
13 from tracks.TrackStyles import TrackStyles
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
14 from util import subtools
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
15 from util import santitizer
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
16
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
17
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
18 class TrackHub:
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
19 def __init__(self, inputFastaFile, outputFile, extra_files_path, tool_directory, trackType):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
20
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
21 self.mySpecieFolderPath = None
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
22
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
23 # Store intermediate files, will be removed if not in debug mode
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
24 self.myTracksFolderPath = None
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
25
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
26 # Store interval files and their tabix index
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
27 self.myFinalTracksFolderPath = None
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
28
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
29 # Store binary files: Bam, BigWig
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
30 self.myBinaryFolderPath = None
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
31
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
32 self.tool_directory = tool_directory
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
33 self.trackType = trackType
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
34 self.reference_genome = inputFastaFile
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
35 self.genome_name = inputFastaFile.assembly_id
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
36 self.extra_files_path = extra_files_path
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
37 self.outputFile = outputFile
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
38 self.chromSizesFile = None
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
39
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
40
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
41 # Set all the missing variables of this class, and create physically the folders/files
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
42 self.__createAssemblyHub__(extra_files_path=extra_files_path)
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
43 # Init the Datatype
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
44 Datatype.pre_init(self.reference_genome, self.chromSizesFile,
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
45 self.extra_files_path, self.tool_directory,
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
46 self.mySpecieFolderPath, self.myTracksFolderPath, self.myBinaryFolderPath, self.trackType)
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
47
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
48 self._prepareRefseq()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
49 self.trackList = os.path.join(self.mySpecieFolderPath, "trackList.json")
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
50 self._createTrackList()
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
51 if Datatype.trackType == 'HTMLFeatures':
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
52 self.myTrackStyle = TrackStyles(self.tool_directory, self.mySpecieFolderPath, self.trackList)
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
53 self.logger = logging.getLogger(__name__)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
54
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
55
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
56
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
57 def addTrack(self, trackDbObject):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
58 if trackDbObject['dataType'].lower() == 'bam':
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
59 subtools.add_track_json(self.trackList, trackDbObject['options'])
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
60 elif trackDbObject['dataType'].lower() == 'bigwig':
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
61 subtools.add_track_json(self.trackList, trackDbObject['options'])
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
62 else:
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
63 if trackDbObject['trackType'] == 'HTMLFeatures':
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
64 self._customizeHTMLFeature(trackDbObject)
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
65 subtools.flatfile_to_json(trackDbObject['trackDataURL'], trackDbObject['dataType'], trackDbObject['trackType'], trackDbObject['trackLabel'], self.mySpecieFolderPath, trackDbObject['options'])
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
66 # Use Tabix index tracks by default for CanvasFeatures
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
67 # TODO: add support for HTMLFeatures
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
68 else:
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
69 subtools.generate_tabix_indexed_track(trackDbObject['trackDataURL'], trackDbObject['dataType'], trackDbObject['track'], self.myFinalTracksFolderPath)
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
70 subtools.add_track_json(self.trackList, trackDbObject['options'])
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
71
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
72 def terminate(self, debug="false"):
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
73 """ Write html file """
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
74 self._indexName()
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
75 if debug.lower() == "false":
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
76 self._removeRaw()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
77 self._outHtml()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
78 print "Success!\n"
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
79
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
80
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
81 def _customizeHTMLFeature(self, trackDbObject):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
82 if trackDbObject['options']:
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
83 subfeatures = trackDbObject['options'].get('subfeatureClasses')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
84 feature_color = trackDbObject['options']['feature_color']
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
85 if subfeatures:
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
86 for key, value in subfeatures.items():
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
87 self.myTrackStyle.addCustomColor(value, feature_color)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
88 else:
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
89 customizedFeature = santitizer.sanitize_name(trackDbObject['trackLabel'])
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
90 clientConfig = json.loads(trackDbObject['options']['clientConfig'])
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
91 clientConfig['renderClassName'] = customizedFeature
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
92 trackDbObject['options']['clientConfig'] = json.dumps(clientConfig)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
93 self.myTrackStyle.addCustomColor(customizedFeature, feature_color)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
94
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
95 def _removeRaw(self):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
96 if os.path.exists(self.myTracksFolderPath):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
97 shutil.rmtree(self.myTracksFolderPath)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
98
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
99 def _createTrackList(self):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
100 if not os.path.exists(self.trackList):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
101 os.mknod(self.trackList)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
102
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
103 def _prepareRefseq(self):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
104 subtools.prepare_refseqs(self.reference_genome.false_path, self.mySpecieFolderPath)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
105
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
106 def _indexName(self):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
107 subtools.generate_names(self.mySpecieFolderPath)
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
108 print "finished name index \n"
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
109
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
110 def _outHtml(self):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
111 mylookup = TemplateLookup(directories=[os.path.join(self.tool_directory, 'templates')],
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
112 output_encoding='utf-8', encoding_errors='replace')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
113 htmlTemplate = mylookup.get_template("display.txt")
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
114
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
115 with open(self.outputFile, 'w') as htmlfile:
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
116 htmlMakoRendered = htmlTemplate.render(
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
117 jbrowse_hub_name = self.reference_genome.assembly_id,
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
118 trackList = os.path.relpath(self.trackList, self.extra_files_path)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
119 )
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
120 htmlfile.write(htmlMakoRendered)
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
121
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
122 def __createAssemblyHub__(self, extra_files_path):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
123 # Get all necessaries infos first
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
124 # 2bit file creation from input fasta
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
125 twoBitFile = tempfile.NamedTemporaryFile(bufsize=0)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
126 subtools.faToTwoBit(self.reference_genome.false_path, twoBitFile.name)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
127
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
128 # Generate the twoBitInfo
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
129 twoBitInfoFile = tempfile.NamedTemporaryFile(bufsize=0)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
130 subtools.twoBitInfo(twoBitFile.name, twoBitInfoFile.name)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
131
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
132 # Then we get the output to generate the chromSizes
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
133 self.chromSizesFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".chrom.sizes")
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
134 subtools.sortChromSizes(twoBitInfoFile.name, self.chromSizesFile.name)
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
135
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
136 # We can get the biggest scaffold here, with chromSizesFile
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
137 with open(self.chromSizesFile.name, 'r') as chrom_sizes:
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
138 # TODO: Check if exists
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
139 self.default_pos = chrom_sizes.readline().split()[0]
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
140
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
141 # Create the specie folder, use generic name "myHub", to support display JBrowse with Galaxy display application
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
142 mySpecieFolderPath = os.path.join(extra_files_path, "myHub")
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
143 if not os.path.exists(mySpecieFolderPath):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
144 os.makedirs(mySpecieFolderPath)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
145 self.mySpecieFolderPath = mySpecieFolderPath
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
146
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
147 # Create the folder named 'raw' inside the specie folder to place raw files
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
148 tracksFolderPath = os.path.join(mySpecieFolderPath, "raw")
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
149 if not os.path.exists(tracksFolderPath):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
150 os.makedirs(tracksFolderPath)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
151 self.myTracksFolderPath = tracksFolderPath
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
152
7
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
153 # Create the folder tracks into the specie folder
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
154 finalTracksFolderPath = os.path.join(mySpecieFolderPath, "tracks")
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
155 if not os.path.exists(finalTracksFolderPath):
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
156 os.makedirs(finalTracksFolderPath)
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
157 self.myFinalTracksFolderPath = finalTracksFolderPath
5d5fdcb798da planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 12fb52d5b285935b2353d93a5aa291838df7893e
yating-l
parents: 6
diff changeset
158
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
159 myBinaryFolderPath = os.path.join(mySpecieFolderPath, 'bbi')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
160 if not os.path.exists(myBinaryFolderPath):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
161 os.makedirs(myBinaryFolderPath)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
162 self.myBinaryFolderPath = myBinaryFolderPath