Mercurial > repos > yating-l > jbrowsearchivecreator
comparison datatypes/Datatype.py @ 25:31a41ce128cc draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit 691e5366893905d30943a3cb8cdfb6341f0f5362-dirty
author | yating-l |
---|---|
date | Fri, 13 Oct 2017 12:44:31 -0400 |
parents | |
children | d17f629f5486 |
comparison
equal
deleted
inserted
replaced
24:bb6fdccef474 | 25:31a41ce128cc |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf8 -*- | |
3 | |
4 """ | |
5 Super Class of the managed datatype | |
6 """ | |
7 | |
8 import os | |
9 import tempfile | |
10 import collections | |
11 from util import subtools | |
12 import logging | |
13 import abc | |
14 from abc import ABCMeta | |
15 from tracks.HTMLFeatures import HTMLFeatures | |
16 from tracks.CanvasFeatures import CanvasFeatures | |
17 from tracks.BamFeatures import BamFeatures | |
18 from tracks.BigwigFeatures import BigwigFeatures | |
19 from datatypes.validators.DataValidation import DataValidation | |
20 | |
21 | |
22 class Datatype(object): | |
23 __metaclass__ = ABCMeta | |
24 | |
25 chromSizesFile = None | |
26 input_fasta_file = None | |
27 extra_files_path = None | |
28 tool_directory = None | |
29 | |
30 mySpecieFolderPath = None | |
31 myTrackFolderPath = None | |
32 myBinaryFolderPath = None | |
33 | |
34 trackType = None | |
35 | |
36 def __init__(self): | |
37 not_init_message = "The {0} is not initialized." \ | |
38 "Did you use pre_init static method first?" | |
39 if Datatype.input_fasta_file is None: | |
40 raise TypeError(not_init_message.format('reference genome')) | |
41 if Datatype.extra_files_path is None: | |
42 raise TypeError(not_init_message.format('track Hub path')) | |
43 if Datatype.tool_directory is None: | |
44 raise TypeError(not_init_message.format('tool directory')) | |
45 self.inputFile = None | |
46 self.trackType = None | |
47 self.dataType = None | |
48 self.trackFileType = None | |
49 self.track = None | |
50 self.trackSettings = dict() | |
51 self.extraSettings = collections.OrderedDict() | |
52 | |
53 | |
54 @staticmethod | |
55 def pre_init(reference_genome, chrom_sizes_file, | |
56 extra_files_path, tool_directory, specie_folder, tracks_folder, binary_folder, track_type): | |
57 Datatype.extra_files_path = extra_files_path | |
58 Datatype.tool_directory = tool_directory | |
59 | |
60 # TODO: All this should be in TrackHub and not in Datatype | |
61 Datatype.mySpecieFolderPath = specie_folder | |
62 Datatype.myTrackFolderPath = tracks_folder | |
63 Datatype.myBinaryFolderPath = binary_folder | |
64 | |
65 Datatype.input_fasta_file = reference_genome | |
66 | |
67 # 2bit file creation from input fasta | |
68 #Datatype.twoBitFile = two_bit_path | |
69 Datatype.chromSizesFile = chrom_sizes_file | |
70 Datatype.trackType = track_type | |
71 | |
72 | |
73 def generateCustomTrack(self): | |
74 self.validateData() | |
75 self.initSettings() | |
76 #Create the track file | |
77 self.createTrack() | |
78 # Create the TrackDb Object | |
79 self.createTrackDb() | |
80 logging.debug("- %s %s created", self.dataType, self.trackName) | |
81 | |
82 | |
83 @abc.abstractmethod | |
84 def validateData(self): | |
85 """validate the input data with DataValidation""" | |
86 | |
87 def initSettings(self): | |
88 #Initialize required fields: trackName, longLabel, shortLable | |
89 self.trackName = self.trackSettings["name"] | |
90 self.trackDataURL = os.path.join(self.myTrackFolderPath, self.trackName) | |
91 if self.trackSettings["long_label"]: | |
92 self.trackLabel = self.trackSettings["long_label"] | |
93 else: | |
94 self.trackLabel = self.trackName | |
95 if "trackType" in self.trackSettings and self.trackSettings["trackType"]: | |
96 self.trackType = self.trackSettings["trackType"] | |
97 if self.trackSettings["group_name"]: | |
98 self.extraSettings["category"] = self.trackSettings["group_name"] | |
99 if "track_color" in self.trackSettings and self.trackSettings["track_color"]: | |
100 self.extraSettings["color"] = self.trackSettings["track_color"] | |
101 | |
102 | |
103 @abc.abstractmethod | |
104 def createTrack(self): | |
105 """Create the final track file""" | |
106 | |
107 def createTrackDb(self): | |
108 if self.trackType == 'HTMLFeatures': | |
109 self.track = HTMLFeatures(self.trackName, self.trackLabel, self.trackDataURL, self.trackType, self.dataType, self.extraSettings) | |
110 elif self.trackType == "CanvasFeatures": | |
111 self.track = CanvasFeatures(self.trackName, self.trackLabel, self.trackDataURL, self.trackType, self.dataType, self.extraSettings) | |
112 elif self.trackType == "bam": | |
113 self.track = BamFeatures(self.trackName, self.trackLabel, self.trackDataURL, self.trackType, self.dataType, self.extraSettings) | |
114 elif self.trackType == "bigwig": | |
115 self.track = BigwigFeatures(self.trackName, self.trackLabel, self.trackDataURL, self.trackType, self.dataType, self.extraSettings) | |
116 else: | |
117 logging.error("Cannot createTrackDb, because trackType is not defined or invalid! trackType = %s", self.trackType) | |
118 self.track.createTrackDb() | |
119 | |
120 #self.track = TrackDb(self.trackName, self.trackLabel, self.trackDataURL, self.trackType, self.dataType, self.extraSettings) | |
121 | |
122 |