diff 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
line wrap: on
line diff
--- a/Datatype.py	Wed Jul 20 12:29:08 2016 -0400
+++ b/Datatype.py	Thu Jul 21 05:58:51 2016 -0400
@@ -6,6 +6,7 @@
 """
 
 import os
+import tempfile
 
 from util import subtools
 
@@ -14,32 +15,54 @@
 
     twoBitFile = None
 
-    def __init__( self, input_fasta_file, extra_files_path, tool_directory ):
+    input_fasta_file = None
+    extra_files_path = None
+    tool_directory = None
 
-        self.input_fasta_file = input_fasta_file
-        self.extra_files_path = extra_files_path
-        self.tool_directory = tool_directory
+    mySpecieFolderPath = None
+    myTrackFolderPath = None
+
+    twoBitFile = None
+    chromSizesFile = None
 
-        self.twoBitFile = None
+    def __init__(self):
 
-        # Construction of the arborescence
-        # TODO: Change the hard-coded path with a input based one
-        self.mySpecieFolderPath = os.path.join(extra_files_path, "myHub", "dbia3")
+        not_init_message = "The {0} is not initialized." \
+                           "Did you use pre_init static method first?"
+        if Datatype.input_fasta_file is None:
+            raise TypeError(not_init_message.format('reference genome'))
+        if Datatype.extra_files_path is None:
+            raise TypeError(not_init_message.format('track Hub path'))
+        if Datatype.tool_directory is None:
+            raise TypeError(not_init_message.format('tool directory'))
+
 
-        # TODO: Refactor the name of the folder "tracks" into one variable, and should be inside TrackHub object
-        self.myTrackFolderPath = os.path.join(self.mySpecieFolderPath, "tracks")
+    @staticmethod
+    def pre_init(reference_genome, two_bit_path, chrom_sizes_file,
+                 extra_files_path, tool_directory, specie_folder, tracks_folder):
+        Datatype.extra_files_path = extra_files_path
+        Datatype.tool_directory = tool_directory
 
-        # TODO: Redundant, should be refactored because they are all doing it...into hubArchiveCreator?
+        # TODO: All this should be in TrackHub and not in Datatype
+        Datatype.mySpecieFolderPath = specie_folder
+        Datatype.myTrackFolderPath = tracks_folder
+
+        Datatype.input_fasta_file = reference_genome
+
         # 2bit file creation from input fasta
-        if not Datatype.twoBitFile:
-            print "We create the self.twoBit in " + self.__class__.__name__
-            Datatype.twoBitFile = subtools.faToTwoBit(self.input_fasta_file, self.mySpecieFolderPath)
+        Datatype.twoBitFile = two_bit_path
+        Datatype.chromSizesFile = chrom_sizes_file
 
-        # TODO: Remove this by saying to all children classes to use "Datatype.twoBitFile" instead
-        self.twoBitFile = Datatype.twoBitFile
+    @staticmethod
+    def get_largest_scaffold_name(self):
+        # We can get the biggest scaffold here, with chromSizesFile
+        with open(Datatype.chromSizesFile.name, 'r') as chrom_sizes:
+            # TODO: Check if exists
+            return chrom_sizes.readline().split()[0]
 
+    # TODO: Rename for PEP8
     def getShortName( self, name_to_shortify ):
         # Slice to get from Long label the short label
         short_label_slice = slice(0, 15)
 
-        return name_to_shortify[short_label_slice]
\ No newline at end of file
+        return name_to_shortify[short_label_slice]