import os

import harvest.dataframe
from harvest.models.simulator import Simulator

class BeastSimulator(Simulator):

    def __init__(self, tree, n_features):
        Simulator.__init__(self, tree, n_features)

    def generate_beast_xml(self):
        # Subclasses should implement this
        return None

    def generate_data(self):
        # Generate BEAST XML file to do simulation
        xml = self.generate_beast_xml()
        temp_filename = xml.write_file(overwrite=True)
        # Run BEAST simulation
        os.system("beast %s > /dev/null" %  temp_filename)
        # Delete BEAST XML file
        os.remove(temp_filename)
        # Read simulated data
        data = harvest.dataframe.read_from_beast_xml(xml.output_filename)
        # Delete simualted data
        os.remove(xml.output_filename)
        self.data = data
        self.data.datatype = self.datatype

[((9, 8, 9, 50), 'harvest.models.simulator.Simulator.__init__', 'Simulator.__init__', ({(9, 27, 9, 31): 'self', (9, 33, 9, 37): 'tree', (9, 39, 9, 49): 'n_features'}, {}), '(self, tree, n_features)', False, 'from harvest.models.simulator import Simulator\n'), ((20, 8, 20, 58), 'os.system', 'os.system', ({(20, 18, 20, 57): "('beast %s > /dev/null' % temp_filename)"}, {}), "('beast %s > /dev/null' % temp_filename)", False, 'import os\n'), ((22, 8, 22, 32), 'os.remove', 'os.remove', ({(22, 18, 22, 31): 'temp_filename'}, {}), '(temp_filename)', False, 'import os\n'), ((26, 8, 26, 38), 'os.remove', 'os.remove', ({(26, 18, 26, 37): 'xml.output_filename'}, {}), '(xml.output_filename)', False, 'import os\n')]