Mercurial > repos > yating-l > jbrowsearchivecreator
comparison util/Reader.py @ 6:237707a6b74d draft
planemo upload for repository https://github.com/Yating-L/jbrowse-archive-creator.git commit a500f7ab2119cc5faaf80393bd87428389d06880-dirty
author | yating-l |
---|---|
date | Thu, 15 Feb 2018 17:05:05 -0500 |
parents | |
children | 5d5fdcb798da |
comparison
equal
deleted
inserted
replaced
5:e762f4b9e4bd | 6:237707a6b74d |
---|---|
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.interval.Bed import Bed | |
10 from datatypes.interval.BedSimpleRepeats import BedSimpleRepeats | |
11 from datatypes.interval.BedSpliceJunctions import BedSpliceJunctions | |
12 from datatypes.interval.BlastXml import BlastXml | |
13 from datatypes.interval.Gff3 import Gff3 | |
14 from datatypes.interval.Gtf import Gtf | |
15 from datatypes.interval.BigPsl import BigPsl | |
16 from datatypes.interval.BedBlatAlignments import BedBlatAlignments | |
17 from datatypes.interval.BedBlastAlignments import BedBlastAlignments | |
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, Bed, BedSimpleRepeats, | |
25 BedSpliceJunctions, BigPsl, BedBlatAlignments, BedBlastAlignments, | |
26 BlastXml, Gff3, Gtf, Psl, Fasta] | |
27 | |
28 def __init__(self, input_json_file): | |
29 self.inputFile = input_json_file | |
30 self.args = self.loadJson() | |
31 | |
32 | |
33 def loadJson(self): | |
34 try: | |
35 data_file = codecs.open(self.inputFile, 'r', 'utf-8') | |
36 return json.load(data_file) | |
37 except IOError: | |
38 print "Cannot find JSON file\n" | |
39 exit(1) | |
40 | |
41 def getToolDir(self): | |
42 try: | |
43 return self.args["tool_directory"] | |
44 except KeyError: | |
45 print ("tool_directory is not defined in the input file!") | |
46 exit(1) | |
47 | |
48 def getExtFilesPath(self): | |
49 try: | |
50 return self.args["extra_files_path"] | |
51 except KeyError: | |
52 print ("extra_files_path is not defined in the input file!") | |
53 exit(1) | |
54 | |
55 def getUserEmail(self): | |
56 try: | |
57 return self.args["user_email"] | |
58 except KeyError: | |
59 print ("user_email is not defined in the input file!") | |
60 exit(1) | |
61 | |
62 def getDebugMode(self): | |
63 try: | |
64 return self.args["debug_mode"] | |
65 except KeyError: | |
66 print ("debug_mode is not defined in the input file!") | |
67 exit(1) | |
68 | |
69 def getTrackType(self): | |
70 track_type = self.args.get("track_type") | |
71 return track_type | |
72 | |
73 def getGenomeName(self): | |
74 genome_name = santitizer.sanitize_name_input(self.args["genome_name"]) | |
75 return genome_name | |
76 | |
77 def getRefGenome(self): | |
78 array_inputs_reference_genome = self.args["fasta"] | |
79 # TODO: Replace these with the object Fasta | |
80 input_fasta_file = array_inputs_reference_genome["false_path"] | |
81 input_fasta_file_name = santitizer.sanitize_name_input(array_inputs_reference_genome["name"]) | |
82 #genome_name = santitizer.sanitize_name_input(self.args["genome_name"]) | |
83 genome_name = self.getGenomeName() | |
84 reference_genome = Fasta(input_fasta_file, | |
85 input_fasta_file_name, genome_name) | |
86 return reference_genome | |
87 | |
88 def getTracksData(self): | |
89 self.logger = logging.getLogger(__name__) | |
90 all_datatype_dictionary = dict() | |
91 for datatype in self.DATATYPE_CLASS: | |
92 class_name = datatype.__name__ | |
93 array_inputs = self.args.get(str(class_name)) | |
94 if array_inputs: | |
95 self.logger.debug("Creating %s objects\n", class_name) | |
96 self.logger.debug("array_inputs: %s", array_inputs) | |
97 all_datatype_dictionary.update(self.create_ordered_datatype_objects(datatype, array_inputs)) | |
98 | |
99 return all_datatype_dictionary | |
100 | |
101 def create_ordered_datatype_objects(self, ExtensionClass, array_inputs): | |
102 """ | |
103 Function which executes the creation all the necessary files / folders for a special Datatype, for TrackHub | |
104 and update the dictionary of datatype | |
105 | |
106 :param ExtensionClass: | |
107 :param array_inputs: | |
108 :type ExtensionClass: Datatype | |
109 :type array_inputs: list[string] | |
110 """ | |
111 | |
112 datatype_dictionary = {} | |
113 | |
114 # TODO: Optimize this double loop | |
115 for input_data in array_inputs: | |
116 input_false_path = input_data["false_path"] | |
117 input_data["name"] = santitizer.sanitize_name_input(input_data["name"]) | |
118 extensionObject = ExtensionClass(input_false_path, input_data) | |
119 extensionObject.generateCustomTrack() | |
120 datatype_dictionary.update({input_data["order_index"]: extensionObject}) | |
121 self.logger.debug("%s object: %s has been created", ExtensionClass, input_data["name"]) | |
122 return datatype_dictionary | |
123 | |
124 | |
125 | |
126 | |
127 |