Esempio n. 1
0
    def sort_by_tree(self):
        tree_filename = tkFileDialog.askopenfilename(initialdir = self.host.settings.work_dir, filetypes = (("Inkscape vector file", "*.svg"), ))
        if tree_filename == "": # Cancel
            return
        old_order_seqs = Aln_basic.read_fasta_from_strings(self.fixed.get_strings())

        sort_and_color_path = os.path.join(self.host.settings.script_dir, "sort_and_color.py")
        fixed_filename = os.path.join(self.host.settings.work_dir, "%s.fixed" % self.host.temp_name)
        Aln_basic.write_widget_into_file(self.fixed.text_widget, fixed_filename)

        if self.host.verbose.get():
            os.system("%s -i %s -w %s -o %s -t %s" % (sort_and_color_path, os.path.basename(fixed_filename), self.host.settings.work_dir, 
                                                      self.host.temp_name, tree_filename))
        else:
            os.system("%s -i %s -w %s -o %s -t %s 1> nul 2> nul" % (sort_and_color_path, os.path.basename(fixed_filename), 
                                                                    self.host.settings.work_dir, self.host.temp_name, tree_filename))

        temp_sorted_filename = os.path.join(self.host.settings.work_dir, "%s.tree_sorted" % self.host.temp_name)
        Aln_basic.read_widget_from_file(self.fixed.text_widget, temp_sorted_filename)
                
        self.IDs.text_widget.delete(1.0, tkinter.END)
        new_order_seqs = Aln_basic.read_fasta_from_strings(self.fixed.get_strings())
        new_ids = ""
        for s in new_order_seqs:
            new_ids += "%s\n" % s.ID            
        self.IDs.text_widget.insert(tkinter.END, new_ids)

        print ("    Alignment was sorted according to the %s tree file!" % tree_filename)
        self.host.log_tab.write_to_log("Alignment was sorted according to the tree file:\n%s" % tree_filename, True)
        if len(new_order_seqs) != len(old_order_seqs):
            print ("    Number of sequences reduced from %i to %i! Possibly IDs in the tree file was interpreted badly" % (len(old_order_seqs), len(new_order_seqs)))
            self.host.set_status("Number of sequences reduced from %i to %i!" % (len(old_order_seqs), len(new_order_seqs)))
Esempio n. 2
0
    def obtain_features(self):
        print("    Obtaining features...")
        curr_mode = self.feature_mode.get()
        domain_filename = os.path.join(self.host.settings.work_dir,
                                       "%s.domain_table" % self.host.temp_name)
        domain_not_empty = None
        if curr_mode == "COG":
            domain_not_empty = Aln_basic.write_widget_into_file(
                self.hmmresults_COG.text_widget, domain_filename)
        else:
            domain_not_empty = Aln_basic.write_widget_into_file(
                self.hmmresults_Pfam.text_widget, domain_filename)
        fixed_filename = os.path.join(self.host.settings.work_dir,
                                      "%s.fixed" % self.host.temp_name)
        dom_filename = "%s.domain_info" % self.host.temp_name
        Aln_basic.write_widget_into_file(self.host.parse_tab.fixed.text_widget,
                                         fixed_filename)

        obtain_features_path = os.path.join(self.host.settings.script_dir,
                                            "obtain_features.py")

        data_for_features = ""
        if domain_not_empty:
            data_for_features += "-p %s" % os.path.basename(domain_filename)
        if not self.TMHMM_results.text_is_empty():
            TM_filename = os.path.join(self.host.settings.work_dir,
                                       "%s.TMHMM" % self.host.temp_name)
            Aln_basic.write_widget_into_file(self.TMHMM_results.text_widget,
                                             TM_filename)
            data_for_features += " -t %s" % os.path.basename(TM_filename)
        self.host.set_status("Working")
        if self.host.verbose.get():
            os.system("%s -i %s -w %s -o %s %s -e %s -f %s -d %s" %
                      (obtain_features_path, os.path.basename(fixed_filename),
                       self.host.settings.work_dir,
                       "%s.features" % self.host.temp_name, data_for_features,
                       self.evalue_threshold.get(),
                       self.overlap_threshold.get(), dom_filename))
        else:
            os.system(
                "%s -i %s -w %s -o %s %s -e %s -f %s -d %s 1> nul 2> nul" %
                (obtain_features_path, os.path.basename(fixed_filename),
                 self.host.settings.work_dir,
                 "%s.features" % self.host.temp_name, data_for_features,
                 self.evalue_threshold.get(), self.overlap_threshold.get(),
                 dom_filename))
        self.host.set_status("Ready")
        Aln_basic.read_widget_from_file(
            self.features.text_widget,
            os.path.join(self.host.settings.work_dir,
                         "%s.features" % self.host.temp_name))

        dom_filename_full = os.path.join(self.host.settings.work_dir,
                                         dom_filename)
        if os.path.isfile(
                dom_filename_full):  # File was created (non-empty domains)
            domain_dict = Aln_basic.read_domain_info_file(dom_filename_full)
            self.host.load_domain_info(
                domain_dict)  # Loading domain info into the info tab
        print("    [..DONE..]")
Esempio n. 3
0
    def align(self):        
        if self.seq_input_frame.text_is_empty(): # No sequences were provided
            self.host.set_status("No sequences were provided to align!", "#FF0000")
            return
        print ("    Alignment construction started...")
        (muscle_name, muscle_path) = Settings.get_program_name(self.host.settings.muscle_dir, "muscle")
        unaligned_filename = os.path.join(self.host.settings.work_dir, "%s.fasta" % self.host.temp_name)
        Aln_basic.write_widget_into_file(self.seq_input_frame.text_widget, unaligned_filename)
        aligned_filename = os.path.join(self.host.settings.work_dir, "%s.aln" % self.host.temp_name)

        self.host.set_status("Alignment")
        maxiters_option = ""
        if self.maxiters.get() != "":
            try:
                maxiters_option = "-maxiters %i" % int(self.maxiters.get())
            except TypeError:
                print ("Option -maxiters is not an integer and is ignored!")
        gapopen_option = ""
        if self.gapopen.get() != "":
            if Aln_basic.is_negative_float(self.gapopen.get(), "-gapopen"):
                gapopen_option = "-gapopen %s" % self.gapopen.get()
        gapextend_option = ""
        if self.gapextend.get() != "":
            if Aln_basic.is_negative_float(self.gapextend.get(), "-gapextend"):
                gapextend_option = "-gapextend %s" % self.gapextend.get()
        muscle_command = "%s -in %s -out %s %s %s %s" % (muscle_path, unaligned_filename, aligned_filename, maxiters_option, gapopen_option, gapextend_option)
        print ("Muscle command to be ran:")
        print (muscle_command)        
        if self.host.verbose.get():                     
            os.system(muscle_command)
        else:
            os.system("%s 1> nul 2> nul" % muscle_command)

        Aln_basic.read_widget_from_file(self.aln_input_frame.text_widget, aligned_filename)
        if self.insert_blocks.get(): # Empty sequence >BLOCKS should be added
            curr_seqs = Aln_basic.read_fasta_from_strings(self.aln_input_frame.get_strings())
            self.aln_input_frame.text_widget.delete(1.0, tkinter.END)
            upd_aln_file = open(aligned_filename, "w")            
            upd_aln_file.write(">BLOCKS\n")
            upd_aln_file.write("%s\n\n" % ("-" * len(curr_seqs[0].sequence)))
            upd_aln_file.write(">SITE\n")
            upd_aln_file.write("%s\n\n" % ("-" * len(curr_seqs[0].sequence)))
            for s in curr_seqs:
                s.print_fasta(upd_aln_file, 60)
            upd_aln_file.close()
            Aln_basic.read_widget_from_file(self.aln_input_frame.text_widget, aligned_filename)            
                    
        self.host.set_status("Ready")

        os.remove(unaligned_filename)
        os.remove(aligned_filename)
        print ("    [..DONE..]")
Esempio n. 4
0
    def check_pending(self):
        files_ready = list()
        i = 0
        while i < len(self.pending_filenames):
            filename = self.pending_filenames[i]
            if os.path.isfile(filename):
                if os.path.getctime(filename) != os.path.getmtime(filename):
                    files_ready.append(filename)
                    self.pending_filenames.pop(i)
                    i -= 1
            i += 1
        if len(self.pending_filenames) == 0:
            self.disable_check_button()

        ready_and_required = list()
        for curr_file in files_ready:
            base_name = os.path.basename(curr_file)
            name_parts = base_name.split(".")
            if len(
                    name_parts
            ) != 2:  # Files without extension or with multiple dots are not considered
                continue
            project_name = name_parts[0]
            extension = name_parts[1]
            if project_name == self.get_project_name():
                if extension == "Pfam_table":
                    Aln_basic.read_widget_from_file(
                        self.features_tab.hmmresults_Pfam.text_widget,
                        curr_file)
                    ready_and_required.append(extension)
                if extension == "COG_table":
                    Aln_basic.read_widget_from_file(
                        self.features_tab.hmmresults_COG.text_widget,
                        curr_file)
                    ready_and_required.append(extension)
                if extension == "TMHMM":
                    Aln_basic.read_widget_from_file(
                        self.features_tab.TMHMM_results.text_widget, curr_file)
                    ready_and_required.append(extension)

        if len(ready_and_required) == 0:  # No files are ready
            self.set_status("Sorry, no file delivered!")
        else:
            self.set_status("These files were ready and loaded: %s" %
                            ",".join(ready_and_required))
Esempio n. 5
0
    def load_project(self):
        project_dir = os.path.join(self.settings.work_dir,
                                   self.get_project_name())
        if self.get_project_name() == "":  # No project name was entered
            project_dir = tkFileDialog.askdirectory(
                initialdir=self.settings.work_dir,
                title="Please select a folder with the project:")
            if project_dir == "":  # Cancel
                return
        if not os.path.isdir(project_dir):
            self.set_status(
                "This project does not exist, please check its name again!",
                "#FF0000")
            return
        #answer = tkMessageBox.askyesno("Please confirm loading", "Are you sure you want to load %s project? All existing data in the frames, if any, will be re-writed!" % self.get_project_name())
        #if answer != True:
        #   return
        self.clear_all()
        self.project_title_widget.insert(tkinter.END,
                                         os.path.basename(project_dir))

        self.set_status("Working")
        print("-------- Project %s is now loading! --------" %
              self.get_project_name())

        project_files = os.listdir(project_dir)
        extension_to_widget = {
            "aln": self.input_tab.aln_input_frame.text_widget,
            "sample": self.input_tab.seq_input_frame.text_widget,
            "fixed": self.parse_tab.fixed.text_widget,
            "pure": self.parse_tab.pure.text_widget,
            "blocks_regions": self.parse_tab.blocks.text_widget,
            "ids": self.parse_tab.IDs.text_widget,
            "COG_table": self.features_tab.hmmresults_COG.text_widget,
            "Pfam_table": self.features_tab.hmmresults_Pfam.text_widget,
            "TMHMM": self.features_tab.TMHMM_results.text_widget,
            #"features"       : self.features_tab.features.text_widget, #FIX: version 0.2.8 (features should not be loaded)
            "auto_log": self.log_tab.auto_log.text_widget,
            "man_log": self.log_tab.manual_log.text_widget
        }

        for curr_file in project_files:
            name_parts = curr_file.split(".")
            if len(
                    name_parts
            ) != 2:  # Files without extension or with multiple dots are not considered
                continue
            project_name = name_parts[0]
            extension = name_parts[1]
            full_filename = os.path.join(project_dir, curr_file)
            if project_name == self.get_project_name():
                if extension in extension_to_widget:
                    Aln_basic.read_widget_from_file(
                        extension_to_widget[extension], full_filename)
                if extension == "pure":
                    self.parse_tab.enable_pure_analysis()
                if extension == "actions":
                    self.purify_tab.load_actions(full_filename)
                if extension == "colors":
                    self.load_colors_from_file(full_filename)

        self.parse_tab.check_numbers()
        self.log_tab.color_important()
        self.set_status("Ready")
Esempio n. 6
0
    def parse(self):
        aligned_filename = os.path.join(self.settings.work_dir,
                                        "%s.aln" % self.temp_name)
        Aln_basic.write_widget_into_file(
            self.input_tab.aln_input_frame.text_widget, aligned_filename)
        remove_seq_limits_path = os.path.join(self.settings.script_dir,
                                              "remove_seq_limits.py")

        self.set_status("Working")
        if self.verbose.get():
            os.system("%s -i %s -w %s -o %s -d -x" %
                      (remove_seq_limits_path, "%s.aln" % self.temp_name,
                       self.settings.work_dir, self.temp_name))
        else:
            os.system("%s -i %s -w %s -o %s -d -x 1> nul 2> nul" %
                      (remove_seq_limits_path, "%s.aln" % self.temp_name,
                       self.settings.work_dir, self.temp_name))
        self.set_status("Ready")

        try:
            os.remove(
                os.path.join(self.settings.work_dir,
                             "%s.aln" % self.temp_name))
            os.remove(
                os.path.join(self.settings.work_dir,
                             "%s.blocks" % self.temp_name))
            os.remove(
                os.path.join(self.settings.work_dir,
                             "%s.motif" % self.temp_name))
            os.remove(
                os.path.join(self.settings.work_dir,
                             "%s.motif_var" % self.temp_name))
            os.remove(
                os.path.join(self.settings.work_dir,
                             "%s.orgs" % self.temp_name))
            os.remove(
                os.path.join(self.settings.work_dir,
                             "%s.pure.correspond" % self.temp_name))
        except OSError:
            pass

        fixed_filename = os.path.join(self.settings.work_dir,
                                      "%s.fixed" % self.temp_name)
        Aln_basic.read_widget_from_file(self.parse_tab.fixed.text_widget,
                                        fixed_filename)
        os.remove(fixed_filename)

        pure_filename = os.path.join(self.settings.work_dir,
                                     "%s.pure" % self.temp_name)
        Aln_basic.read_widget_from_file(self.parse_tab.pure.text_widget,
                                        pure_filename)
        self.parse_tab.enable_pure_analysis()
        os.remove(pure_filename)

        blocks_filename = os.path.join(self.settings.work_dir,
                                       "%s.blocks_regions" % self.temp_name)
        if os.path.isfile(blocks_filename):
            Aln_basic.read_widget_from_file(self.parse_tab.blocks.text_widget,
                                            blocks_filename)
            os.remove(blocks_filename)

        ids_filename = os.path.join(self.settings.work_dir,
                                    "%s.ids" % self.temp_name)
        Aln_basic.read_widget_from_file(self.parse_tab.IDs.text_widget,
                                        ids_filename)
        os.remove(ids_filename)

        self.parse_tab.check_numbers()