annotate datatypes/Datatype.py @ 83:0bc486356e2a draft

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