annotate datatypes/Datatype.py @ 3:fa990284327b draft default tip

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit ac73da32d59853ca563e7939d05016a6f3a6899e-dirty
author yating-l
date Mon, 30 Oct 2017 11:58:31 -0400
parents 85195e0d4b71
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
1 #!/usr/bin/python
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
2 # -*- coding: utf8 -*-
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
3
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
4 """
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
5 Super Class of the managed datatype
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
6 """
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
7
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
8 import os
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
9 import tempfile
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
10 import collections
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
11 import util
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
12 import logging
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
13 import abc
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
14 from abc import ABCMeta
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
15 from TrackDb import TrackDb
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
16 from datatypes.validators.DataValidation import DataValidation
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
17
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
18
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
19 class Datatype(object):
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
20 __metaclass__ = ABCMeta
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
21
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
22 twoBitFile = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
23 chromSizesFile = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
24 input_fasta_file = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
25 extra_files_path = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
26 tool_directory = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
27
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
28 mySpecieFolderPath = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
29 myTrackFolderPath = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
30
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
31
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
32 def __init__(self):
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
33 not_init_message = "The {0} is not initialized." \
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
34 "Did you use pre_init static method first?"
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
35 if Datatype.input_fasta_file is None:
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
36 raise TypeError(not_init_message.format('reference genome'))
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
37 if Datatype.extra_files_path is None:
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
38 raise TypeError(not_init_message.format('track Hub path'))
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
39 if Datatype.tool_directory is None:
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
40 raise TypeError(not_init_message.format('tool directory'))
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
41 self.inputFile = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
42 self.trackType = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
43 self.dataType = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
44 self.track = None
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
45 self.trackSettings = dict()
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
46 self.extraSettings = collections.OrderedDict()
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
47
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
48 @staticmethod
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
49 def pre_init(reference_genome, two_bit_path, chrom_sizes_file,
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
50 extra_files_path, tool_directory, specie_folder, tracks_folder):
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
51 Datatype.extra_files_path = extra_files_path
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
52 Datatype.tool_directory = tool_directory
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
53
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
54 # TODO: All this should be in TrackHub and not in Datatype
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
55 Datatype.mySpecieFolderPath = specie_folder
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
56 Datatype.myTrackFolderPath = tracks_folder
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
57
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
58 Datatype.input_fasta_file = reference_genome
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
59
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
60 # 2bit file creation from input fasta
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
61 Datatype.twoBitFile = two_bit_path
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
62 Datatype.chromSizesFile = chrom_sizes_file
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
63
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
64 def generateCustomTrack(self):
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
65 self.validateData()
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
66 self.initSettings()
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
67 #Create the track file
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
68 self.createTrack()
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
69 # Create the TrackDb Object
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
70 self.createTrackDb()
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
71 logging.debug("- %s %s created", self.dataType, self.trackName)
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
72
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
73
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
74 @abc.abstractmethod
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
75 def validateData(self):
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
76 """validate the input data with DataValidation"""
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
77
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
78 def initSettings(self):
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
79 #Initialize required fields: trackName, longLabel, shortLable
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
80 self.trackName = self.trackSettings["name"]
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
81 if self.trackSettings["long_label"]:
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
82 self.longLabel = self.trackSettings["long_label"]
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
83 else:
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
84 self.longLabel = self.trackName
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
85 if not "short_label" in self.trackSettings:
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
86 self.shortLabel = ""
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
87 else:
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
88 self.shortLabel = self.trackSettings["short_label"]
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
89 self.trackDataURL = os.path.join(self.myTrackFolderPath, self.trackName)
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
90
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
91
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
92 @abc.abstractmethod
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
93 def createTrack(self):
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
94 """Create the final track file"""
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
95
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
96 def createTrackDb(self):
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
97 self.track = TrackDb(self.trackName, self.longLabel, self.shortLabel, self.trackDataURL, self.trackType, self.extraSettings)
85195e0d4b71 planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit b1ae7349f118a0fe7923d765020dfc684cf84116-dirty
yating-l
parents:
diff changeset
98