4040from  sate .utility  import  IndentedHelpFormatterWithNL 
4141from  sate .filemgr  import  open_with_intermediates 
4242from  sate  import  filemgr 
43+ from  sate  import  TEMP_SEQ_ALIGNMENT_TAG , TEMP_TREE_TAG 
44+ 
4345
4446_RunningJobs  =  None 
4547
@@ -171,6 +173,9 @@ def finish_sate_execution(sate_team,
171173    # We must read the incoming tree in before we call the get_sequences_for_sate 
172174    #   function that relabels that taxa in the dataset 
173175    ###### 
176+     alignment_as_tmp_filename_to_report  =  None 
177+     tree_as_tmp_filename_to_report  =  None 
178+     
174179    tree_file  =  options .treefile 
175180    if  tree_file :
176181        if  not  os .path .exists (tree_file ):
@@ -183,6 +188,7 @@ def finish_sate_execution(sate_team,
183188            MESSENGER .send_warning ('%d starting trees found in "%s". The first tree will be used.'  %  (len (tree_list ), tree_file ))
184189        starting_tree  =  tree_list [0 ]
185190        score  =  None 
191+         tree_as_tmp_filename_to_report  =  tree_file 
186192
187193    ############################################################################ 
188194    # This will relabel the taxa if they have problematic names 
@@ -271,6 +277,8 @@ def finish_sate_execution(sate_team,
271277            jobq .put (job )
272278            score , starting_tree_str  =  job .get_results ()
273279            _RunningJobs  =  None 
280+             alignment_as_tmp_filename_to_report  =  sate_products .get_abs_path_for_iter_output ("initialsearch" , TEMP_SEQ_ALIGNMENT_TAG , allow_existing = True )
281+             tree_as_tmp_filename_to_report  =  sate_products .get_abs_path_for_iter_output ("initialsearch" , TEMP_TREE_TAG , allow_existing = True )
274282            if  delete_tree_temps :
275283                sate_team .temp_fs .remove_dir (init_tree_dir )
276284        _LOG .debug ('We have the tree and whole_alignment, partitions...' )
@@ -289,6 +297,8 @@ def finish_sate_execution(sate_team,
289297                        score = score ,
290298                        ** sate_config_dict )
291299        job .tree_str  =  starting_tree_str 
300+         job .curr_iter_align_tmp_filename  =  alignment_as_tmp_filename_to_report 
301+         job .curr_iter_tree_tmp_filename  =  tree_as_tmp_filename_to_report 
292302        if  score  is  not   None :
293303            job .store_optimum_results (new_multilocus_dataset = multilocus_dataset ,
294304                    new_tree_str = starting_tree_str ,
@@ -302,6 +312,11 @@ def finish_sate_execution(sate_team,
302312            MESSENGER .send_info ("Starting SATe algorithm on initial tree..." )
303313            job .run (tmp_dir_par = temporaries_dir , sate_products = sate_products )
304314            _RunningJobs  =  None 
315+ 
316+             if  job .return_final_tree_and_alignment :
317+                 alignment_as_tmp_filename_to_report  =  job .curr_iter_align_tmp_filename 
318+             else :
319+                 alignment_as_tmp_filename_to_report  =  job .best_alignment_tmp_filename 
305320
306321            if  user_config .commandline .raxml_search_after :
307322                raxml_model  =  user_config .raxml .model .strip ()
@@ -327,26 +342,31 @@ def finish_sate_execution(sate_team,
327342                jobq .put (post_job )
328343                post_score , post_tree  =  post_job .get_results ()
329344                _RunningJobs  =  None 
345+                 tree_as_tmp_filename_to_report  =  sate_products .get_abs_path_for_iter_output ("postraxtree" , TEMP_TREE_TAG , allow_existing = True )
330346                if  delete_tree_temps :
331347                    sate_team .temp_fs .remove_dir (post_tree_dir )
332348                job .tree_str  =  post_tree 
333349                job .score  =  post_score 
334350                if  post_score  >  job .best_score :
335351                    job .best_tree_str  =  post_tree 
336352                    job .best_score  =  post_score 
353+             else :
354+                 if  job .return_final_tree_and_alignment :
355+                     tree_as_tmp_filename_to_report  =  job .curr_iter_tree_tmp_filename 
356+                 else :
357+                     tree_as_tmp_filename_to_report  =  job .best_tree_tmp_filename 
337358
338-         
339359
340360        job .multilocus_dataset .restore_taxon_names ()
341361        assert  len (sate_products .alignment_streams ) ==  len (job .multilocus_dataset )
342362        for  i , alignment  in  enumerate (job .multilocus_dataset ):
343363            alignment_stream  =  sate_products .alignment_streams [i ]
344-             MESSENGER .send_info ("Writing final  alignment to %s"  %  alignment_stream .name )
364+             MESSENGER .send_info ("Writing resulting  alignment to %s"  %  alignment_stream .name )
345365            alignment .write (alignment_stream , file_format = "FASTA" )
346366            alignment_stream .close ()
347367
348368
349-         MESSENGER .send_info ("Writing final  tree to %s"  %  sate_products .tree_stream .name )
369+         MESSENGER .send_info ("Writing resulting  tree to %s"  %  sate_products .tree_stream .name )
350370        tree_str  =  job .tree .compose_newick ()
351371        sate_products .tree_stream .write ("%s;\n "  %  tree_str )
352372
@@ -357,13 +377,19 @@ def finish_sate_execution(sate_team,
357377        #        outtree_fn = os.path.join(seqdir, "combined_%s.tre" % options.job) 
358378        #    else: 
359379        #        outtree_fn = aln_filename + ".tre" 
360-         #MESSENGER.send_info("Writing final  tree to %s" % outtree_fn) 
380+         #MESSENGER.send_info("Writing resulting  tree to %s" % outtree_fn) 
361381        #tree_str = job.tree.compose_newick() 
362382        #sate_products.tree_stream.write("%s;\n" % tree_str) 
363383
364384
365-         MESSENGER .send_info ("Writing final  likelihood score to %s"  %  sate_products .score_stream .name )
385+         MESSENGER .send_info ("Writing resulting  likelihood score to %s"  %  sate_products .score_stream .name )
366386        sate_products .score_stream .write ("%s\n "  %  job .score )
387+         
388+         if  alignment_as_tmp_filename_to_report  is  not   None :
389+             MESSENGER .send_info ('The resulting alignment (with the names in a "safe" form) was first written as the file "%s"'  %  alignment_as_tmp_filename_to_report )
390+         if  tree_as_tmp_filename_to_report  is  not   None :
391+             MESSENGER .send_info ('The resulting tree (with the names in a "safe" form) was first written as the file "%s"'  %  tree_as_tmp_filename_to_report )
392+ 
367393    finally :
368394        for  el  in  prev_signals :
369395            sig , prev_handler  =  el 
0 commit comments