<jupyter_start><jupyter_text>Distribution of publication count for Dmel TF genesFor each TF gene, count the number of *curated* publications, using data from GO and Monarch<jupyter_code>import ontobio.golr.golr_associations as ga
# Fetch all Dmel TF genes
DNA_BINDING_TF = 'GO:0003700'
DMEL = 'NCBITaxon:7227'
tf_genes = ga.get_subjects_for_object(object=DNA_BINDING_TF, subject_taxon=DMEL)
len(tf_genes)
# Routine to go to GO and Monarch to fetch all annotations for a gene
def get_pubs_for_gene(g):
    
    # Monarch
    r = ga.search_associations(subject=g, rows=-1)
    pubs = set()
    for a in r['associations']:
        pl = a['publications']
        if pl is not None:
            pubs.update([p['id'] for p in pl if p['id'].startswith('PMID')])
    
    # GO
    r = ga.search_associations(subject=g, rows=-1, object_category='function')
    for a in r['associations']:
        pl = a['reference']
        if pl is not None:
            pubs.update([p for p in pl if p.startswith('PMID')])
   
    return pubs
    
len(get_pubs_for_gene(tf_genes[0]))
# find all gene,numberOfPub pairs
pairs = []
for g in tf_genes:
    np = len(get_pubs_for_gene(g))
    pairs.append((g,np))
    
# Check
vals = [np for _,np in pairs]
vals[0:5]
# Check
tf_genes_with_no_pubs = [g for g,np in pairs if np==0]
tf_genes_with_no_pubs
# genes with fewer than 5 pubs
[g for g,np in pairs if np < 5]
import matplotlib.pyplot as plt
%matplotlib inline

# Histogram
plt.hist(vals, bins=40)
plt.ylabel('No of genes')
plt.xlabel('No of pubs')
plt.show()
# Save results
import csv
with open('gene-pubs.csv', 'w', newline='') as csvfile:
    w = csv.writer(csvfile, delimiter=',')
    for g,np in pairs:
        w.writerow([g,np])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12011494252873563, 'fraction_numerical': 0.01206896551724138, 'mean_word_length': 3.7568306010928962, 'pattern_counts': {'":': 0, '<': 6, '<?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': '668136', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 681, 'n_tokens_neox': 647, 'n_words': 183, 'path': 'notebooks/TF_Pub_Analysis.ipynb', 'repo_name': 'alliance-genome/ontobio', 'size': '1740'}