File size: 13,052 Bytes
032c0ea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
import pandas as pd
import re
def load_indications(file_path):
"""
Load indications from a TSV file.
"""
try:
# Read the TSV file
df = pd.read_csv(file_path, sep='\t', na_values=['', 'NA', 'N/A'])
return df
except Exception as e:
print(f"Error loading file: {e}")
return None
def map_indication_to_organ(indication, areas=None):
"""
Map a medical indication to an organ.
Returns the organ name if a confident mapping exists, otherwise None.
"""
# List of target organs
target_organs = [
'Bowel', 'Lung', 'Esophagus/Stomach', 'Pancreas', 'Skin',
'Uterus', 'Breast', 'Ovary/Fallopian Tube', 'Cervix',
'CNS/Brain', 'Liver', 'Kidney', 'Peripheral Nervous System',
'Vulva/Vagina', 'Bladder/Urinary Tract'
]
# Dictionary mapping indication keywords to organs
keyword_to_organ = {
# Bowel related
'bowel': 'Bowel',
'intestinal': 'Bowel',
'colon': 'Bowel',
'colorectal': 'Bowel',
'rectal': 'Bowel',
'anus': 'Bowel',
'colitis': 'Bowel',
'crohn': 'Bowel',
'inflammatory bowel': 'Bowel',
'diverticulitis': 'Bowel',
'ileus': 'Bowel',
'short bowel': 'Bowel',
# Lung related
'lung': 'Lung',
'pulmonary': 'Lung',
'respiratory': 'Lung',
'bronch': 'Lung',
'pneumonia': 'Lung',
'emphysema': 'Lung',
'asthma': 'Lung',
'chronic obstructive pulmonary': 'Lung',
'idiopathic pulmonary fibrosis': 'Lung',
# Esophagus/Stomach related
'esophag': 'Esophagus/Stomach',
'stomach': 'Esophagus/Stomach',
'gastric': 'Esophagus/Stomach',
'gastroesophageal': 'Esophagus/Stomach',
'duodenal': 'Esophagus/Stomach',
'peptic ulcer': 'Esophagus/Stomach',
'gastritis': 'Esophagus/Stomach',
'barrett': 'Esophagus/Stomach',
# Pancreas related
'pancrea': 'Pancreas',
'exocrine pancreatic': 'Pancreas',
# Skin related
'skin': 'Skin',
'dermat': 'Skin',
'cutaneous': 'Skin',
'melanoma': 'Skin',
'psoriasis': 'Skin',
'eczema': 'Skin',
'acne': 'Skin',
'rosacea': 'Skin',
'alopecia': 'Skin',
'vitiligo': 'Skin',
'keratosis': 'Skin',
'keloid': 'Skin',
'ichthyosis': 'Skin',
'pruritus': 'Skin',
'urticaria': 'Skin',
'pemphigus': 'Skin',
'pemphigoid': 'Skin',
'scleroderma': 'Skin',
# Uterus related
'uter': 'Uterus',
'endometri': 'Uterus',
'myometri': 'Uterus',
'leiomyoma': 'Uterus',
# Breast related
'breast': 'Breast',
'mammary': 'Breast',
# Ovary/Fallopian tube related
'ovar': 'Ovary/Fallopian Tube',
'fallopian': 'Ovary/Fallopian Tube',
'polycystic ovary': 'Ovary/Fallopian Tube',
# Cervix related
'cervix': 'Cervix',
'cervical': 'Cervix',
# CNS/Brain related
'brain': 'CNS/Brain',
'central nervous': 'CNS/Brain',
'cns': 'CNS/Brain',
'cerebr': 'CNS/Brain',
'alzheimer': 'CNS/Brain',
'parkinson': 'CNS/Brain',
'glioma': 'CNS/Brain',
'glioblastoma': 'CNS/Brain',
'medulloblastoma': 'CNS/Brain',
'meningioma': 'CNS/Brain',
'epilepsy': 'CNS/Brain',
'dementia': 'CNS/Brain',
'encephalitis': 'CNS/Brain',
'encephalopathy': 'CNS/Brain',
'huntington': 'CNS/Brain',
'multiple sclerosis': 'CNS/Brain',
'stroke': 'CNS/Brain',
# Liver related
'liver': 'Liver',
'hepat': 'Liver',
'biliary': 'Liver',
'cholang': 'Liver',
'cirrhosis': 'Liver',
'fatty liver': 'Liver',
# Kidney related
'kidney': 'Kidney',
'renal': 'Kidney',
'nephro': 'Kidney',
'nephri': 'Kidney',
'glomerulo': 'Kidney',
'polycystic kidney': 'Kidney',
# Peripheral Nervous System related
'peripheral nervous': 'Peripheral Nervous System',
'neuropathy': 'Peripheral Nervous System',
'neuralgia': 'Peripheral Nervous System',
# Vulva/Vagina related
'vulva': 'Vulva/Vagina',
'vagina': 'Vulva/Vagina',
'vulvar': 'Vulva/Vagina',
'vaginal': 'Vulva/Vagina',
'vaginitis': 'Vulva/Vagina',
# Bladder/Urinary Tract related
'bladder': 'Bladder/Urinary Tract',
'urinary': 'Bladder/Urinary Tract',
'urethral': 'Bladder/Urinary Tract',
'urethra': 'Bladder/Urinary Tract',
'cystitis': 'Bladder/Urinary Tract',
}
# Indications that are too general or affect multiple systems
too_general = [
'Neoplasms', 'Inflammation', 'Pain', 'Infection', 'Fever',
'Autoimmune Diseases', 'Immune System Diseases',
'Nervous System Diseases', 'Metabolic Diseases',
'Arthritis', 'Diabetes Mellitus', 'Hypertension',
'Depression', 'Anxiety Disorders', 'HIV Infections',
'Sepsis', 'Wound Healing', 'Cachexia', 'Fatigue',
'Nausea', 'Vomiting', 'Multiple Myeloma', 'Leukemia', 'Lymphoma'
]
# Specific disease to organ mapping
specific_disease_mapping = {
'Ulcerative Colitis': 'Bowel',
'Crohn Disease': 'Bowel',
'Asthma': 'Lung',
'Psoriasis': 'Skin',
'Lupus Erythematosus, Cutaneous': 'Skin',
'Lupus Nephritis': 'Kidney',
'Alzheimer Disease': 'CNS/Brain',
'Parkinson Disease': 'CNS/Brain',
'Amyotrophic Lateral Sclerosis': 'CNS/Brain',
'Huntington Disease': 'CNS/Brain',
'Non-alcoholic Fatty Liver Disease': 'Liver',
'Carcinoma, Non-Small-Cell Lung': 'Lung',
'Small Cell Lung Carcinoma': 'Lung',
'Liver Cirrhosis': 'Liver',
'Liver Neoplasms': 'Liver',
'Liver Cirrhosis, Biliary': 'Liver',
'Breast Neoplasms': 'Breast',
'Ovarian Neoplasms': 'Ovary/Fallopian Tube',
'Brain Neoplasms': 'CNS/Brain',
'Brain Injuries': 'CNS/Brain',
'Brain Injuries, Traumatic': 'CNS/Brain',
'Brain Ischemia': 'CNS/Brain',
'Pancreatic Neoplasms': 'Pancreas',
'Urinary Bladder Neoplasms': 'Bladder/Urinary Tract',
'Stomach Neoplasms': 'Esophagus/Stomach',
'Uterine Cervical Neoplasms': 'Cervix',
'Endometrial Neoplasms': 'Uterus',
'Kidney Neoplasms': 'Kidney',
'Colorectal Neoplasms': 'Bowel',
'Inflammatory Bowel Diseases': 'Bowel',
'COVID-19': 'Lung',
'Severe Acute Respiratory Syndrome': 'Lung',
'Pulmonary Disease, Chronic Obstructive': 'Lung',
'Idiopathic Pulmonary Fibrosis': 'Lung',
'Respiratory Distress Syndrome': 'Lung',
'Esophageal Neoplasms': 'Esophagus/Stomach',
'Acne Vulgaris': 'Skin',
'Psoriatic Arthritis': 'Skin',
'Alopecia': 'Skin',
'Alopecia Areata': 'Skin',
'Vitiligo': 'Skin',
'Rosacea': 'Skin',
'Hidradenitis Suppurativa': 'Skin',
'Pemphigus': 'Skin',
'Pemphigoid, Bullous': 'Skin',
'Scleroderma, Systemic': 'Skin',
'Scleroderma, Diffuse': 'Skin',
'Scleroderma, Limited': 'Skin',
'Fallopian Tube Neoplasms': 'Ovary/Fallopian Tube',
'Polycystic Ovary Syndrome': 'Ovary/Fallopian Tube',
'Endometriosis': 'Uterus',
'Leiomyoma': 'Uterus',
'Carcinoma, Squamous Cell': 'Skin',
'Neoplasms, Basal Cell': 'Skin',
'Melanoma': 'Skin',
'Glioblastoma': 'CNS/Brain',
'Medulloblastoma': 'CNS/Brain',
'Irritable Bowel Syndrome': 'Bowel',
'Diabetic Nephropathies': 'Kidney',
'Diabetic Neuropathies': 'Peripheral Nervous System',
'Multiple Sclerosis': 'CNS/Brain',
}
# First, check if the indication is too general
if indication in too_general:
return None
# Check if the indication is in our specific disease mapping
if indication in specific_disease_mapping:
return specific_disease_mapping[indication]
# Check for keyword matches
indication_lower = indication.lower()
for keyword, organ in keyword_to_organ.items():
if keyword in indication_lower:
return organ
# Use the 'areas' context for additional mapping
if areas:
areas_lower = str(areas).lower()
if 'digestive' in areas_lower:
if any(term in indication_lower for term in ['bowel', 'colon', 'rectal', 'intestin']):
return 'Bowel'
elif any(term in indication_lower for term in ['liver', 'hepat', 'biliary']):
return 'Liver'
elif 'pancrea' in indication_lower:
return 'Pancreas'
elif any(term in indication_lower for term in ['stomach', 'gastric', 'esophag']):
return 'Esophagus/Stomach'
elif 'respiratory' in areas_lower:
return 'Lung'
elif 'neurology' in areas_lower:
if 'peripheral' in indication_lower:
return 'Peripheral Nervous System'
else:
return 'CNS/Brain'
elif 'dermatology' in areas_lower:
return 'Skin'
elif 'oncology' in areas_lower:
# For oncology, need more specific organ information
if any(term in indication_lower for term in ['lung', 'pulmonary', 'bronch']):
return 'Lung'
elif any(term in indication_lower for term in ['brain', 'glioma', 'cerebr']):
return 'CNS/Brain'
elif any(term in indication_lower for term in ['liver', 'hepatic']):
return 'Liver'
elif any(term in indication_lower for term in ['skin', 'melanoma', 'basal cell']):
return 'Skin'
elif any(term in indication_lower for term in ['breast', 'mammary']):
return 'Breast'
elif any(term in indication_lower for term in ['colon', 'rectal', 'colorectal']):
return 'Bowel'
elif any(term in indication_lower for term in ['pancreas', 'pancreatic']):
return 'Pancreas'
elif any(term in indication_lower for term in ['kidney', 'renal']):
return 'Kidney'
elif any(term in indication_lower for term in ['bladder', 'urinary']):
return 'Bladder/Urinary Tract'
elif any(term in indication_lower for term in ['cervix', 'cervical']):
return 'Cervix'
elif any(term in indication_lower for term in ['uterus', 'uterine', 'endometri']):
return 'Uterus'
elif any(term in indication_lower for term in ['ovary', 'ovarian', 'fallopian']):
return 'Ovary/Fallopian Tube'
# If no confident mapping is found, return None
return None
def main():
# Load indications from TSV file
file_path = '../genetic_support/data/indic.tsv' # Update this path if necessary
indications_df = load_indications(file_path)
indications_df = indications_df.dropna(subset=['indication_mesh_term'])
if indications_df is not None:
# Add a new column for organ mapping
indications_df['organ'] = indications_df.apply(
lambda row: map_indication_to_organ(row['indication_mesh_term'], row.get('areas')),
axis=1
)
# Display indications with their mapped organs
mapped_df = indications_df[['indication_mesh_term', 'organ']]
all_mappings = mapped_df.copy() # Save all mappings for reference
# Show only confident mappings
mapped_df = mapped_df[mapped_df['organ'].notnull()]
print(f"Successfully mapped {len(mapped_df)} out of {len(indications_df)} indications to organs.")
print(mapped_df.head(20)) # Display first 20 mappings
# Save the results to CSV files
mapped_df.to_csv('indication_to_organ_mapping_confident.tsv', index=False, sep='\t')
all_mappings.to_csv('indication_to_organ_mapping_all.tsv', index=False, sep='\t')
print("Mappings saved to 'indication_to_organ_mapping_confident.tsv'")
# Summary of organ distribution
if not mapped_df.empty:
organ_counts = mapped_df['organ'].value_counts()
print("\nDistribution of indications across organs:")
print(organ_counts)
# Indications that couldn't be confidently mapped
unmapped = indications_df[indications_df['organ'].isnull()]
print(f"\nNumber of indications that couldn't be confidently mapped: {len(unmapped)}")
if __name__ == "__main__":
main() |