annotate TrackHub.py @ 6:237707a6b74d draft

planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
author yating-l
date Thu, 15 Feb 2018 17:05:05 -0500
parents 7e471cdd9e71
children 5d5fdcb798da
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.rootAssemblyHub = 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 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
24
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
25 # 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
26 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
27
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
28 # 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
29 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
30
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
31 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
32 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
33 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
34 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
35 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
36 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
37 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
38
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 # Set all the missing variables of this class, and create physically the folders/files
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
41 self.rootAssemblyHub = self.__createAssemblyHub__(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
42 # 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
43 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
44 self.extra_files_path, self.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
45 self.mySpecieFolderPath, self.myTracksFolderPath, self.myBinaryFolderPath, self.trackType)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
46
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
47 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
48 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
49 self._createTrackList()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
50
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
51 self.myTrackStyle = TrackStyles(self.tool_directory, self.mySpecieFolderPath, 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
52 #self.cssFolderPath = os.path.join(self.mySpecieFolderPath, 'css')
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.cssFilePath = os.path.join(self.cssFolderPath, 'custom_track_styles.css')
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
54 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
55
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
56
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
57
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
58 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
59 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
60 #new_track = subprocess.Popen(['echo', trackDbObject['options']], stdout=subprocess.PIPE)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
61 #subprocess.call(['add-track-json.pl', json_file], stdin=new_track.stdout)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
62 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
63 #subtools.add_track_json(self.trackList, trackDbObject['track_json'])
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
64 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
65 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
66 else:
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
67 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
68 self._customizeHTMLFeature(trackDbObject)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
69 subtools.flatfile_to_json(trackDbObject['trackDataURL'], trackDbObject['dataType'], trackDbObject['trackType'], trackDbObject['trackLabel'], self.mySpecieFolderPath, 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
70
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
71
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
72 def terminate(self, debug=False):
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()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
75 if not debug:
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._makeArchive()
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
78 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
79 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
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
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
82 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
83 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
84 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
85 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
86 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
87 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
88 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
89 else:
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
90 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
91 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
92 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
93 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
94 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
95
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
96 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
97 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
98 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
99
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
100 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
101 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
102 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
103
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
104 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
105 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
106 #try:
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
107 #print os.path.join(self.tool_dir, 'prepare-refseqs.pl') + ", '--fasta', " + self.reference +", '--out', self.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
108 #subprocess.call(['prepare-refseqs.pl', '--fasta', self.reference_genome.false_path, '--out', 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
109 #except OSError as e:
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
110 #print "Cannot prepare reference error({0}): {1}".format(e.errno, e.strerror)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
111
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
112 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
113 #subprocess.call(['generate-names.pl', '-v', '--out', 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
114 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
115 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
116
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
117 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
118 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
119 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
120 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
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 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
123 htmlMakoRendered = htmlTemplate.render(
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
124 species_folder = os.path.relpath(self.mySpecieFolderPath, 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
125 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
126 )
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
127 htmlfile.write(htmlMakoRendered)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
128 #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
129 # htmlstr = 'The new Organism "%s" is created on Apollo: <br>' % self.genome_name
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
130 # jbrowse_hub = '<li><a href = "%s" target="_blank">View JBrowse Hub on Apollo</a></li>' % host_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 # htmlstr += jbrowse_hub
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
132 # htmlfile.write(htmlstr)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
133
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
134
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
135
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
136 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
137 # 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
138 # 2bit file creation from input fasta
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
139
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
140 # baseNameFasta = os.path.basename(fasta_file_name)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
141 # suffixTwoBit, extensionTwoBit = os.path.splitext(baseNameFasta)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
142 # nameTwoBit = suffixTwoBit + '.2bit'
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
143 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
144 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
145
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
146 # 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
147 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
148 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
149
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
150 # 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
151 self.chromSizesFile = tempfile.NamedTemporaryFile(bufsize=0, suffix=".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
152 subtools.sortChromSizes(twoBitInfoFile.name, self.chromSizesFile.name)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
153
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
154 # 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
155 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
156 # 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
157 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
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 # TODO: Manage to put every fill Function in a file dedicated for reading reasons
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
160 # Create the root directory
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
161 myHubPath = os.path.join(extra_files_path, "myHub")
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
162 if not os.path.exists(myHubPath):
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
163 os.makedirs(myHubPath)
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
164
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
165 # Create the specie folder
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
166 # TODO: Generate the name depending on the specie
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
167 mySpecieFolderPath = os.path.join(myHubPath, self.genome_name)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
168 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
169 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
170 self.mySpecieFolderPath = mySpecieFolderPath
0
804a93e87cc8 planemo upload for repository https://github.com/Yating-L/jbrowse_hub commit f22711ea7a464bdaf4d5aaea07f2eacf967aa66e-dirty
yating-l
parents:
diff changeset
171
6
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
172 # We create the 2bit file while we just created the specie folder
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
173 #self.twoBitName = self.genome_name + ".2bit"
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
174 #self.two_bit_final_path = os.path.join(self.mySpecieFolderPath, self.twoBitName)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
175 #shutil.copyfile(twoBitFile.name, self.two_bit_final_path)
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
176
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
177 # Create the folder tracks into the specie folder
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
178 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
179 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
180 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
181 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
182
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
183 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
184 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
185 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
186 self.myBinaryFolderPath = myBinaryFolderPath
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
187
237707a6b74d planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
yating-l
parents: 4
diff changeset
188 return myHubPath