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