snp_eids = [] for ind, snp in enumerate(snps): print 'snp', snp['rs_id'] snp['chromosome'] = chr_map[snp['chromosome']] snp = store.create_entity('Snp', **snp) snp_eids.append(snp.eid) if sqlgen_store and ind and ind % 100000 == 0: store.flush() # Flush/Commit if sqlgen_store: store.flush() # Platform platform = {'identifier': 'Affymetrix_6.0'} platform = store.create_entity('GenomicPlatform', **platform) for snp_eid in snp_eids: store.relate(platform.eid, 'related_snps', snp_eid) ### Genetics measures ##################################################### gen_measures = import_genomic_measures(genetics_dir, 'Localizer94') # Flush/Commit if sqlgen_store: store.flush() ########################################################################### ### Subjects ############################################################## ########################################################################### centers, devices, score_defs = {}, {}, {} for sid in glob.glob('%s/*' % subjects_dir): print '-------->', sid, os.path.split(sid)[1]
if options.snps: snps = import_snps(options.chromosomes, options.snps) snp_eids = [] for ind, snp in enumerate(snps): print 'snp', snp['rs_id'] snp['chromosome'] = chr_map[snp['chromosome']] snp = store.create_entity('Snp', **snp) snp_eids.append(snp.eid) if ind and ind % 100000 == 0: store.flush() store.flush() # Platform platform = {'identifier': 'Affymetrix_6.0'} platform = store.create_entity('GenomicPlatform', **platform).eid for snp_eid in snp_eids: store.relate(platform, 'related_snps', snp_eid) store.flush() ############################################################################### ### STUDY/PI/CENTERS ########################################################## ############################################################################### study = store.create_entity('Study', name=u'Demo study', data_filepath=u'/tmp/demo_data', description=u'Demo study with random data', keywords=u'demo;random;semantic').eid pi_1 = store.create_entity('Investigator', identifier=u'pi_1', firstname=u'Angus', lastname=u'Young', title=u'PhD', institution=u'Research Center', department=u'Cognitive Sciences').eid pi_2 = store.create_entity('Investigator', identifier=u'pi_2', firstname=u'Malcom', lastname=u'Young', title=u'MD', institution=u'Research Center', department=u'Cognitive Sciences').eid
for study_path in ('Extra-18_volumes', 'MMRR-21_volumes', 'NKI-RS-22_volume', 'NKI-TRT-20_volumes', 'OASIS-TRT-20_volumes'): full_study_path = osp.join(base_path, study_path) if not osp.exists(full_study_path): print '%s does not exist, skip it' % full_study_path continue # Create study count_subject = 0 study = store.create_entity('Study', data_filepath=unicode(full_study_path), name = unicode(study_path)) for subject_path in glob.iglob(osp.join(full_study_path,'*')): subject_id = subject_path.split('/')[-1] print '--->', subject_id subject = store.create_entity('Subject', identifier=unicode(subject_id), gender=u'unknown', handedness=u'unknown') store.relate(subject.eid, 'related_studies', study.eid) store.relate(subject.eid, 'related_studies', global_study.eid) assessment = store.create_entity('Assessment',identifier=u'label', related_study=study.eid, protocol=u'mindboggle-label') store.relate(subject.eid, 'concerned_by', assessment.eid) for image in glob.iglob(osp.join(full_study_path, subject_path, '*.nii.gz')): image_id = image.split('/')[-1].split('.')[0] anat = {'identifier': u'%s_%s' % (subject_id, image_id), 'label': u'labels' if 'labels' in image_id else u'anatomy', 'format': u'nii.gz', 'type': u'normalized T1', 'related_study': study.eid, 'filepath': unicode(osp.relpath(image, start=full_study_path)), 'valid': True, 'completed': True, 'description': 'Image from Mindboggle'} mri_data = store.create_entity('MRIData', sequence=u'T1')
infos = line.strip().split('\t') if len(infos) != 4: print '!!!!', infos demographics[infos[1]] = {'gender': infos[2], 'age': int(infos[3])} # Subjects count_subject = 0 for subject_path in glob.iglob(osp.join(study_path,'sub*')): subject_id = study_id + '_' + subject_path.split('/')[-1] print '--->', subject_id age, gender = None, None if subject_id in demographics: age = demographics[subject_id].get('age') gender = demographics[subject_id].get('gender') subject = store.create_entity('Subject', identifier=unicode(subject_id), age = age, gender=gender or u'unknown', handedness=u'unknown') store.relate(subject.eid, 'related_studies', study.eid) store.relate(subject.eid, 'related_studies', global_study.eid) # anatomy assessment = store.create_entity('Assessment',identifier=u'anat', protocol=u'anat', related_study=study.eid) store.relate(subject.eid, 'concerned_by', assessment.eid) for image in glob.iglob(osp.join(study_path, subject_path, 'anatomy/*.nii.gz')): image_id = image.split('/')[-1].split('.')[0] anat = {'identifier': u'%s_%s' % (subject_id, image_id), 'label': u'anatomy', 'format': u'nii.gz', 'type': u'normalized T1', 'related_study': study.eid, 'filepath': unicode(osp.relpath(image, start=study_path)), 'valid': True, 'completed': True, 'description': 'Image from OpenFmri'} mri_data = store.create_entity('MRIData', sequence=u'T1')