<commit_before>'''
This is an example script for using itol.py
To use itol.py, you essentially have to instantiate the object, set the tree,
submit the file to itol, then use the returned data
'''

import os
import sys

current_dir = os.path.abspath(os.path.realpath(__file__))
root_path = os.path.join(current_dir, '..')
sys.path.append(root_path)

from itolapi import Itol, ItolExport  # NOQA

print('Running example itol and itolexport script')
print('')
print('Creating the upload params')

# Create the Itol class
test = Itol.Itol()

# Set the tree file
tree = os.path.join(current_dir, 'example_tree')
test.add_variable('treeFile', tree)
# Add parameters
test.add_variable('treeName', 'adsf')
test.add_variable('treeFormat', 'newick')
test.add_variable('dataset1File', os.path.join(current_dir, 'example_data'))
test.add_variable('dataset1Label', 'colors')
test.add_variable('dataset1Separator', 'comma')
test.add_variable('dataset1Type', 'multibar')
# Check parameters
test.print_variables()
# Submit the tree
print('')
print((
    'Uploading the tree.  This may take some time depending on how large the '
    'tree is and how much load there is on the itol server'
))
good_upload = test.upload()
if not good_upload:
    print('There was an error:' + test.comm.upload_output)
    sys.exit(1)

# Read the tree ID
print('Tree ID: ' + str(test.comm.tree_id))

# Read the iTOL API return statement
print('iTOL output: ' + str(test.comm.upload_output))

# Website to be redirected to iTOL tree
print('Tree Web Page URL: ' + test.get_webpage())

# Warnings associated with the upload
print('Warnings: ' + str(test.comm.warnings))


# Export a pre-made tree to pdf
itol_exporter = ItolExport.ItolExport()
itol_exporter.set_export_param_value('tree', '18793532031912684633930')
itol_exporter.set_export_param_value('format', 'pdf')
itol_exporter.set_export_param_value('datasetList', 'dataset1')
# itol_exporter.export('example_pdf.pdf')
# print('exported tree to ',export_location)

# Export the tree above to pdf
print('Exporting to pdf')
itol_exporter = test.get_itol_export()
export_location = 'example_pdf.pdf'
itol_exporter.set_export_param_value('format', 'pdf')
itol_exporter.set_export_param_value('datasetList', 'dataset1')
itol_exporter.export('example_pdf.pdf')
print('exported tree to ', export_location)<commit_msg>Export example_pdf.pdf to example directory<commit_after>'''
This is an example script for using itol.py
To use itol.py, you essentially have to instantiate the object, set the tree,
submit the file to itol, then use the returned data
'''

import os
import sys

current_dir = os.path.dirname(os.path.realpath(__file__))
root_path = os.path.join(current_dir, '..')
sys.path.append(root_path)

from itolapi import Itol, ItolExport  # NOQA

print('Running example itol and itolexport script')
print('')
print('Creating the upload params')

# Create the Itol class
test = Itol.Itol()

# Set the tree file
tree = os.path.join(current_dir, 'example_tree')
test.add_variable('treeFile', tree)
# Add parameters
test.add_variable('treeName', 'adsf')
test.add_variable('treeFormat', 'newick')
test.add_variable('dataset1File', os.path.join(current_dir, 'example_data'))
test.add_variable('dataset1Label', 'colors')
test.add_variable('dataset1Separator', 'comma')
test.add_variable('dataset1Type', 'multibar')
# Check parameters
test.print_variables()
# Submit the tree
print('')
print((
    'Uploading the tree.  This may take some time depending on how large the '
    'tree is and how much load there is on the itol server'
))
good_upload = test.upload()
if not good_upload:
    print('There was an error:' + test.comm.upload_output)
    sys.exit(1)

# Read the tree ID
print('Tree ID: ' + str(test.comm.tree_id))

# Read the iTOL API return statement
print('iTOL output: ' + str(test.comm.upload_output))

# Website to be redirected to iTOL tree
print('Tree Web Page URL: ' + test.get_webpage())

# Warnings associated with the upload
print('Warnings: ' + str(test.comm.warnings))


# Export a pre-made tree to pdf
itol_exporter = ItolExport.ItolExport()
itol_exporter.set_export_param_value('tree', '18793532031912684633930')
itol_exporter.set_export_param_value('format', 'pdf')
itol_exporter.set_export_param_value('datasetList', 'dataset1')
# itol_exporter.export('example_pdf.pdf')
# print('exported tree to ',export_location)

# Export the tree above to pdf
print('Exporting to pdf')
itol_exporter = test.get_itol_export()
export_location = os.path.join(current_dir, 'example_pdf.pdf')
itol_exporter.set_export_param_value('format', 'pdf')
itol_exporter.set_export_param_value('datasetList', 'dataset1')
itol_exporter.export(export_location)
print('exported tree to ', export_location)
{'fraction_non_alphanumeric': 0.122002970507108, 'fraction_numerical': 0.012730744748567792, 'mean_word_length': 6.185975609756097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6301082', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1543, 'n_words': 420}