<jupyter_start><jupyter_text>OHNOLOG DB candidatesUsing candidates from http://ohnologs.curie.fr/Question: Are ohnologs more likely to be protein complexes?<jupyter_code>import numpy as np
import pandas as pd
from scipy.stats import fisher_exact
import json
def read_gid_to_chr(infile):
    gid_to_chr = {}
    with open(infile, "r") as handle:
        for line in handle:
            if line.startswith("Ensembl"):
                continue
            elif line.startswith("ENS"):
                line = line.rstrip().split()
                gid_to_chr[line[0]] = line[1]
    return gid_to_chr

gid_to_chr = read_gid_to_chr("Gallus_gallus.75.gid.chr.tsv")
pid_to_chr = read_gid_to_chr("Gallus_gallus.75.pid.chr.tsv")

# Get a list of Z linked gene IDs
Z_genes = [g for g, pos in gid_to_chr.items() if pos == "Z"]
print("Genes on the Z: ",len(Z_genes))
def read_protein_complex_json(json_infile):
    with open(json_infile, "r") as infile:  
        data = json.load(infile)
        return data

protein_complexes = read_protein_complex_json("2015-05-14-ChickenComplexes.json")
print("Number of protein complexes:", len(protein_complexes))
Z_protein_complexes = []
all_protein_complexes = []
for c in protein_complexes:
    chicken_orthologs = protein_complexes[c]["chicken_orthologs"]
    if chicken_orthologs:
        for ortholog in chicken_orthologs:
            gid = ortholog["id"]
            pid = ortholog["protein_id"]
            if pid_to_chr[pid] == "Z":
                Z_protein_complexes.append(gid)
            all_protein_complexes.append(gid)
            
Z_protein_complexes = list(set(Z_protein_complexes))
all_protein_complexes = list(set(all_protein_complexes))
print("Number of unique protein complex genes on the Z chromosome:", len(Z_protein_complexes))
print("Number of unique protein complex genes in the chicken genome:", len(all_protein_complexes))
def read_ohnolog_pairs(infile):
    ohnolog_pairs = pd.read_csv(infile,  sep='\t')
    return ohnolog_pairs

def get_categories(ohnologs, Z_genes, protein_complexes):
    results={"COMPLEX_OHNO": [],
             "NO_COMPLEX_OHNO": [],
             "COMPLEX_NO_OHNO": [],
             "NO_COMPLEX_NO_OHNO": []
            }
    
    for g in Z_genes:
        
        if g in protein_complexes:
            if g in ohnologs:
                results["COMPLEX_OHNO"].append(g)
            
            else:
                results["COMPLEX_NO_OHNO"].append(g)
            
        else:
            if g in ohnologs:
                results["NO_COMPLEX_OHNO"].append(g)
            else:
                results["NO_COMPLEX_NO_OHNO"].append(g)
                        
    print("OHNO  NO-OHNO")
    print("COMPLEX", len(results["COMPLEX_OHNO"]), len(results["COMPLEX_NO_OHNO"]))
    print("NO-COMPLEX",len(results["NO_COMPLEX_OHNO"]), len(results["NO_COMPLEX_NO_OHNO"]))
    print (fisher_exact([[len(results["COMPLEX_OHNO"]),len(results["COMPLEX_NO_OHNO"])],
                        [len(results["NO_COMPLEX_OHNO"]), len(results["NO_COMPLEX_NO_OHNO"])]]))
    print("------")
    return results

ohnolog_curie_pairs = read_ohnolog_pairs("CHICKEN.Pairs.Relaxed.2R.txt")
ohno1 = list(ohnolog_curie_pairs["Ohnolog-1 Id"])
ohno2 = list(ohnolog_curie_pairs["Ohnolog-2 Id"])
ohnolog_curie_pairs_relaxed_ids = list(set(ohno1+ohno2))
print(len(ohnolog_curie_pairs_relaxed_ids))

Z_ohnologs_curie = []
for gid in ohnolog_curie_pairs_relaxed_ids:
    # Some genes in the DB are not in this genome release Ensembl 75
    if gid in gid_to_chr:
        if gid_to_chr[gid] == "Z":
            Z_ohnologs_curie.append(gid)
print(len(Z_ohnologs_curie))

dc_complex = get_categories(Z_ohnologs_curie, Z_genes, Z_protein_complexes)
dc_complex = get_categories(ohnolog_curie_pairs_relaxed_ids, gid_to_chr.keys(), all_protein_complexes)
print 410./(1914+410)
print 1931./(1931+12853)
736./(4135+736)
1605./(10632+1605)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11412487205731832, 'fraction_numerical': 0.017656090071647902, 'mean_word_length': 3.3773796192609185, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '583834', 'license': 'MIT', 'n_tokens_mistral': 1503, 'n_tokens_neox': 1381, 'n_words': 248, 'path': 'protein-complexes-corum/2015-08-24-DC-Curie-Ohnolog-protein-complexes.ipynb', 'repo_name': 'qfma/ohnologdc', 'size': '3908'}