Mercurial > repos > rmarenco > hubarchivecreator
comparison util/Reader.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 | e7c4be523cb7 |
comparison
equal
deleted
inserted
replaced
28:6aa28a85cc38 | 29:7e8a8b732db3 |
---|---|
1 import json | |
2 import logging | |
3 import codecs | |
4 | |
5 | |
6 # Internal dependencies | |
7 from datatypes.binary.Bam import Bam | |
8 from datatypes.binary.BigWig import BigWig | |
9 from datatypes.binary.BigBed import BigBed | |
10 from datatypes.interval.Bed import Bed | |
11 from datatypes.interval.BedSimpleRepeats import BedSimpleRepeats | |
12 from datatypes.interval.BedSpliceJunctions import BedSpliceJunctions | |
13 from datatypes.interval.CytoBand import CytoBand | |
14 from datatypes.interval.BedBlatAlignments import BedBlatAlignments | |
15 from datatypes.interval.BedBlastAlignments import BedBlastAlignments | |
16 from datatypes.interval.Gff3 import Gff3 | |
17 from datatypes.interval.Gtf import Gtf | |
18 from datatypes.interval.Psl import Psl | |
19 from datatypes.sequence.Fasta import Fasta | |
20 from util import santitizer | |
21 | |
22 class Reader(object): | |
23 | |
24 DATATYPE_CLASS = [Bam, BigWig, BigBed, Bed, BedSimpleRepeats, BedSpliceJunctions, CytoBand, BedBlatAlignments, BedBlastAlignments, Gff3, Gtf, Psl, Fasta] | |
25 | |
26 def __init__(self, input_json_file): | |
27 self.inputFile = input_json_file | |
28 self.args = self.loadJson() | |
29 | |
30 | |
31 def loadJson(self): | |
32 try: | |
33 data_file = codecs.open(self.inputFile, 'r', 'utf-8') | |
34 return json.load(data_file) | |
35 except IOError: | |
36 print "Cannot find JSON file\n" | |
37 exit(1) | |
38 | |
39 def getToolDir(self): | |
40 try: | |
41 return self.args["tool_directory"] | |
42 except KeyError: | |
43 print ("tool_directory is not defined in the input file!") | |
44 exit(1) | |
45 | |
46 def getExtFilesPath(self): | |
47 try: | |
48 return self.args["extra_files_path"] | |
49 except KeyError: | |
50 print ("extra_files_path is not defined in the input file!") | |
51 exit(1) | |
52 | |
53 def getUserEmail(self): | |
54 try: | |
55 return self.args["user_email"] | |
56 except KeyError: | |
57 print ("user_email is not defined in the input file!") | |
58 exit(1) | |
59 | |
60 def getDebugMode(self): | |
61 try: | |
62 return self.args["debug_mode"] | |
63 except KeyError: | |
64 print ("debug_mode is not defined in the input file!") | |
65 exit(1) | |
66 | |
67 | |
68 def getRefGenome(self): | |
69 array_inputs_reference_genome = self.args["fasta"] | |
70 # TODO: Replace these with the object Fasta | |
71 input_fasta_file = array_inputs_reference_genome["false_path"] | |
72 input_fasta_file_name = santitizer.sanitize_name_input(array_inputs_reference_genome["name"]) | |
73 genome_name = santitizer.sanitize_name_input(self.args["genome_name"]) | |
74 reference_genome = Fasta(input_fasta_file, | |
75 input_fasta_file_name, genome_name) | |
76 return reference_genome | |
77 | |
78 | |
79 def getTracksData(self): | |
80 self.logger = logging.getLogger(__name__) | |
81 all_datatype_dictionary = dict() | |
82 for datatype in self.DATATYPE_CLASS: | |
83 class_name = datatype.__name__ | |
84 array_inputs = self.args.get(str(class_name)) | |
85 if array_inputs: | |
86 self.logger.debug("Create %s objects\n", class_name) | |
87 self.logger.debug("array_inputs: %s", array_inputs) | |
88 all_datatype_dictionary.update(self.create_ordered_datatype_objects(datatype, array_inputs)) | |
89 | |
90 return all_datatype_dictionary | |
91 | |
92 def create_ordered_datatype_objects(self, ExtensionClass, array_inputs): | |
93 """ | |
94 Function which executes the creation all the necessary files / folders for a special Datatype, for TrackHub | |
95 and update the dictionary of datatype | |
96 | |
97 :param ExtensionClass: | |
98 :param array_inputs: | |
99 :type ExtensionClass: Datatype | |
100 :type array_inputs: list[string] | |
101 """ | |
102 | |
103 datatype_dictionary = {} | |
104 | |
105 # TODO: Optimize this double loop | |
106 for input_data in array_inputs: | |
107 input_false_path = input_data["false_path"] | |
108 input_data["name"] = santitizer.sanitize_name_input(input_data["name"]) | |
109 extensionObject = ExtensionClass(input_false_path, input_data) | |
110 extensionObject.generateCustomTrack() | |
111 datatype_dictionary.update({input_data["order_index"]: extensionObject}) | |
112 return datatype_dictionary | |
113 | |
114 | |
115 | |
116 | |
117 |