comparison Datatype.py @ 10:acc233161f50 draft

planemo upload for repository https://github.com/goeckslab/hub-archive-creator commit 1b1063f90004764bcf504f4340738eca5c4b1f9d
author rmarenco
date Thu, 21 Jul 2016 05:58:51 -0400
parents 816956489fe9
children d05236b15f81
comparison
equal deleted inserted replaced
9:4f9847539a28 10:acc233161f50
4 """ 4 """
5 Super Class of the managed datatype 5 Super Class of the managed datatype
6 """ 6 """
7 7
8 import os 8 import os
9 import tempfile
9 10
10 from util import subtools 11 from util import subtools
11 12
12 13
13 class Datatype(object): 14 class Datatype(object):
14 15
15 twoBitFile = None 16 twoBitFile = None
16 17
17 def __init__( self, input_fasta_file, extra_files_path, tool_directory ): 18 input_fasta_file = None
19 extra_files_path = None
20 tool_directory = None
18 21
19 self.input_fasta_file = input_fasta_file 22 mySpecieFolderPath = None
20 self.extra_files_path = extra_files_path 23 myTrackFolderPath = None
21 self.tool_directory = tool_directory
22 24
23 self.twoBitFile = None 25 twoBitFile = None
26 chromSizesFile = None
24 27
25 # Construction of the arborescence 28 def __init__(self):
26 # TODO: Change the hard-coded path with a input based one
27 self.mySpecieFolderPath = os.path.join(extra_files_path, "myHub", "dbia3")
28 29
29 # TODO: Refactor the name of the folder "tracks" into one variable, and should be inside TrackHub object 30 not_init_message = "The {0} is not initialized." \
30 self.myTrackFolderPath = os.path.join(self.mySpecieFolderPath, "tracks") 31 "Did you use pre_init static method first?"
32 if Datatype.input_fasta_file is None:
33 raise TypeError(not_init_message.format('reference genome'))
34 if Datatype.extra_files_path is None:
35 raise TypeError(not_init_message.format('track Hub path'))
36 if Datatype.tool_directory is None:
37 raise TypeError(not_init_message.format('tool directory'))
31 38
32 # TODO: Redundant, should be refactored because they are all doing it...into hubArchiveCreator? 39
40 @staticmethod
41 def pre_init(reference_genome, two_bit_path, chrom_sizes_file,
42 extra_files_path, tool_directory, specie_folder, tracks_folder):
43 Datatype.extra_files_path = extra_files_path
44 Datatype.tool_directory = tool_directory
45
46 # TODO: All this should be in TrackHub and not in Datatype
47 Datatype.mySpecieFolderPath = specie_folder
48 Datatype.myTrackFolderPath = tracks_folder
49
50 Datatype.input_fasta_file = reference_genome
51
33 # 2bit file creation from input fasta 52 # 2bit file creation from input fasta
34 if not Datatype.twoBitFile: 53 Datatype.twoBitFile = two_bit_path
35 print "We create the self.twoBit in " + self.__class__.__name__ 54 Datatype.chromSizesFile = chrom_sizes_file
36 Datatype.twoBitFile = subtools.faToTwoBit(self.input_fasta_file, self.mySpecieFolderPath)
37 55
38 # TODO: Remove this by saying to all children classes to use "Datatype.twoBitFile" instead 56 @staticmethod
39 self.twoBitFile = Datatype.twoBitFile 57 def get_largest_scaffold_name(self):
58 # We can get the biggest scaffold here, with chromSizesFile
59 with open(Datatype.chromSizesFile.name, 'r') as chrom_sizes:
60 # TODO: Check if exists
61 return chrom_sizes.readline().split()[0]
40 62
63 # TODO: Rename for PEP8
41 def getShortName( self, name_to_shortify ): 64 def getShortName( self, name_to_shortify ):
42 # Slice to get from Long label the short label 65 # Slice to get from Long label the short label
43 short_label_slice = slice(0, 15) 66 short_label_slice = slice(0, 15)
44 67
45 return name_to_shortify[short_label_slice] 68 return name_to_shortify[short_label_slice]