<commit_before># Transforms an NLP standoff file into SBML
# For more information see <NAME>, <NAME> and <NAME>. Extracting Biological Pathway Models From NLP Event Representations. In Proceedings of the 2015 Workshop on Biomedical Natural Language Processing (BioNLP 2015), pages 42-51, 2015. Association for Computational Linguistics.
# http://ijcai.org/papers15/Papers/IJCAI15-271.pdf

# to run all tests
# ls tests/*.ann | xargs -I {} python2.7 st2sbml.py --file {}  --output {}.output-sbml.xml --complete-reactions

import argparse
import cgi
import copy
import logging
import os
import re
import sets
import sys

import libsbml
import parse_standoff
import uniprot_tools

# mapping of trigger (entity) to sbo term (based on 1)
STANDOFF_ENTITY_TO_SBO_MAPPING = {
    "gene" : "SBO:0000354", # informational molecule segment
    "complex" : "SBO:0000253", # non-covalent complex
    "protein" : "SBO:0000252", # polypeptide chain
    "dna" : "SBO:0000251", # deoxyribonucleic acid
    "dnaregion" : "SBO:0000251", # deoxyribonucleic acid
    "rna" : "SBO:0000250", # ribonucleic acid
    "rnaregion" : "SBO:0000250", # ribonucleic acid
    "smallmolecule" : "SBO:0000247", # simple chemical
    "simple_molecule" : "SBO:0000247", # simple chemical
    "ion" : "SBO:0000247", # simple chemical
    "drug" : "SBO:0000247" # simple chemical
}

STANDOFF_EVENT_TO_SBO_MAPPING = {
    "acetylation"  :   "SBO:0000215",
    "activation"   :   "SBO:0000170",
    "association"  :   "SBO:0000297",
    "binding"  :   "SBO:0000297",
    "catabolism"   :   "GO:0009056",
    "catalysis"    :   "SBO:0000172",
    "conversion"   :   "SBO:0000182",
    "deacetylation"    :   "GO:0006476",
    "degradation"  :   "SBO:0000179",
    "demethylation"    :   "GO:0006482",
    "dephosphorylation"    :   "SBO:0000330",
    "deubiquitination" :   "GO:0016579",
    "dissociation" :   "SBO:0000180",
    "gene_expression" : "GO:0010467",
    "inactivation" :   "SBO:0000169",
    "localization" :   "GO:0051179",
    "methylation"  :   "SBO:0000214",
    "negative_regulation"  :  "SBO:0000169",
    "pathway"  :   "SBO:0000375", 
    "phosphorylation"  :   "SBO:0000216",
    "positive_regulation"  :   "SBO:0000170",
    "protein_catabolism"   :   "SBO:0000179", # degradation
    "regulation"   :   "SBO:0000168",
    "transcription"    :   "SBO:0000183", 
    "translation"  :   "SBO:0000184",
    "transport"    :   "SBO:0000185",
    "ubiquitination"   :   "SBO:0000224"
}

# mapping of general reaction components to sbo term 
GENERIC_REACTION_SBO_MAPPING = {
    "reactant"  :   "SBO:0000010",
    "product"  :   "SBO:0000011",
    "modifier"  :   "SBO:0000019",
    "activator"  :   "SBO:0000021",
    "inhibitor"  :   "SBO:0000020"
}

def parse_arguments( args = None):
    
    parser = argparse.ArgumentParser( description='Converts BioNLP shared task format to SBML (requires libsbml).')
    
    parser.add_argument( '--file',
                    action = "store",
                    dest = "file",
                    default = "test.ann",
                    help = "the file to convert (default is test.ann)")

    parser.add_argument( '--path',
                        action = "store",
                        dest = "path",
                        default = None,
                        help = "the path to a1, a2 or ann file (includes the prefix)")
    
    parser.add_argument( '--a1',
                        action = "store",
                        dest = "a1",
                        default = ".a1",
                        help = "the file ending for a1 files")
    
    parser.add_argument( '--a2',
                        action="store",
                        dest = "a2",
                        default = ".a2",
                        help = "the file ending for a2 files")
    
    parser.add_argument( '--ann',
                        action="store",
                        dest = "ann",
                        default = ".ann",
                        help = "the file ending for a2 files")
    
    parser.add_argument( '--use-ann',
                        action="store_true",
                        dest = "use_ann",
                        default = True,
                        help="whether to use ann or a1/a2")
    
    parser.add_argument( '--output',
                        action = "store",
                        dest = "output",
                        default = "output-sbml.xml",
                        help="the path to output file")

    parser.add_argument( '--remove-unconnected-species',
                        action = "store_true",
                        dest = "remove_unconnected_species",
                        default = False,
                        help = "whether to keep unconnected species (i.e. species not used in reactions)")

    parser.add_argument( '--complete-reactions',
                        action = "store_true",
                        dest = "complete_reactions",
                        default = False,
                        help = "whether to complete reactions by adding reactants and products.")

    parser.add_argument( '--remove-unconnected-reactions',
                        action = "store_true",<commit_msg>--use-ann should be False by default<commit_after># Transforms an NLP standoff file into SBML
# For more information see <NAME>, <NAME> and <NAME>. Extracting Biological Pathway Models From NLP Event Representations. In Proceedings of the 2015 Workshop on Biomedical Natural Language Processing (BioNLP 2015), pages 42-51, 2015. Association for Computational Linguistics.
# http://ijcai.org/papers15/Papers/IJCAI15-271.pdf

# to run all tests
# ls tests/*.ann | xargs -I {} python2.7 st2sbml.py --file {}  --output {}.output-sbml.xml --complete-reactions

import argparse
import cgi
import copy
import logging
import os
import re
import sets
import sys

import libsbml
import parse_standoff
import uniprot_tools

# mapping of trigger (entity) to sbo term (based on 1)
STANDOFF_ENTITY_TO_SBO_MAPPING = {
    "gene" : "SBO:0000354", # informational molecule segment
    "complex" : "SBO:0000253", # non-covalent complex
    "protein" : "SBO:0000252", # polypeptide chain
    "dna" : "SBO:0000251", # deoxyribonucleic acid
    "dnaregion" : "SBO:0000251", # deoxyribonucleic acid
    "rna" : "SBO:0000250", # ribonucleic acid
    "rnaregion" : "SBO:0000250", # ribonucleic acid
    "smallmolecule" : "SBO:0000247", # simple chemical
    "simple_molecule" : "SBO:0000247", # simple chemical
    "ion" : "SBO:0000247", # simple chemical
    "drug" : "SBO:0000247" # simple chemical
}

STANDOFF_EVENT_TO_SBO_MAPPING = {
    "acetylation"  :   "SBO:0000215",
    "activation"   :   "SBO:0000170",
    "association"  :   "SBO:0000297",
    "binding"  :   "SBO:0000297",
    "catabolism"   :   "GO:0009056",
    "catalysis"    :   "SBO:0000172",
    "conversion"   :   "SBO:0000182",
    "deacetylation"    :   "GO:0006476",
    "degradation"  :   "SBO:0000179",
    "demethylation"    :   "GO:0006482",
    "dephosphorylation"    :   "SBO:0000330",
    "deubiquitination" :   "GO:0016579",
    "dissociation" :   "SBO:0000180",
    "gene_expression" : "GO:0010467",
    "inactivation" :   "SBO:0000169",
    "localization" :   "GO:0051179",
    "methylation"  :   "SBO:0000214",
    "negative_regulation"  :  "SBO:0000169",
    "pathway"  :   "SBO:0000375", 
    "phosphorylation"  :   "SBO:0000216",
    "positive_regulation"  :   "SBO:0000170",
    "protein_catabolism"   :   "SBO:0000179", # degradation
    "regulation"   :   "SBO:0000168",
    "transcription"    :   "SBO:0000183", 
    "translation"  :   "SBO:0000184",
    "transport"    :   "SBO:0000185",
    "ubiquitination"   :   "SBO:0000224"
}

# mapping of general reaction components to sbo term 
GENERIC_REACTION_SBO_MAPPING = {
    "reactant"  :   "SBO:0000010",
    "product"  :   "SBO:0000011",
    "modifier"  :   "SBO:0000019",
    "activator"  :   "SBO:0000021",
    "inhibitor"  :   "SBO:0000020"
}

def parse_arguments( args = None):
    
    parser = argparse.ArgumentParser( description='Converts BioNLP shared task format to SBML (requires libsbml).')
    
    parser.add_argument( '--file',
                    action = "store",
                    dest = "file",
                    default = "test.ann",
                    help = "the file to convert (default is test.ann)")

    parser.add_argument( '--path',
                        action = "store",
                        dest = "path",
                        default = None,
                        help = "the path to a1, a2 or ann file (includes the prefix)")
    
    parser.add_argument( '--a1',
                        action = "store",
                        dest = "a1",
                        default = ".a1",
                        help = "the file ending for a1 files")
    
    parser.add_argument( '--a2',
                        action="store",
                        dest = "a2",
                        default = ".a2",
                        help = "the file ending for a2 files")
    
    parser.add_argument( '--ann',
                        action="store",
                        dest = "ann",
                        default = ".ann",
                        help = "the file ending for a2 files")
    
    parser.add_argument( '--use-ann',
                        action="store_true",
                        dest = "use_ann",
                        default = False,
                        help="whether to use ann or a1/a2")
    
    parser.add_argument( '--output',
                        action = "store",
                        dest = "output",
                        default = "output-sbml.xml",
                        help="the path to output file")

    parser.add_argument( '--remove-unconnected-species',
                        action = "store_true",
                        dest = "remove_unconnected_species",
                        default = False,
                        help = "whether to keep unconnected species (i.e. species not used in reactions)")

    parser.add_argument( '--complete-reactions',
                        action = "store_true",
                        dest = "complete_reactions",
                        default = False,
                        help = "whether to complete reactions by adding reactants and products.")

    parser.add_argument( '--remove-unconnected-reactions',
                        action = "store_true",
{'fraction_non_alphanumeric': 0.12106978527607362, 'fraction_numerical': 0.06537576687116564, 'mean_word_length': 1.8876280099640188, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '5576077', 'n_tokens_mistral': 3807, 'n_tokens_neox': 3118, 'n_words': 752}