Project: s41467-024-47569-x | Function: combine_lm_transmem_and_proteins (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Complex transmembrane domain processing algorithm that segments membrane proteins into topological regions and assigns cross-links to appropriate subcellular compartments based on residue positions

**KEY TERMS:** {
  "transmembrane_regions": "transmembrane domain boundaries from UniProt",
  "crosslinks_before_tm": "cross-links N-terminal to transmembrane region",
  "crosslinks_after_tm": "cross-links C-terminal to transmembrane region",
  "crosslinks_in_tm": "cross-links within transmembrane domain",
  "subcellular_location": "compartment assignment for protein regions"
}

**CONTEXT CODE:** 
    new_data = pd.DataFrame({'gene': gene_list, 'protein': protein_list,
                             'subcellular_location': subcellular_location_list})

    return new_data


# function assigning location markers if proteins are in one location and dont have transmembrane region
def get_transmembrane_information(data, uniprot):
    """
    method extracting transmembrane information for proteins and in
    case of a membrane proteins splitting it into rows depending on
    the number of transmembrane domains
    :param data:
    :param uniprot:
    :return: new_data
    """
    gene_list = []
    protein_list = []
    transmembrane_list = []

    for i in data.index:
        protein_name = re.sub("^[^\\|]*\\|([^\\|]+)\\|.*$", "\\1", data['Protein1'][i])

        # skip if protein not in uniprot list
        if (uniprot['Entry'].eq(protein_name).any()) is False:
            continue

        if len(uniprot.loc[uniprot.Entry == protein_name, 'Transmembrane']) == 0:
            continue

        transmem_uniprot = uniprot.loc[uniprot.Entry == protein_name, 'Transmembrane'].values[0]

        if pd.isnull(transmem_uniprot):
            continue
        else:
            transmem = re.findall("TRANSMEM (.+?)\\;", transmem_uniprot)

            # gene_a, protein_a, crosslinks_ab, subcellular_location, transmembrane
            gene_list.append(data.iloc[i]['gene_a'])
            protein_list.append(protein_name)
            transmembrane_list.append(transmem)

    new_data = pd.DataFrame({'gene': gene_list, 'protein': protein_list,
                             'transmembrane': transmembrane_list})

    return new_data


# function splitting proteins+crosslinks into multiple rows if they have transmembrane regions
def combine_lm_transmem_and_proteins(data, lm_data, transmem_data):
    """
    method combining subcellular location and transmembrane domains
    for proteins; a unique subcellular location signals a localization
    marker
    :param data:
    :param lm_data:
    :param transmem_data:
    :return: new date
    """
    # MASKED: Complex transmembrane domain processing algorithm that segments membrane proteins into topological regions and assigns cross-links to appropriate subcellular compartments based on residue positions
    raise NotImplementedError("This function is masked for testing purposes.")

def add_topology_information(data,uniprot):
    """
    add topology information for mitochondrion membrane proteins
    :param data:
    :param uniprot:
    :return: new_data
    """
    protein_helper_list = []

    gene_list = []
    protein_list = []
    crosslinks_list = []
    subcellular_location_list = []
    topology_list = []
    transmembrane_list = []
    is_lm_list = []

    data['transmembrane'] = data['transmembrane'].fillna("")
    data['subcellular_location'] = data['subcellular_location'].fillna("")
     # TODO its not returning any membrane proteins as lm
    for i in data.index:
        is_lm = ""
        protein = data.iloc[i]['protein']
        if 'NDUFS8' == data.iloc[i]['gene']:
            print()
        if protein in protein_helper_list:
            continue
        else:
            protein_helper_list.append(protein)

        sub = data.loc[data['protein'] == protein]
        number_tm_regions = len(sub[sub['transmembrane'] != ''])

        # if no mito protein, continue
        mask = [bool(re.search(p, s)) for p, s in zip('itoch',sub['subcellular_location'])]

        # only add topology for mito proteins with unique subcellular location
        # if no transmembrane regions, dont consider topological domains
        if sum(mask) == 0:
            gene_list.extend(sub['gene'].tolist())
            protein_list.extend(sub['protein'].tolist())
            crosslinks_list.extend(sub['crosslinks'].tolist())
            subcellular_location_list.extend(sub['subcellular_location'].tolist())
            topology_list.extend([""] * len(sub.index))
            transmembrane_list.extend(sub['transmembrane'].tolist())
            is_lm_list.extend(["FALSE"] * len(sub.index))
            continue

        if len(sub.index) < 2:
            if sub['subcellular_location'].str.contains('membrane protein').any():
                gene_list.extend(sub['gene'].tolist())
                protein_list.extend(sub['protein'].tolist())
                crosslinks_list.extend(sub['crosslinks'].tolist())
                subcellular_location_list.extend(sub['subcellular_location'].tolist())
                topology_list.extend([""]*len(sub.index))
                transmembrane_list.extend(sub['transmembrane'].tolist())
                is_lm_list.extend(["FALSE"] * len(sub.index))
                continue
            else:
                gene_list.extend(sub['gene'].tolist())
                protein_list.extend(sub['protein'].tolist())
                crosslinks_list.extend(sub['crosslinks'].tolist())
                subcellular_location_list.extend(sub['subcellular_location'].tolist())
                topology_list.extend([""] * len(sub.index))
                transmembrane_list.extend(sub['transmembrane'].tolist())
                is_lm_list.extend(sub['is_localization_marker'].tolist())
                continue

        if number_tm_regions > 0 and len(uniprot.loc[uniprot['Entry'] == protein, 'Topological domain']) == 0:
            gene_list.extend(sub['gene'].tolist())
            protein_list.extend(sub['protein'].tolist())
            crosslinks_list.extend(sub['crosslinks'].tolist())
            subcellular_location_list.extend(sub['subcellular_location'].tolist())
            topology_list.extend([""] * len(sub.index))
            transmembrane_list.extend(sub['transmembrane'].tolist())
            is_lm_list.extend(["FALSE"] * len(sub.index))
            continue

        topology_uniprot = uniprot.loc[uniprot['Entry'] == protein, 'Topological domain'].values[0]

        # if is membrane protein and does not have topology information
        if (number_tm_regions > 0 and pd.isnull(topology_uniprot)) or \
                (number_tm_regions > 0 and topology_uniprot == ""):
            gene_list.extend(sub['gene'].tolist())
            protein_list.extend(sub['protein'].tolist())
            crosslinks_list.extend(sub['crosslinks'].tolist())
            subcellular_location_list.extend(sub['subcellular_location'].tolist())


Complete the function implementation replacing "raise NotImplementedError".