def update_PDB_ihm_cross_link_restraint(model): # Add the PDB.ihm_cross_link_restraint.pseudo_site_flag column utils.create_column_if_not_exist( model, 'PDB', 'ihm_cross_link_restraint', Column.define( 'pseudo_site_flag', builtin_types.text, comment= 'A flag indicating if the cross link involves a pseudo site that is not part of the model representation', nullok=True)) # Create the foreign key PDB.ihm_cross_link_restraint.pseudo_site_flag references Vocab.pseudo_site_flag.Name utils.create_foreign_key_if_not_exists( model, 'PDB', 'ihm_cross_link_restraint', 'ihm_cross_link_restraint_pseudo_site_flag_fkey', ForeignKey.define(['pseudo_site_flag'], 'Vocab', 'pseudo_site_flag', ['Name'], constraint_names=[[ 'Vocab', 'ihm_cross_link_restraint_pseudo_site_flag_fkey' ]], on_update='CASCADE', on_delete='NO ACTION')) # Create combo1 key utils.create_key_if_not_exists(model, 'PDB', 'ihm_cross_link_restraint', ['RID', 'structure_id', 'id'], 'ihm_cross_link_restraint_combo1_key')
def update_PDB_ihm_related_datasets(model): # -- add columns utils.create_column_if_not_exist( model, 'PDB', 'ihm_related_datasets', Column.define( 'transformation_id', builtin_types.int8, comment= 'Identifier corresponding to the transformation matrix to be applied to the derived dataset in order to transform it to the primary dataset', nullok=True)) utils.create_column_if_not_exist( model, 'PDB', 'ihm_related_datasets', Column.define('Transformation_RID', builtin_types.text, comment='Identifier to the transformation RID', nullok=True)) # -- add fk utils.create_foreign_key_if_not_exists( model, 'PDB', 'ihm_related_datasets', 'ihm_related_datasets_ihm_data_transformation_combo2_fkey', ForeignKey.define( ['Transformation_RID', 'transformation_id'], 'PDB', 'ihm_data_transformation', ['RID', 'id'], constraint_names=[[ 'PDB', 'ihm_related_datasets_ihm_data_transformation_combo2_fkey' ]], on_update='CASCADE', on_delete='NO ACTION'))
def update_Data_Dictionary_Name(catalog, model): try: utils.create_column_if_not_exist(model, 'Vocab', 'Data_Dictionary_Name', column) url = '/attribute/Vocab:{}/RID,Name'.format('Data_Dictionary_Name') resp = catalog.get(url) resp.raise_for_status() rows = resp.json() #print(json.dumps(rows, indent=4)) values = [] for row in rows: values.append({ 'RID': row['RID'], 'Location': location[row['Name']] }) columns = ['RID', 'Location'] url = '/attributegroup/Vocab:{}/RID;Location'.format( 'Data_Dictionary_Name') resp = catalog.put(url, json=values) resp.raise_for_status() print('Updated {}'.format('Data_Dictionary_Name')) except: et, ev, tb = sys.exc_info() print('got exception "%s"' % str(ev)) print('%s' % ''.join(traceback.format_exception(et, ev, tb)))
def update_PDB_ihm_derived_distance_restraint(model): # -- add columns utils.create_column_if_not_exist( model, 'PDB', 'ihm_derived_distance_restraint', Column.define( 'distance_threshold_mean', builtin_types.float8, comment='The distance threshold mean applied to the restraint', nullok=True)) utils.create_column_if_not_exist( model, 'PDB', 'ihm_derived_distance_restraint', Column.define( 'distance_threshold_esd', builtin_types.float8, comment= 'The estimated standard deviation of the distance threshold applied to the restraint', nullok=True))
def update_PDB_ihm_ensemble_info(model): # Add the PDB.ihm_ensemble_info.sub_sample_flag and PDB.ihm_ensemble_info.sub_sampling_type columns utils.create_column_if_not_exist( model, 'PDB', 'ihm_ensemble_info', Column.define( 'sub_sample_flag', builtin_types.text, comment= 'A flag that indicates whether the ensemble consists of sub samples', nullok=True)) utils.create_column_if_not_exist( model, 'PDB', 'ihm_ensemble_info', Column.define('sub_sampling_type', builtin_types.text, comment='Type of sub sampling', nullok=True)) # Create the foreign keys utils.create_foreign_key_if_not_exists( model, 'PDB', 'ihm_ensemble_info', 'ihm_ensemble_info_sub_sample_flag_fkey', ForeignKey.define(['sub_sample_flag'], 'Vocab', 'sub_sample_flag', ['Name'], constraint_names=[[ 'Vocab', 'ihm_ensemble_info_sub_sample_flag_fkey' ]], on_update='CASCADE', on_delete='NO ACTION')) utils.create_foreign_key_if_not_exists( model, 'PDB', 'ihm_ensemble_info', 'ihm_ensemble_info_sub_sampling_type_fkey', ForeignKey.define(['sub_sampling_type'], 'Vocab', 'sub_sampling_type', ['Name'], constraint_names=[[ 'Vocab', 'ihm_ensemble_info_sub_sampling_type_fkey' ]], on_update='CASCADE', on_delete='NO ACTION')) utils.create_key_if_not_exists(model, 'PDB', 'ihm_ensemble_info', ['RID', 'structure_id', 'ensemble_id'], 'ihm_ensemble_info_combo1_key')
def main(server_name, catalog_id, credentials): server = DerivaServer('https', server_name, credentials) catalog = server.connect_ermrest(catalog_id) catalog.dcctx['cid'] = 'oneoff/model' model = catalog.getCatalogModel() utils.alter_on_update_fkey_if_exist(model, 'PDB', 'Entry_Related_File', 'Entry_Related_File_File_Type_fkey', 'CASCADE') utils.create_column_if_not_exist(model, 'PDB', 'ihm_starting_computational_models', Column.define( 'External_Files_RID', builtin_types.text, comment='Identifier to the external files RID', nullok=True )) utils.create_column_if_not_exist(model, 'PDB', 'ihm_starting_computational_models', Column.define( 'Software_RID', builtin_types.text, comment='Identifier to the software RID', nullok=True )) utils.create_column_if_not_exist(model, 'PDB', 'ihm_interface_residue_feature', Column.define( 'Dataset_List_RID', builtin_types.text, comment='Identifier to the dataset list RID', nullok=True )) utils.create_column_if_not_exist(model, 'PDB', 'ihm_derived_distance_restraint', Column.define( 'Dataset_List_RID', builtin_types.text, comment='Identifier to the dataset list RID', nullok=True )) utils.create_column_if_not_exist(model, 'PDB', 'ihm_geometric_object_distance_restraint', Column.define( 'Dataset_List_RID', builtin_types.text, comment='Identifier to the dataset list RID', nullok=True )) utils.rename_fkey_if_exist(model, 'PDB', 'ihm_starting_computational_models', 'ihm_starting_computational_models_script_file_id_fkey', 'ihm_starting_computational_models_script_file_id_fk') utils.rename_fkey_if_exist(model, 'PDB', 'ihm_starting_computational_models', 'ihm_starting_computational_models_software_id_fkey', 'ihm_starting_computational_models_software_id_fk') utils.rename_fkey_if_exist(model, 'PDB', 'ihm_interface_residue_feature', 'ihm_interface_residue_feature_dataset_list_id_fkey', 'ihm_interface_residue_feature_dataset_list_id_fk') utils.rename_fkey_if_exist(model, 'PDB', 'ihm_derived_distance_restraint', 'ihm_derived_distance_restraint_dataset_list_id_fkey', 'ihm_derived_distance_restraint_dataset_list_id_fk') utils.rename_fkey_if_exist(model, 'PDB', 'ihm_geometric_object_distance_restraint', 'ihm_geometric_object_distance_restraint_dataset_list_id_fkey', 'ihm_geometric_object_distance_restraint_dataset_list_id_fk') utils.create_key_if_not_exists(model, 'PDB', 'ihm_dataset_list', ['RID', 'id'], 'ihm_dataset_list_combo2_key') model = catalog.getCatalogModel() utils.create_foreign_key_if_not_exists(model, 'PDB', 'ihm_starting_computational_models', 'ihm_starting_computational_models_script_file_id_fkey', ForeignKey.define(['External_Files_RID', 'script_file_id'], 'PDB', 'ihm_external_files', ['RID', 'id'], constraint_names=[ ['PDB', 'ihm_starting_computational_models_script_file_id_fkey'] ], on_update='CASCADE', on_delete='NO ACTION') ) model = catalog.getCatalogModel() utils.create_foreign_key_if_not_exists(model, 'PDB', 'ihm_starting_computational_models', 'ihm_starting_computational_models_software_id_fkey', ForeignKey.define(['Software_RID', 'software_id'], 'PDB', 'software', ['RID', 'pdbx_ordinal'], constraint_names=[ ['PDB', 'ihm_starting_computational_models_software_id_fkey'] ], on_update='CASCADE', on_delete='NO ACTION') ) model = catalog.getCatalogModel() utils.create_foreign_key_if_not_exists(model, 'PDB', 'ihm_interface_residue_feature', 'ihm_interface_residue_feature_dataset_list_id_fkey', ForeignKey.define(['Dataset_List_RID', 'dataset_list_id'], 'PDB', 'ihm_dataset_list', ['RID', 'id'], constraint_names=[ ['PDB', 'ihm_interface_residue_feature_dataset_list_id_fkey'] ], on_update='CASCADE', on_delete='NO ACTION') ) model = catalog.getCatalogModel() utils.create_foreign_key_if_not_exists(model, 'PDB', 'ihm_derived_distance_restraint', 'ihm_derived_distance_restraint_dataset_list_id_fkey', ForeignKey.define(['Dataset_List_RID', 'dataset_list_id'], 'PDB', 'ihm_dataset_list', ['RID', 'id'], constraint_names=[ ['PDB', 'ihm_derived_distance_restraint_dataset_list_id_fkey'] ], on_update='CASCADE', on_delete='NO ACTION') ) model = catalog.getCatalogModel() utils.create_foreign_key_if_not_exists(model, 'PDB', 'ihm_geometric_object_distance_restraint', 'ihm_geometric_object_distance_restraint_dataset_list_id_fkey', ForeignKey.define(['Dataset_List_RID', 'dataset_list_id'], 'PDB', 'ihm_dataset_list', ['RID', 'id'], constraint_names=[ ['PDB', 'ihm_geometric_object_distance_restraint_dataset_list_id_fkey'] ], on_update='CASCADE', on_delete='NO ACTION') )
def update_PDB_ihm_pseudo_site_feature(model): # Drop fkeys from ihm_pseudo_site_feature utils.drop_fkey_if_exist(model, 'PDB', 'ihm_pseudo_site_feature', 'ihm_pseudo_site_feature_feature_id_fkey') # -- Remove columns from the PDB.ihm_pseudo_site_feature table utils.drop_column_if_exist(model, 'PDB', 'ihm_pseudo_site_feature', 'Cartn_x') utils.drop_column_if_exist(model, 'PDB', 'ihm_pseudo_site_feature', 'Cartn_y') utils.drop_column_if_exist(model, 'PDB', 'ihm_pseudo_site_feature', 'Cartn_z') utils.drop_column_if_exist(model, 'PDB', 'ihm_pseudo_site_feature', 'radius') utils.drop_column_if_exist(model, 'PDB', 'ihm_pseudo_site_feature', 'description') # -- add columns utils.create_column_if_not_exist( model, 'PDB', 'ihm_pseudo_site_feature', Column.define( 'pseudo_site_id', builtin_types.int8, comment='Pseudo site identifier corresponding to this feature', nullok=False)) utils.create_column_if_not_exist( model, 'PDB', 'ihm_pseudo_site_feature', Column.define('Pseudo_Site_RID', builtin_types.text, comment='Identifier to the pseudo site RID', nullok=False)) utils.create_column_if_not_exist( model, 'PDB', 'ihm_pseudo_site_feature', Column.define('Feature_RID', builtin_types.text, comment='Identifier to the feature RID', nullok=False)) # -- add fk utils.create_foreign_key_if_not_exists( model, 'PDB', 'ihm_pseudo_site_feature', 'ihm_pseudo_site_feature_ihm_pseudo_site_combo1_fkey', ForeignKey.define( ['Pseudo_Site_RID', 'structure_id', 'pseudo_site_id'], 'PDB', 'ihm_pseudo_site', ['RID', 'structure_id', 'id'], constraint_names=[[ 'PDB', 'ihm_pseudo_site_feature_ihm_pseudo_site_combo1_fkey' ]], on_update='CASCADE', on_delete='NO ACTION')) utils.create_foreign_key_if_not_exists( model, 'PDB', 'ihm_pseudo_site_feature', 'ihm_pseudo_site_feature_ihm_feature_list_combo1_fkey', ForeignKey.define( ['Feature_RID', 'structure_id', 'feature_id'], 'PDB', 'ihm_feature_list', ['RID', 'structure_id', 'feature_id'], constraint_names=[[ 'PDB', 'ihm_pseudo_site_feature_ihm_feature_list_combo1_fkey' ]], on_update='CASCADE', on_delete='NO ACTION' ) # won't allow delete until there is no reference )
def main(server_name, catalog_id, credentials): server = DerivaServer('https', server_name, credentials) catalog = server.connect_ermrest(catalog_id) catalog.dcctx['cid'] = "oneoff/model" model = catalog.getCatalogModel() """ Add the Table_Name column to the Vocab.File_Type table """ utils.create_column_if_not_exist( model, 'Vocab', 'File_Type', Column.define('Table_Name', builtin_types.text, nullok=True)) """ Create the new vocabulary tables """ utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table('cross_link_partner', 'Identity of the crosslink partner')) utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table( 'sub_sample_flag', 'Flag for ensembles consisting of sub samples')) utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table('sub_sampling_type', 'Types of sub samples in ensembles')) utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table('pseudo_site_flag', 'Flag for crosslinks involving pseudo sites')) utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table( 'ihm_derived_angle_restraint_group_conditionality', 'Conditionality of a group of angles restrained together')) utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table('ihm_derived_angle_restraint_restraint_type', 'The type of angle restraint')) utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table( 'ihm_derived_dihedral_restraint_group_conditionality', 'Conditionality of a group of dihedrals restrained together')) utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table( 'ihm_derived_dihedral_restraint_restraint_type', 'The type of dihedral restraint')) utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table( 'struct_ref_seq_dif_details', 'Details about the special aspects of point differences in the alignment of the macromolecular sequence in the integrative model and the sequence in the reference database' )) utils.create_table_if_not_exist( model, 'Vocab', utils.define_Vocab_table( 'struct_ref_db_name', 'The name of the database containing reference information')) """ Load data into the new vocabulary tables """ utils.add_rows_to_vocab_table(catalog, 'cross_link_partner', cross_link_partner_rows) utils.add_rows_to_vocab_table(catalog, 'sub_sample_flag', sub_sample_flag_rows) utils.add_rows_to_vocab_table(catalog, 'sub_sampling_type', sub_sampling_type_rows) utils.add_rows_to_vocab_table(catalog, 'pseudo_site_flag', pseudo_site_flag_rows) utils.add_rows_to_vocab_table( catalog, 'ihm_derived_angle_restraint_group_conditionality', ihm_derived_angle_restraint_group_conditionality_rows) utils.add_rows_to_vocab_table( catalog, 'ihm_derived_angle_restraint_restraint_type', ihm_derived_angle_restraint_restraint_type_rows) utils.add_rows_to_vocab_table( catalog, 'ihm_derived_dihedral_restraint_group_conditionality', ihm_derived_dihedral_restraint_group_conditionality_rows) utils.add_rows_to_vocab_table( catalog, 'ihm_derived_dihedral_restraint_restraint_type', ihm_derived_dihedral_restraint_restraint_type_rows) utils.add_rows_to_vocab_table(catalog, 'struct_ref_seq_dif_details', struct_ref_seq_dif_details_rows) utils.add_rows_to_vocab_table(catalog, 'struct_ref_db_name', struct_ref_db_name_rows) """ Load data into existing vocabulary tables """ utils.add_rows_to_vocab_table(catalog, 'ihm_cross_link_list_linker_type', ihm_cross_link_list_linker_type_rows) utils.add_rows_to_vocab_table(catalog, 'ihm_dataset_list_data_type', ihm_dataset_list_data_type_rows) utils.add_rows_to_vocab_table( catalog, 'ihm_dataset_related_db_reference_db_name', ihm_dataset_related_db_reference_db_name_rows) utils.add_rows_to_vocab_table( catalog, 'ihm_derived_distance_restraint_restraint_type', ihm_derived_distance_restraint_restraint_type_rows) utils.add_rows_to_vocab_table(catalog, 'File_Type', File_Type_rows) """ Create the acls bindings """ utils.set_table_acl_bindings(catalog, 'Vocab', 'cross_link_partner', acl_bindings) utils.set_table_acl_bindings(catalog, 'Vocab', 'sub_sample_flag', acl_bindings) utils.set_table_acl_bindings(catalog, 'Vocab', 'sub_sampling_type', acl_bindings) utils.set_table_acl_bindings(catalog, 'Vocab', 'pseudo_site_flag', acl_bindings) utils.set_table_acl_bindings( catalog, 'Vocab', 'ihm_derived_angle_restraint_group_conditionality', acl_bindings) utils.set_table_acl_bindings(catalog, 'Vocab', 'ihm_derived_angle_restraint_restraint_type', acl_bindings) utils.set_table_acl_bindings( catalog, 'Vocab', 'ihm_derived_dihedral_restraint_group_conditionality', acl_bindings) utils.set_table_acl_bindings( catalog, 'Vocab', 'ihm_derived_dihedral_restraint_restraint_type', acl_bindings) utils.set_table_acl_bindings(catalog, 'Vocab', 'struct_ref_seq_dif_details', acl_bindings) utils.set_table_acl_bindings(catalog, 'Vocab', 'struct_ref_db_name', acl_bindings)