# Path: indra/sources/acsn/processor.py
# class AcsnProcessor:
#     """Processes Atlas of cancer signalling network (ACSN) relationships
#     into INDRA statements
# 
#     Attributes
#     ----------
#     relations_df : pandas.DataFrame
#         A tab-separated data frame which consists of binary relationship between
#         proteins with PMIDs.
#     correspondence_dict : dict
#         A dictionary with correspondences between ACSN entities and their
#         HGNC symbols.
#     """
#     def __init__(self, relations_df, correspondence_dict):
#         """Constructor for AcsnProcessor class"""
#         self.relations_df = relations_df
#         self.correspondence_dict = correspondence_dict
#         self.fplx_lookup = _make_famplex_lookup()
#         self.statements = []
# 
#     def extract_statements(self):
#         """Return INDRA Statements Extracted from ACSN relations."""
#         for _, row in self.relations_df.iterrows():
#             acsn_agent_a, stmt_types, acsn_agent_b, pmids = list(row)
#             stmt_type = get_stmt_type(stmt_types)
#             if stmt_type:
#                 agent_a = self.get_agent(acsn_agent_a)
#                 agent_b = self.get_agent(acsn_agent_b)
#                 if agent_a and agent_b:
#                     if str(pmids) == 'nan':
#                         evs = [Evidence(source_api='acsn')]
# 
#                     else:
#                         evs = [Evidence(source_api='acsn', pmid=pmid)
#                                for pmid in pmids.split(';')]
# 
#                     if stmt_type == Complex:
#                         stmt = stmt_type([agent_a, agent_b], evidence=evs)
#                     else:
#                         stmt = stmt_type(agent_a, agent_b, evidence=evs)
# 
#                     self.statements.append(stmt)
# 
#     def get_agent(self, acsn_agent: str) -> Union[Agent, None]:
#         """Return an INDRA Agent corresponding to an ACSN agent.
# 
#         Parameters
#         ----------
#         acsn_agent :
#             Agent extracted from the relations statement data frame
# 
#         Returns
#         -------
#         :
#             Returns INDRA agent with HGNC or FamPlex ID in db_refs. If there
#             are no groundings available, we return None.
#         """
#         mapping = self.correspondence_dict.get(acsn_agent)
#         if not mapping:
#             return None
#         if len(mapping) == 1:
#             hgnc_id = get_hgnc_id(mapping[0])
#             if hgnc_id:
#                 db_refs = {'HGNC': hgnc_id}
#                 return get_standard_agent(mapping[0], db_refs=db_refs)
#         else:
#             fplx_rel = self.fplx_lookup.get(tuple(sorted(
#                 self.correspondence_dict[acsn_agent])))
#             if fplx_rel:
#                 db_refs = {'FPLX': fplx_rel}
#                 return get_standard_agent(fplx_rel, db_refs=db_refs)
#         return None


from typing import Mapping
from .processor import AcsnProcessor
import pandas
import requests
__all__ = ['process_from_web', 'process_files', 'process_df']



ACSN_URL = 'https://acsn.curie.fr/ACSN2/downloads/'
ACSN_RELATIONS_URL = ACSN_URL + \
                     'ACSN2_binary_relations_between_proteins_with_PMID.txt'
ACSN_CORRESPONDENCE_URL = ACSN_URL + 'ACSN2_HUGO_Correspondence.gmt'


def process_from_web() -> AcsnProcessor:
    """Process ACSN data directly from the web.

    Returns
    -------
    :
        A processor with a list of INDRA statements that were extracted
        in its statements attribute.
    """
    relations_df = pandas.read_csv(ACSN_RELATIONS_URL, sep='\t')
    correspondence_dict = _transform_gmt(
        requests.get(ACSN_CORRESPONDENCE_URL).text.split('\n'))
    return process_df(relations_df, correspondence_dict)


def process_files(relations_path: str, correspondence_path: str) -> \

# Path: indra/sources/acsn/processor.py
# class AcsnProcessor:
#     """Processes Atlas of cancer signalling network (ACSN) relationships
#     into INDRA statements
# 
#     Attributes
#     ----------
#     relations_df : pandas.DataFrame
#         A tab-separated data frame which consists of binary relationship between
#         proteins with PMIDs.
#     correspondence_dict : dict
#         A dictionary with correspondences between ACSN entities and their
#         HGNC symbols.
#     """
#     def __init__(self, relations_df, correspondence_dict):
#         """Constructor for AcsnProcessor class"""
#         self.relations_df = relations_df
#         self.correspondence_dict = correspondence_dict
#         self.fplx_lookup = _make_famplex_lookup()
#         self.statements = []
# 
#     def extract_statements(self):
#         """Return INDRA Statements Extracted from ACSN relations."""
#         for _, row in self.relations_df.iterrows():
#             acsn_agent_a, stmt_types, acsn_agent_b, pmids = list(row)
#             stmt_type = get_stmt_type(stmt_types)
#             if stmt_type:
#                 agent_a = self.get_agent(acsn_agent_a)
#                 agent_b = self.get_agent(acsn_agent_b)
#                 if agent_a and agent_b:
#                     if str(pmids) == 'nan':
#                         evs = [Evidence(source_api='acsn')]
# 
#                     else:
#                         evs = [Evidence(source_api='acsn', pmid=pmid)
#                                for pmid in pmids.split(';')]
# 
#                     if stmt_type == Complex:
#                         stmt = stmt_type([agent_a, agent_b], evidence=evs)
#                     else:
#                         stmt = stmt_type(agent_a, agent_b, evidence=evs)
# 
#                     self.statements.append(stmt)
# 
#     def get_agent(self, acsn_agent: str) -> Union[Agent, None]:
#         """Return an INDRA Agent corresponding to an ACSN agent.
# 
#         Parameters
#         ----------
#         acsn_agent :
#             Agent extracted from the relations statement data frame
# 
#         Returns
#         -------
#         :
#             Returns INDRA agent with HGNC or FamPlex ID in db_refs. If there
#             are no groundings available, we return None.
#         """
#         mapping = self.correspondence_dict.get(acsn_agent)
#         if not mapping:
#             return None
#         if len(mapping) == 1:
#             hgnc_id = get_hgnc_id(mapping[0])
#             if hgnc_id:
#                 db_refs = {'HGNC': hgnc_id}
#                 return get_standard_agent(mapping[0], db_refs=db_refs)
#         else:
#             fplx_rel = self.fplx_lookup.get(tuple(sorted(
#                 self.correspondence_dict[acsn_agent])))
#             if fplx_rel:
#                 db_refs = {'FPLX': fplx_rel}
#                 return get_standard_agent(fplx_rel, db_refs=db_refs)
#         return None


# Path: indra/sources/acsn/api.py
from typing import Mapping
from .processor import AcsnProcessor
import pandas
import requests

__all__ = ['process_from_web', 'process_files', 'process_df']



ACSN_URL = 'https://acsn.curie.fr/ACSN2/downloads/'
ACSN_RELATIONS_URL = ACSN_URL + \
                     'ACSN2_binary_relations_between_proteins_with_PMID.txt'
ACSN_CORRESPONDENCE_URL = ACSN_URL + 'ACSN2_HUGO_Correspondence.gmt'


def process_from_web() -> AcsnProcessor:
    """Process ACSN data directly from the web.

    Returns
    -------
    :
        A processor with a list of INDRA statements that were extracted
        in its statements attribute.
    """
    relations_df = pandas.read_csv(ACSN_RELATIONS_URL, sep='\t')
    correspondence_dict = _transform_gmt(
        requests.get(ACSN_CORRESPONDENCE_URL).text.split('\n'))
    return process_df(relations_df, correspondence_dict)


def process_files(relations_path: str, correspondence_path: str) -> \

        AcsnProcessor: