comparison datatypes/Datatype.py @ 29:7e8a8b732db3 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1a81ebd0ddea950b84af3fc830e9267a4814b29f
author yating-l
date Wed, 16 May 2018 18:04:20 -0400
parents
children
comparison
equal deleted inserted replaced
28:6aa28a85cc38 29:7e8a8b732db3
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 import util
12 import logging
13 import abc
14 from abc import ABCMeta
15 from TrackDb import TrackDb
16 from datatypes.validators.DataValidation import DataValidation
17
18
19 class Datatype(object):
20 __metaclass__ = ABCMeta
21
22 twoBitFile = None
23 chromSizesFile = None
24 input_fasta_file = None
25 extra_files_path = None
26 tool_directory = None
27
28 mySpecieFolderPath = None
29 myTrackFolderPath = None
30
31
32 def __init__(self):
33 not_init_message = "The {0} is not initialized." \
34 "Did you use pre_init static method first?"
35 if Datatype.input_fasta_file is None:
36 raise TypeError(not_init_message.format('reference genome'))
37 if Datatype.extra_files_path is None:
38 raise TypeError(not_init_message.format('track Hub path'))
39 if Datatype.tool_directory is None:
40 raise TypeError(not_init_message.format('tool directory'))
41 self.inputFile = None
42 self.trackType = None
43 self.dataType = None
44 self.track = None
45 self.trackSettings = dict()
46 self.extraSettings = collections.OrderedDict()
47
48 @staticmethod
49 def pre_init(reference_genome, two_bit_path, chrom_sizes_file,
50 extra_files_path, tool_directory, specie_folder, tracks_folder):
51 Datatype.extra_files_path = extra_files_path
52 Datatype.tool_directory = tool_directory
53
54 # TODO: All this should be in TrackHub and not in Datatype
55 Datatype.mySpecieFolderPath = specie_folder
56 Datatype.myTrackFolderPath = tracks_folder
57
58 Datatype.input_fasta_file = reference_genome
59
60 # 2bit file creation from input fasta
61 Datatype.twoBitFile = two_bit_path
62 Datatype.chromSizesFile = chrom_sizes_file
63
64 def generateCustomTrack(self):
65 self.validateData()
66 self.initSettings()
67 #Create the track file
68 self.createTrack()
69 # Create the TrackDb Object
70 self.createTrackDb()
71 logging.debug("- %s %s created", self.dataType, self.trackName)
72
73
74 @abc.abstractmethod
75 def validateData(self):
76 """validate the input data with DataValidation"""
77
78 def initSettings(self):
79 #Initialize required fields: trackName, longLabel, shortLable
80 self.trackName = self.trackSettings["name"]
81 if self.trackSettings["long_label"]:
82 self.longLabel = self.trackSettings["long_label"]
83 else:
84 self.longLabel = self.trackName
85 if not "short_label" in self.trackSettings:
86 self.shortLabel = ""
87 else:
88 self.shortLabel = self.trackSettings["short_label"]
89 self.trackDataURL = os.path.join(self.myTrackFolderPath, self.trackName)
90
91
92 @abc.abstractmethod
93 def createTrack(self):
94 """Create the final track file"""
95
96 def createTrackDb(self):
97 self.track = TrackDb(self.trackName, self.longLabel, self.shortLabel, self.trackDataURL, self.trackType, self.extraSettings)
98