<commit_before>#!/usr/bin/env python3

## Author(s): <NAME>
## Contact(s): <EMAIL>
## Python version: 3.6.0
## Creation : 12-20-2016

'''
Generation of XML for Galaxy from https://bio.tools based on the Tooldog model using
galaxyxml library.
'''

###########  Import  ###########

# General libraries
import os
import copy
import json
import logging

# External libraries
import galaxyxml.tool as gxt
import galaxyxml.tool.parameters as gxtp
import requests

# Class and Objects
from tooldog.edam_to_galaxy import EdamToGalaxy
from tooldog import version

###########  Constant(s)  ###########

###########  Logger  ###########

LOGGER = logging.getLogger(__name__)

###########  Class(es)  ###########

class GenerateXml(object):
    '''
    Class to support generation of XML from :class:`tooldog.model.Biotool` object.
    '''

    def __init__(self, biotool, galaxy_url=None, edam_url=None, mapping_json=None):
        '''
        Initialize a [Tool] object from galaxyxml with the minimal information
        (a name, an id, a version, a description, the command, the command version
        and a help).

        :param biotool: Biotool object of an entry from https://bio.tools.
        :type biotool: :class:`tooldog.model.Biotool`
        '''
        LOGGER.info("Creating new GenerateXml object...")
        # Initialize GalaxyInfo
        self.etog = EdamToGalaxy(galaxy_url=galaxy_url, edam_url=edam_url,\
                                 mapping_json=mapping_json)
        # Initialize counters for inputs and outputs
        self.input_ct = 0
        self.output_ct = 0
        # Initialize tool
        #   Get the first sentence of the description only
        description = biotool.description.split('.')[0] + '.'
        self.tool = gxt.Tool(biotool.name, biotool.tool_id, biotool.version, \
                             description, "COMMAND", version_command=\
                             "COMMAND --version")
        self.tool.help = (biotool.description + "\n\nTool Homepage: " + \
                          biotool.homepage)
        #   Add information about Galaxy, EDAM and Tooldog in the XML
        self.tool.add_comment("Information was obtained from the Galaxy instance: " +\
                              self.etog.galaxy_url + " v" + \
                              self.etog.galaxy_version + " and EDAM v" + \
                              self.etog.edam_version) 
        self.tool.add_comment("This tool descriptor has been generated by ToolDog v" +\
                              version) 

    def add_edam_topic(self, topic):
        '''
        Add the EDAM topic to the tool (XML: edam_topics).

        :param topic: Topic object.
        :type topic: :class:`tooldog.model.Topic`
        '''
        LOGGER.debug("Adding EDAM topic " + topic.get_edam_id() + " to GenerateXml object.")
        if not hasattr(self.tool, 'edam_topics'):
            # First time we add topics to the tool
            self.tool.edam_topics = gxtp.EdamTopics()
        self.tool.edam_topics.append(gxtp.EdamTopic(topic.get_edam_id()))

    def add_edam_operation(self, operation):
        '''
        Add the EDAM operation to the tool (XML: edam_operations).

        :param topic: Operation object.
        :type topic: :class:`tooldog.model.Operation`
        '''
        LOGGER.debug("Adding EDAM operation " + operation.get_edam_id() +\
                     " to GenerateXml object.")
        if not hasattr(self.tool, 'edam_operations'):
            # First time we add operations to the tool
            self.tool.edam_operations = gxtp.EdamOperations()
        self.tool.edam_operations.append(gxtp.EdamOperation(operation.get_edam_id()))

    def add_input_file(self, input_obj):
        '''
        Add an input to the tool (XML: <inputs>).

        :param input_obj: Input object.
        :type input_obj: :class:`tooldog.model.Input`
        '''
        LOGGER.debug("Adding input to GenerateXml object...")
        if not hasattr(self.tool, 'inputs'):
            self.tool.inputs = gxtp.Inputs()
        # Build parameter
        self.input_ct += 1
        data_uri = input_obj.data_type.get_edam_id()
        # Give unique name to the input
        name = 'INPUT' + str(self.input_ct)
        # Get all different format for this input
        list_formats = []
        if not input_obj.formats:
            list_formats.append(self.etog.get_datatype(edam_data=data_uri))
        else:
            for format_obj in input_obj.formats:
                format_uri = format_obj.get_edam_id()
                list_formats.append(self.etog.get_datatype(edam_data=data_uri,\
                                                           edam_format=format_uri))
        formats = ', '.join(list_formats)
        # Create the parameter
        param = gxtp.DataParam(name, label=input_obj.data_type.term, \
                               help=input_obj.description, format=formats)
        # Override the corresponding arguments in the command line
        param.command_line_override = '--' + name + ' $' + name
        # Appends parameter to inputs
        self.tool.inputs.append(param)

    def add_output_file(self, output):
        '''
        Add an output to the tool (XML: <outputs>).
 
        :param output: Output object.
        :type output: :class:`tooldog.model.Output`
        '''<commit_msg>code gardening with pylint<commit_after>#!/usr/bin/env python3

## Author(s): <NAME>
## Contact(s): <EMAIL>
## Python version: 3.6.0
## Creation : 12-20-2016

'''
Generation of XML for Galaxy from https://bio.tools based on the Tooldog model using
galaxyxml library.
'''

###########  Import  ###########

# General libraries
import os
import copy
import logging

# External libraries
import galaxyxml.tool as gxt
import galaxyxml.tool.parameters as gxtp

# Class and Objects
from tooldog.edam_to_galaxy import EdamToGalaxy
from tooldog import version

###########  Constant(s)  ###########

###########  Logger  ###########

LOGGER = logging.getLogger(__name__)

###########  Class(es)  ###########

class GenerateXml(object):
    '''
    Class to support generation of XML from :class:`tooldog.model.Biotool` object.
    '''

    def __init__(self, biotool, galaxy_url=None, edam_url=None, mapping_json=None):
        '''
        Initialize a [Tool] object from galaxyxml with the minimal information
        (a name, an id, a version, a description, the command, the command version
        and a help).

        :param biotool: Biotool object of an entry from https://bio.tools.
        :type biotool: :class:`tooldog.model.Biotool`
        '''
        LOGGER.info("Creating new GenerateXml object...")
        # Initialize GalaxyInfo
        self.etog = EdamToGalaxy(galaxy_url=galaxy_url, edam_url=edam_url,\
                                 mapping_json=mapping_json)
        # Initialize counters for inputs and outputs
        self.input_ct = 0
        self.output_ct = 0
        # Initialize tool
        #   Get the first sentence of the description only
        description = biotool.description.split('.')[0] + '.'
        self.tool = gxt.Tool(biotool.name, biotool.tool_id, biotool.version, \
                             description, "COMMAND", version_command=\
                             "COMMAND --version")
        self.tool.help = (biotool.description + "\n\nTool Homepage: " + \
                          biotool.homepage)
        #   Add information about Galaxy, EDAM and Tooldog in the XML
        self.tool.add_comment("Information was obtained from the Galaxy instance: " +\
                              self.etog.galaxy_url + " v" + \
                              self.etog.galaxy_version + " and EDAM v" + \
                              self.etog.edam_version)
        self.tool.add_comment("This tool descriptor has been generated by ToolDog v" +\
                              version)

    def add_edam_topic(self, topic):
        '''
        Add the EDAM topic to the tool (XML: edam_topics).

        :param topic: Topic object.
        :type topic: :class:`tooldog.model.Topic`
        '''
        LOGGER.debug("Adding EDAM topic " + topic.get_edam_id() + " to GenerateXml object.")
        if not hasattr(self.tool, 'edam_topics'):
            # First time we add topics to the tool
            self.tool.edam_topics = gxtp.EdamTopics()
        self.tool.edam_topics.append(gxtp.EdamTopic(topic.get_edam_id()))

    def add_edam_operation(self, operation):
        '''
        Add the EDAM operation to the tool (XML: edam_operations).

        :param topic: Operation object.
        :type topic: :class:`tooldog.model.Operation`
        '''
        LOGGER.debug("Adding EDAM operation " + operation.get_edam_id() +\
                     " to GenerateXml object.")
        if not hasattr(self.tool, 'edam_operations'):
            # First time we add operations to the tool
            self.tool.edam_operations = gxtp.EdamOperations()
        self.tool.edam_operations.append(gxtp.EdamOperation(operation.get_edam_id()))

    def add_input_file(self, input_obj):
        '''
        Add an input to the tool (XML: <inputs>).

        :param input_obj: Input object.
        :type input_obj: :class:`tooldog.model.Input`
        '''
        LOGGER.debug("Adding input to GenerateXml object...")
        if not hasattr(self.tool, 'inputs'):
            self.tool.inputs = gxtp.Inputs()
        # Build parameter
        self.input_ct += 1
        data_uri = input_obj.data_type.get_edam_id()
        # Give unique name to the input
        name = 'INPUT' + str(self.input_ct)
        # Get all different format for this input
        list_formats = []
        if not input_obj.formats:
            list_formats.append(self.etog.get_datatype(edam_data=data_uri))
        else:
            for format_obj in input_obj.formats:
                format_uri = format_obj.get_edam_id()
                list_formats.append(self.etog.get_datatype(edam_data=data_uri,\
                                                           edam_format=format_uri))
        formats = ', '.join(list_formats)
        # Create the parameter
        param = gxtp.DataParam(name, label=input_obj.data_type.term, \
                               help=input_obj.description, format=formats)
        # Override the corresponding arguments in the command line
        param.command_line_override = '--' + name + ' $' + name
        # Appends parameter to inputs
        self.tool.inputs.append(param)

    def add_output_file(self, output):
        '''
        Add an output to the tool (XML: <outputs>).

        :param output: Output object.
        :type output: :class:`tooldog.model.Output`
        '''
{'fraction_non_alphanumeric': 0.1139906103286385, 'fraction_numerical': 0.003004694835680751, 'mean_word_length': 2.168997322225528, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1602473', 'n_tokens_mistral': 3138, 'n_tokens_neox': 3080, 'n_words': 781}