negative_phenotype_total = 0 owners = set() studies = set() fields_used = set() for patient_id in patient_ids: stderr.write(str(count) + '\r') count += 1 owner = bot.get_owner(patient_id) or '' study = bot.get_study(patient_id) or '' if ((len(wanted_users) == 0 or owner.lower() in wanted_users) and (len(wanted_studies) == 0 or study.lower() in wanted_studies)): patient_total += 1 owners.add(owner) studies.add(study) patient = bot.get(patient_id) if patient['phenotype']: positive_phenotype_total += len(patient['phenotype'].split('|')) if patient['negative_phenotype']: negative_phenotype_total += len(patient['negative_phenotype'].split('|')) for key, value in patient.items(): if value: #print(key + ': ' + value) fields_used.add(key) print('Owned patients: ' + str(patient_total)) print('Average positive phenotypes per patient: ' + str(positive_phenotype_total / patient_total)) print('Average negative phenotypes per patient: ' + str(negative_phenotype_total / patient_total)) print('Owners: ' + str(len(owners)) + ', ' + str(sorted(owners))) print('Study forms: ' + str(len(studies)) + ', ' + str(sorted(studies))) print('Fields used at least once: ' + str(len(fields_used)) + ', ' + str(sorted(fields_used)))
patient_ids = bot.list(study, owner) stderr.write('Looking through ' + str(len(patient_ids)) + ' patient records...\n') stderr.write('\n') stdout.write('#FID\tIID\tPAT\tMAT\tSEX\tPHENOTYPE\n') writer = csv.writer(sys.stdout, delimiter='\t') fid = study if study else '0' for patient_id in patient_ids: stderr.write(str(count) + '\r') count += 1 patient = bot.get(patient_id) iid = patient['external_id'] pat = '0' mat = '0' if patient.get('gender') == 'M': sex = 1 elif patient.get('gender') == 'F': sex = 2 else: sex = 0 if patient.get('case_or_control') == 'case': phenotype = 2 elif patient.get('case_or_control') == 'control': phenotype = 1 else: phenotype = 0