# Path: epac/json_util.py
# class EpaJsonParser:
#     """This class parses the RAxML-EPA json output file"""
#     def __init__(self, jsonfin):
#         f=open(jsonfin) 
#         try:    
#             self.jdata = json.load(f)
#         finally:
#             f.close()
#     
#     def get_placement(self):
#         return self.jdata["placements"]
#         
#     def get_tree(self):
#         return self.jdata["tree"]
#         
#     def get_std_newick_tree(self):
#         tree = self.jdata["tree"]
#         tree = tree.replace("{", "[&&NHX:B=")
#         tree = tree.replace("}", "]")
#         return tree
# 
#     def get_raxml_version(self):
#         return self.jdata["metadata"]["raxml_version"]
# 
#     def get_raxml_invocation(self):
#         return self.jdata["metadata"]["invocation"]


import os
import sys
import glob
import shutil
import datetime
import random
import re
from subprocess import call,STDOUT
from .json_util import EpaJsonParser
        if silent:        
            self.cfg.log.debug(' '.join(call_str) + "\n")
            out_fname = self.make_raxml_fname("output", job_name)
            with open(out_fname, "w") as fout:
                call(call_str, stdout=fout, stderr=STDOUT)
        else:        
            call(call_str)

        return ' '.join(call_str)
        
    def restart_from_checkpoint(self, job_name, params, silent=True):
        old_chkpoint_fname = self.checkpoint_fname(job_name)
        if not os.path.isfile(old_chkpoint_fname):
            old_chkpoint_fname = self.bkup_checkpoint_fname(job_name)
            if not os.path.isfile(old_chkpoint_fname):
                old_chkpoint_fname = None

        old_info = self.info_fname(job_name)
        FileUtils.remove_if_exists(old_info)
        if old_chkpoint_fname:
            chkpoint_fname = self.checkpoint_fname("last_chkpoint")
            shutil.move(old_chkpoint_fname, chkpoint_fname)
            
        return self.run(job_name, params, silent, chkpoint_fname)
        
    def run_multiple(self, job_name, params, repnum, silent=True):    
        best_lh = float("-inf")
        best_jobname = None
        check_old_jobs = self.cfg.restart
        

# Path: epac/json_util.py
# class EpaJsonParser:
#     """This class parses the RAxML-EPA json output file"""
#     def __init__(self, jsonfin):
#         f=open(jsonfin) 
#         try:    
#             self.jdata = json.load(f)
#         finally:
#             f.close()
#     
#     def get_placement(self):
#         return self.jdata["placements"]
#         
#     def get_tree(self):
#         return self.jdata["tree"]
#         
#     def get_std_newick_tree(self):
#         tree = self.jdata["tree"]
#         tree = tree.replace("{", "[&&NHX:B=")
#         tree = tree.replace("}", "]")
#         return tree
# 
#     def get_raxml_version(self):
#         return self.jdata["metadata"]["raxml_version"]
# 
#     def get_raxml_invocation(self):
#         return self.jdata["metadata"]["invocation"]


# Path: epac/raxml_util.py
import os
import sys
import glob
import shutil
import datetime
import random
import re
from subprocess import call,STDOUT
from .json_util import EpaJsonParser

        if silent:        
            self.cfg.log.debug(' '.join(call_str) + "\n")
            out_fname = self.make_raxml_fname("output", job_name)
            with open(out_fname, "w") as fout:
                call(call_str, stdout=fout, stderr=STDOUT)
        else:        
            call(call_str)

        return ' '.join(call_str)
        
    def restart_from_checkpoint(self, job_name, params, silent=True):
        old_chkpoint_fname = self.checkpoint_fname(job_name)
        if not os.path.isfile(old_chkpoint_fname):
            old_chkpoint_fname = self.bkup_checkpoint_fname(job_name)
            if not os.path.isfile(old_chkpoint_fname):
                old_chkpoint_fname = None

        old_info = self.info_fname(job_name)
        FileUtils.remove_if_exists(old_info)
        if old_chkpoint_fname:
            chkpoint_fname = self.checkpoint_fname("last_chkpoint")
            shutil.move(old_chkpoint_fname, chkpoint_fname)
            
        return self.run(job_name, params, silent, chkpoint_fname)
        
    def run_multiple(self, job_name, params, repnum, silent=True):    
        best_lh = float("-inf")
        best_jobname = None
        check_old_jobs = self.cfg.restart
        

        for i in range(repnum):