alethiotx.artemis.utils
Artemis: public knowledge graphs enable accessible and scalable drug target discovery.
Github Repository
1""" 2**Artemis**: public knowledge graphs enable accessible and scalable drug target discovery. 3 4Github Repository 5----------------- 6 7`GitHub - alethiotx/artemis-paper <https://github.com/alethiotx/artemis-paper>`_ 8""" 9 10def find_overlapping_genes(genes: list, overlap = 1, common_genes = []): 11 """ 12 Find genes that overlap across multiple gene lists. 13 14 :param genes: A list of gene lists to check for overlapping genes. 15 :type genes: list 16 :param overlap: Minimum number of lists a gene must appear in to be considered overlapping, defaults to 1. 17 :type overlap: int 18 :param common_genes: Initial list of common genes to include in the result, defaults to []. 19 :type common_genes: list 20 :return: A list of genes that appear in more than ``overlap`` lists but not in all lists. 21 :rtype: list 22 23 **Example** 24 >>> genes_list = [['gene1', 'gene2'], ['gene2', 'gene3'], ['gene2', 'gene4']] 25 >>> find_overlapping_genes(genes_list, overlap=1) 26 ['gene2'] 27 28 .. note:: 29 30 Genes that appear in all input lists are excluded from the result by default. 31 To include them, modify the condition ``d[i] < len(genes)`` to ``d[i] <= len(genes)``. 32 33 """ 34 d = {} 35 overlapping_genes = common_genes.copy() 36 37 for i in [x for y in genes for x in y]: 38 if i in d.keys(): 39 d[i]=d[i]+1 40 else: 41 d[i]=1 42 for i in d.keys(): 43 if d[i]>overlap and d[i] < len(genes): # the second condition excludes genes present in all lists, if you want to include those, change < to <=, or remove the condition entirely 44 overlapping_genes.append(i) 45 return overlapping_genes 46 47# run when file is directly executed 48if __name__ == '__main__': 49 print("Artemis module. Run tests or examples here.") 50 # # 'Breast Cancer', 51 # # 'Lung Cancer', 52 # # 'Prostate Cancer', 53 # # 'Bowel Cancer', 54 # # 'Melanoma', 55 # # 'Diabetes Mellitus Type 2', 56 # # 'Cardiovascular Disease', 57 # df = get_pathway_genes("acute myeloid leukemia") 58 # print(df.loc["FLT3", ["gene_count", "rank"]]) 59 # breast, lung, prostate, melanoma, bowel, diabetes, cardiovascular = load_clinical_scores(date="2025-11-11") 60 # print('Clinical scores:\n\n') 61 # print([breast, lung, prostate, melanoma, bowel, diabetes, cardiovascular]) 62 # print('All target genes:\n\n') 63 # known_targets = get_all_targets([breast, lung, prostate, melanoma, bowel, diabetes, cardiovascular]) 64 # print(known_targets) 65 # print('Cut clinical scores:\n\n') 66 # print(cut_clinical_scores([breast, lung, prostate, melanoma, bowel, diabetes, cardiovascular], lowest_score = 10)) 67 # breast_pg, lung_pg, prostate_pg, melanoma_pg, bowel_pg, diabetes_pg, cardiovascular_pg = load_pathway_genes(date='2025-09-15', n=50) 68 # print('Uniquified clinical scores:\n\n') 69 # print(uniquify_clinical_scores([breast, lung, prostate, melanoma, bowel, diabetes, cardiovascular])) 70 # print('Uniquified pathway genes:\n\n') 71 # print(uniquify_pathway_genes([breast_pg, lung_pg, prostate_pg, melanoma_pg, bowel_pg, diabetes_pg, cardiovascular_pg])) 72 # print(prepare_upset(breast, lung, prostate, melanoma, bowel, diabetes, cardiovascular, mode='ct')) 73 74 # # X is always bigger than y!!! 75 # X = DataFrame({ 76 # 'term1' : [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 0, 0, 1, 1, 2, 2, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 0, 0, 1, 1, 2, 2], 77 # 'term2' : [1, 2, 3, 4, 5, 0, 0, 1, 1, 2, 2, 2, 3, 4, 5, 6, 5, 7, 2, 9, 2, 1, 1, 2, 3, 4, 5, 0, 0, 1, 1, 2, 2, 2, 3, 4, 5, 6, 5, 7, 2, 9, 2, 1], 78 # 'term3' : [2, 3, 4, 5, 6, 5, 7, 2, 9, 2, 1, 3, 4, 5, 6, 7, 4, 5, 0, 0, 1, 2, 2, 3, 4, 5, 6, 5, 7, 2, 9, 2, 1, 3, 4, 5, 6, 7, 4, 5, 0, 0, 1, 2], 79 # 'term4' : [3, 4, 5, 6, 7, 4, 5, 0, 0, 1, 2, 9, 2, 1, 3, 4, 5, 6, 7, 5, 7, 2, 3, 4, 5, 6, 7, 4, 5, 0, 0, 1, 2, 9, 2, 1, 3, 4, 5, 6, 7, 5, 7, 2], 80 # 'term5' : [4, 5, 6, 7, 8, 6, 5, 7, 2, 9, 3, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, 4, 5, 6, 7, 8, 6, 5, 7, 2, 9, 3, 0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] 81 # }) 82 # y = DataFrame({ 83 # 'Target Gene' : ['gene1', 'gene2', 'gene3', 'gene4', 'gene5', 'gene6', 'gene7', 'gene8', 'gene9', 'gene10', 'gene11', 'gene12', 'gene13', 'gene14', 'gene15'], 84 # 'Clinical Score' : [1, 1, 1, 4, 5, 10, 5, 3, 2, 5, 1, 100, 200, 300, 400] 85 # }) 86 # # X is always bigger than y!!! 87 # X.index = ['gene1', 'gene2', 'gene3', 'gene4', 'gene5', 'gene6', 'gene7', 'gene8', 'gene9', 'gene10', 'gene11', 'gene12', 'gene13', 'gene14', 'gene15', 'gene16', 'gene17', 'gene18', 'gene19', 'gene20', 'gene21', 'gene22', 'gene23', 'gene24', 'gene25', 'gene26', 'gene27', 'gene28', 'gene29', 'gene30', 'gene31', 'gene32', 'gene33', 'gene34', 'gene35', 'gene36', 'gene37', 'gene38', 'gene39', 'gene40', 'gene41', 'gene42', 'gene43', 'gene44'] 88 # print('\nInput term matrix:') 89 # print(X) 90 # print('\nInput clinical scores:') 91 # print(y) 92 # print('\nCheck binning:') 93 # res = pre_model(X, y, bins = 5) 94 # print(res['y_encoded']) 95 96 # known_targets = ['gene32', 'gene33'] 97 98 # res = pre_model(X, y, known_targets = known_targets, bins = 5) 99 # print(res['y_encoded']) 100 101 # print('\nResults of cross validation pipeline:') 102 # print(cv_pipeline(X, y, n_iterations = 3)) 103 # print(cv_pipeline(X, y, y_slot = 'y_encoded', scoring = 'accuracy', n_iterations = 3))
def
find_overlapping_genes(genes: list, overlap=1, common_genes=[]):
11def find_overlapping_genes(genes: list, overlap = 1, common_genes = []): 12 """ 13 Find genes that overlap across multiple gene lists. 14 15 :param genes: A list of gene lists to check for overlapping genes. 16 :type genes: list 17 :param overlap: Minimum number of lists a gene must appear in to be considered overlapping, defaults to 1. 18 :type overlap: int 19 :param common_genes: Initial list of common genes to include in the result, defaults to []. 20 :type common_genes: list 21 :return: A list of genes that appear in more than ``overlap`` lists but not in all lists. 22 :rtype: list 23 24 **Example** 25 >>> genes_list = [['gene1', 'gene2'], ['gene2', 'gene3'], ['gene2', 'gene4']] 26 >>> find_overlapping_genes(genes_list, overlap=1) 27 ['gene2'] 28 29 .. note:: 30 31 Genes that appear in all input lists are excluded from the result by default. 32 To include them, modify the condition ``d[i] < len(genes)`` to ``d[i] <= len(genes)``. 33 34 """ 35 d = {} 36 overlapping_genes = common_genes.copy() 37 38 for i in [x for y in genes for x in y]: 39 if i in d.keys(): 40 d[i]=d[i]+1 41 else: 42 d[i]=1 43 for i in d.keys(): 44 if d[i]>overlap and d[i] < len(genes): # the second condition excludes genes present in all lists, if you want to include those, change < to <=, or remove the condition entirely 45 overlapping_genes.append(i) 46 return overlapping_genes
Find genes that overlap across multiple gene lists.
Parameters
- genes: A list of gene lists to check for overlapping genes.
- overlap: Minimum number of lists a gene must appear in to be considered overlapping, defaults to 1.
- common_genes: Initial list of common genes to include in the result, defaults to [].
Returns
A list of genes that appear in more than
overlaplists but not in all lists.
Example
>>> genes_list = [['gene1', 'gene2'], ['gene2', 'gene3'], ['gene2', 'gene4']]
>>> find_overlapping_genes(genes_list, overlap=1)
['gene2']
Genes that appear in all input lists are excluded from the result by default.
To include them, modify the condition d[i] < len(genes) to d[i] <= len(genes).