# 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 self.cfg.epa_use_heuristic in ["TRUE", "YES", "1"]:
            raxml_params += ["-G", str(self.cfg.epa_heur_rate)]            

        if self.cfg.epa_load_optmod and optmod_fname:
            if os.path.isfile(optmod_fname):
                raxml_params += ["-R", optmod_fname]
                if self.cfg.raxml_model.startswith("GTRCAT") and not self.cfg.compress_patterns:
                    raxml_params +=  ["-H"]
            else:
                self.cfg.log.info("WARNING: Binary model file not found: %s" % optmod_fname)
                self.cfg.log.info("WARNING: Model parameters will be estimated by RAxML")
                
        self.run(job_name, raxml_params, silent)
        
        jp = None
        failed = False
        if mode == "l1o_subtree":
            jp = []
            i = 0
            while True:
                jp_fname = self.make_raxml_fname(result_file_stem, job_name) + ".%d.jplace" % (i+1)
                if not os.path.isfile(jp_fname):
                    break
                jp.append(EpaJsonParser(jp_fname))
                i += 1
            failed = i == 0    
        else:
            jp_fname = self.make_raxml_fname(result_file_stem, job_name) + ".jplace"
            if os.path.isfile(jp_fname):

# 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 self.cfg.epa_use_heuristic in ["TRUE", "YES", "1"]:
            raxml_params += ["-G", str(self.cfg.epa_heur_rate)]            

        if self.cfg.epa_load_optmod and optmod_fname:
            if os.path.isfile(optmod_fname):
                raxml_params += ["-R", optmod_fname]
                if self.cfg.raxml_model.startswith("GTRCAT") and not self.cfg.compress_patterns:
                    raxml_params +=  ["-H"]
            else:
                self.cfg.log.info("WARNING: Binary model file not found: %s" % optmod_fname)
                self.cfg.log.info("WARNING: Model parameters will be estimated by RAxML")
                
        self.run(job_name, raxml_params, silent)
        
        jp = None
        failed = False
        if mode == "l1o_subtree":
            jp = []
            i = 0
            while True:
                jp_fname = self.make_raxml_fname(result_file_stem, job_name) + ".%d.jplace" % (i+1)
                if not os.path.isfile(jp_fname):
                    break
                jp.append(EpaJsonParser(jp_fname))
                i += 1
            failed = i == 0    
        else:
            jp_fname = self.make_raxml_fname(result_file_stem, job_name) + ".jplace"
            if os.path.isfile(jp_fname):

                jp = EpaJsonParser(jp_fname)