<commit_before>import json
from indra.sources import sparser
from indra.sources.sparser.processor import _fix_agent
from indra.statements import Agent, Phosphorylation, Complex
from nose.plugins.attrib import attr

# ############################
# XML processing tests
# ############################

def test_invalid_xml():
    sp = sparser.process_xml('xyz')
    assert sp is None


def test_phosphorylation():
    sp = sparser.process_xml(xml_str1)
    assert len(sp.statements) == 1
    assert sp.statements[0].enz.name == 'MAP2K1'
    assert sp.statements[0].sub.name == 'MAPK3'
    assert len(sp.statements[0].evidence) == 1
    ev = sp.statements[0].evidence[0]
    assert ev.pmid == '54321'
    assert ev.text
    assert ev.source_api == 'sparser'


# This test uses some slow UniPtot web queries to standardize agent names
@attr('webservice', 'slow')
def test_phosphorylation2():
    sp = sparser.process_xml(xml_str2)
    assert len(sp.statements) == 1
    assert sp.statements[0].enz.name == 'MAPK1'
    assert sp.statements[0].sub.name == 'TP53BP2'
    assert sp.statements[0].residue == 'S'
    assert sp.statements[0].position == '827'
    assert (len(sp.statements[0].evidence) == 1)
    ev = sp.statements[0].evidence[0]
    assert (ev.pmid == '12345')
    assert (ev.text)
    assert (ev.source_api == 'sparser')


def test_fix_agent_be_name():
    a = Agent('XXX', db_refs={'FPLX': 'CDK'})
    _fix_agent(a)
    assert a.name == 'CDK'


def test_fix_agent_hgnc_only():
    a = Agent('XXX', db_refs={'HGNC': '7199'})
    _fix_agent(a)
    assert a.name == 'MOS'
    assert a.db_refs.get('UP') == 'P00540'


def test_fix_agent_fa_only():
    a = Agent('XXX', db_refs={'FA': '00815'})
    _fix_agent(a)
    assert a.name == 'Cyclin'
    assert a.db_refs.get('FPLX') == 'Cyclin'
    assert a.db_refs.get('NXPFA') == '00815'
    assert 'FA' not in a.db_refs


def test_fix_agent_ncit_only():
    a = Agent('XXX', db_refs={'NCIT': 'C25785'})
    _fix_agent(a)
    assert a.name == 'KRAS'
    assert a.db_refs.get('HGNC') == '6407'
    assert a.db_refs.get('UP') == 'P01116'


def test_fix_agent_ncit_only():
    a = Agent('XXX', db_refs={'NCIT': 'C104166'})
    _fix_agent(a)
    assert a.name == 'TUBB'
    assert a.db_refs.get('FPLX') == 'TUBB'


def test_fix_agent_pcid():<commit_msg>Update NCIT equivalence in test_sparser<commit_after>import json
from indra.sources import sparser
from indra.sources.sparser.processor import _fix_agent
from indra.statements import Agent, Phosphorylation, Complex
from nose.plugins.attrib import attr

# ############################
# XML processing tests
# ############################

def test_invalid_xml():
    sp = sparser.process_xml('xyz')
    assert sp is None


def test_phosphorylation():
    sp = sparser.process_xml(xml_str1)
    assert len(sp.statements) == 1
    assert sp.statements[0].enz.name == 'MAP2K1'
    assert sp.statements[0].sub.name == 'MAPK3'
    assert len(sp.statements[0].evidence) == 1
    ev = sp.statements[0].evidence[0]
    assert ev.pmid == '54321'
    assert ev.text
    assert ev.source_api == 'sparser'


# This test uses some slow UniPtot web queries to standardize agent names
@attr('webservice', 'slow')
def test_phosphorylation2():
    sp = sparser.process_xml(xml_str2)
    assert len(sp.statements) == 1
    assert sp.statements[0].enz.name == 'MAPK1'
    assert sp.statements[0].sub.name == 'TP53BP2'
    assert sp.statements[0].residue == 'S'
    assert sp.statements[0].position == '827'
    assert (len(sp.statements[0].evidence) == 1)
    ev = sp.statements[0].evidence[0]
    assert (ev.pmid == '12345')
    assert (ev.text)
    assert (ev.source_api == 'sparser')


def test_fix_agent_be_name():
    a = Agent('XXX', db_refs={'FPLX': 'CDK'})
    _fix_agent(a)
    assert a.name == 'CDK'


def test_fix_agent_hgnc_only():
    a = Agent('XXX', db_refs={'HGNC': '7199'})
    _fix_agent(a)
    assert a.name == 'MOS'
    assert a.db_refs.get('UP') == 'P00540'


def test_fix_agent_fa_only():
    a = Agent('XXX', db_refs={'FA': '00815'})
    _fix_agent(a)
    assert a.name == 'Cyclin'
    assert a.db_refs.get('FPLX') == 'Cyclin'
    assert a.db_refs.get('NXPFA') == '00815'
    assert 'FA' not in a.db_refs


def test_fix_agent_ncit_only():
    a = Agent('XXX', db_refs={'NCIT': 'C25785'})
    _fix_agent(a)
    assert a.name == 'KRAS'
    assert a.db_refs.get('HGNC') == '6407'
    assert a.db_refs.get('UP') == 'P01116'


def test_fix_agent_ncit_only():
    a = Agent('XXX', db_refs={'NCIT': 'C129655'})
    _fix_agent(a)
    assert a.name == 'TUBB'
    assert a.db_refs.get('FPLX') == 'TUBB'


def test_fix_agent_pcid():
{'fraction_non_alphanumeric': 0.1777681660899654, 'fraction_numerical': 0.03373702422145329, 'mean_word_length': 3.873551106427819, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '7191620', 'n_tokens_mistral': 1905, 'n_tokens_neox': 1708, 'n_words': 359}