Quellcode durchsuchen

Periodic check-in

Stephen Ficklin vor 6 Jahren
Ursprung
Commit
4e6cc401be

+ 45 - 10
tripal/api/tripal.entities.api.inc

@@ -326,6 +326,7 @@ function tripal_load_vocab_entity($values) {
  *     - name:  the bundle name (e.g. 'bio_data_234')
  *     - label: the bundle label (e.g. 'Organism')
  *     - term_id: the term ID to which the bundle belongs
+ *     - accession: the full acccession for the bundle (e.g. OBI:0100026)
  *
  * @return
  *   A TripalBundle entity object or NULL if not found.
@@ -348,6 +349,17 @@ function tripal_load_bundle_entity($values) {
   if (array_key_exists('term_id', $values)) {
     $query->condition('tb.term_id', $values['term_id']);
   }
+  if (array_key_exists('accession', $values)) {
+    list($vocab, $accession) = explode(':', $values['accession'], 2);
+    $term = tripal_load_term_entity(['vocabulary' => $vocab, 'accession' => $accession]);
+    if (!$term) {
+      tripal_report_error('tripal_chado', TRIPAL_ERROR, "Could not find bundle with term accession: !accession", 
+        ['!accession' => $values['accession']]);
+      return NULL;
+    }
+    $query->condition('tb.term_id', $term->id);
+    
+  }
   $bundle = $query->execute()->fetchObject();
 
   if ($bundle) {
@@ -417,20 +429,31 @@ function tripal_add_notification($title, $details, $type, $actions, $submitter_i
  *     - term_name: A human-readable name for this term.  This will became
  *       the name that appears for the content type.  In practice, this
  *       should be the name of the term. (E.g. the name for SO:0000704 is gene).
- * @param $error
- *  A string, passed by reference, that is filled with the error message
- *  if the function fails.
+ * @param $job
+ *  The job ID if this is launched via a job.
  *
  * @return
  *   The bundle object or FALSE if failure.
  *
  * @ingroup tripal_entities_api
  */
-function tripal_create_bundle($args, &$error = '') {
+function tripal_create_bundle($args, $job = NULL) {
   $vocabulary = $args['vocabulary'];
   $accession = $args['accession'];
   $term_name = $args['term_name'];
   $storage_args = $args['storage_args'];
+  
+  $message_args = [
+    'job' => $job,
+    'print' => TRUE,
+    'watchdog' => TRUE,
+  ];
+  
+//   tripal_report_error('tripal_entities', TRIPAL_INFO, 
+//    "Creation of a content type is performed using a database transaction. " .
+//     "If it fails or is terminated prematurely then all insertions and " .
+//     "updates are rolled back and will not be found in the database", 
+//     [], $message_args);
 
   $transaction = db_transaction();
   try {
@@ -444,7 +467,7 @@ function tripal_create_bundle($args, &$error = '') {
       else {
         $transaction->rollback();
         tripal_report_error('tripal_entities', TRIPAL_ERROR, 
-          'Unable to create TripalVocab :vocab', array(':vocab' => $vocabulary));
+          'Unable to create TripalVocab :vocab', array(':vocab' => $vocabulary), $message_args);
         return FALSE;
       }
     }
@@ -463,7 +486,7 @@ function tripal_create_bundle($args, &$error = '') {
       else {
         $transaction->rollback();
         tripal_report_error('tripal_entities', TRIPAL_ERROR,
-          'Unable to create TripalTerm :term', array(':term' => $term_name));
+          'Unable to create TripalTerm :term', array(':term' => $term_name), $message_args);
         return FALSE;
       }
     }
@@ -493,7 +516,7 @@ function tripal_create_bundle($args, &$error = '') {
     if (!$bundle) {
       $transaction->rollback();
       tripal_report_error('tripal_entities', TRIPAL_ERROR,
-        'Unable to create Tripal Bundle :name.', array(':name' => $bundle_name));
+        'Unable to create Tripal Bundle :name.', array(':name' => $bundle_name), $message_args);
       return FALSE;
     }
 
@@ -517,10 +540,15 @@ function tripal_create_bundle($args, &$error = '') {
     if (!$bundle) {
       $transaction->rollback();
       tripal_report_error('tripal_entities', TRIPAL_ERROR,
-        'Unable to load Tripal Bundle :name after cache clear.', array(':name' => $bundle_name));
+        'Unable to load Tripal Bundle :name after cache clear.', array(':name' => $bundle_name), $message_args);
       return FALSE;
     }
+    
+    // Set the bundle category
+    $category = array_key_exists('bundle_category', $args) ? $args['bundle_category'] : 'Other';
+    tripal_set_bundle_variable($variable_name, $bundle->id, $category);
 
+    // Attache the bundle fields.
     tripal_create_bundle_fields($bundle, $term);
 
     // Specifically commiting here since we have a fully featured bundle.
@@ -532,8 +560,9 @@ function tripal_create_bundle($args, &$error = '') {
   }
   catch (Exception $e) {
     $transaction->rollback();
-    drupal_set_message(t("Failed to create content type: %message.",
-      array('%message' => $e->getMessage())), 'error');
+    $message_args['drupal_set_message'] = TRUE;
+    tripal_report_error('tripal_entities', TRIPAL_ERROR,
+      "Failed to create content type: %message.", ['%message' => $e->getMessage()], $message_args);
     return FALSE;
   }
 
@@ -549,6 +578,12 @@ function tripal_create_bundle($args, &$error = '') {
     }
   }
 
+  // Set admin access for the new bundle.
+  tripal_admin_access($bundle);
+  
+  // Report that we're done.
+  tripal_report_error('tripal_entities', TRIPAL_INFO, "Done.", [], $message_args);
+  
   return $bundle;
 }
 

+ 6 - 5
tripal/includes/TripalBundleUIController.inc

@@ -839,15 +839,16 @@ function tripal_admin_add_type_form_submit($form, &$form_state) {
         'storage_args' => $storage_args,
       );
 
-      $bundle = tripal_create_bundle($args, $error);
-      if (!$bundle) {
+      global $user;
+      $job_id = tripal_add_job("Create content type: " . $term_name . ' ('. $vocabulary . ':' . $accession . ')', 
+        'tripal', 'tripal_create_bundle', [$args], $user->uid);
+
+      if (!$job_id) {
         drupal_set_message($error, 'error');
         $form_state['redirect'] = "admin/structure/bio_data";
       }
       else {
-        drupal_set_message('New content type created!');
-        drupal_set_message('Please ' . l("set the user permissions", "admin/people/permissions") . ' for this new content type.');
-        tripal_admin_access($bundle);
+        drupal_set_message('After the content type is created, please ' . l("set the user permissions", "admin/people/permissions") . ' for this new content type.');
         $form_state['redirect'] = "admin/structure/bio_data";
       }
     }

+ 45 - 9
tripal/includes/TripalEntityUIController.inc

@@ -702,15 +702,51 @@ function tripal_entity_form_ajax_callback($form, $form_state) {
   * TripalEntityUIController class.
   */
  function tripal_add_page() {
-   $item = menu_get_item();
-   $content = system_admin_menu_block($item);
-   // Bypass the node/add listing if only one content type is available.
-   if (count($content) == 1) {
-     $item = array_shift($content);
-     drupal_goto($item['href']);
-   }
-   return theme('tripal_add_list', array('content' => $content));
-
+//    $item = menu_get_item();
+//    $content = system_admin_menu_block($item);
+//    // Bypass the node/add listing if only one content type is available.
+//    if (count($content) == 1) {
+//      $item = array_shift($content);
+//      drupal_goto($item['href']);
+//    }
+//    return theme('tripal_add_list', array('content' => $content));
+  $select = "
+    SELECT TB.id, TB.label, TBV.value as category, TV.name as variable_type, TV.description
+    FROM tripal_bundle TB
+      LEFT JOIN tripal_bundle_variables TBV on TB.id = TBV.bundle_id
+      LEFT JOIN tripal_variables TV on TV.variable_id = TBV.variable_id
+    WHERE TV.name = 'bundle_category'
+    ORDER BY TV.description, TB.label 
+  ";
+  $bundles = db_query($select);  
+  
+  $content = [];
+  $category = 'Other';
+  $machine_name = preg_replace('/[^\w]/', '_', $category);
+  $content[$machine_name . '_fieldset'] = array(
+    '#type' => 'fieldset',
+    '#title' => $category,
+  ); 
+  while ($bundle = $bundles->fetchObject()) {
+    if ($category != $bundle->category) {
+      $category = $bundle->category;
+      $machine_name = preg_replace('/[^\w]/', '_', $category);
+      $content[$machine_name . '_fieldset'] = array(
+        '#type' => 'fieldset',
+        '#title' => $category,
+      ); 
+    }
+    $bundle = tripal_load_bundle_entity(['id' => $bundle->id]);
+    if (!$bundle) {
+      dpm('No bundle');
+      continue;
+    }
+    $content[$machine_name . '_fieldset'][$bundle->name] = array(
+      '#type' => '#markup',
+      '#markup' => $bundle->label,
+    );
+  }
+  return $content;
  }
 
  /**

+ 331 - 253
tripal_chado/includes/setup/tripal_chado.setup.inc

@@ -225,26 +225,26 @@ function tripal_chado_prepare_chado($job = NULL) {
     $mview_id = chado_get_mview_id('db2cv_mview');
     chado_populate_mview($mview_id);
     
-    
     drush_print("Creating common Tripal Content Types...");
     drush_print("This may take awhile if you are upgrading a site that has lots of data...");
-    tripal_chado_prepare_general_types();
-    
     if ($report_progress) {
-      $job->setProgress(90);
+      $job->setProgress(85);
     }
-
-    
-
-   
-
+    tripal_chado_prepare_general_types($job);
+    tripal_chado_prepare_genomic_types($job);
+    tripal_chado_prepare_genetic_types($job);
+    tripal_chado_prepare_germplasm_types($job);
+    tripal_chado_prepare_expression_types($job);
     
-
     // Add the supported loaders
     variable_set('tripal_pub_supported_dbs', array('PMID', 'AGL'));
 
     // Set a variable to indicate the site is prepared.
     variable_set('tripal_chado_is_prepared', TRUE);
+    
+    if ($report_progress) {
+      $job->setProgress(100);
+    }  
   }
   catch (Exception $e) {
     $job->logMessage($e);
@@ -255,13 +255,11 @@ function tripal_chado_prepare_chado($job = NULL) {
 /**
  * Creates the "General" category of content types.
  */
-function tripal_chado_prepare_general_types() {
+function tripal_chado_prepare_general_types($job) {
   
   //
   // Create the 'Organism' entity type. This uses the obi:organism term.
-  //
-  drush_print("Creating Organism...");
-  $error = '';
+  //  
   $args = array(
     'vocabulary' => 'OBI',
     'accession' => '0100026',
@@ -271,25 +269,11 @@ function tripal_chado_prepare_general_types() {
     ),
     'category' => 'General'
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'OBI', 'accession' => '0100026'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Organism" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
-  if ($report_progress) {
-    $job->setProgress(74);
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
   
   //
   // Create the 'Analysis' entity type. This uses the local:analysis term.
-  //
-  drush_print("Creating Analysis...");
-  $error = '';
+  //  
   $args = array(
     'vocabulary' => 'operation',
     'accession' => '2945',
@@ -299,53 +283,40 @@ function tripal_chado_prepare_general_types() {
     ),
     'category' => 'General'
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'operation', 'accession' => '2945'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Analysis" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
-  if ($report_progress) {
-    $job->setProgress(78);
-  }
-  
+  _tripal_chado_preapre_create_bundle($args, $job);
+
   //
   // Create the 'Project' entity type. This uses the local:project term.
-  //
-  drush_print("Creating Project...");
-  $error = '';
+  //  
   $args = array(
-    'vocabulary' => 'local',
-    'accession' => 'project',
-    'term_name' => 'project',
+    'vocabulary' => 'NCIT',
+    'accession' => 'C47885',
+    'term_name' => 'Project',
     'storage_args' => array(
       'data_table' => 'project',
     ),
     'category' => 'General'
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'local', 'accession' => 'project'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Project" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
-  if ($report_progress) {
-    $job->setProgress(82);
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
+
   
   //
-  // Create the 'Contact' entity type. This uses the local:contact term.
+  // Create the 'Study' entity type. This uses the local:project term.
+  //  
+  $args = array(
+    'vocabulary' => 'SIO',
+    'accession' => '001066',
+    'term_name' => 'Study',
+    'storage_args' => array(
+      'data_table' => 'study',
+    ),
+    'category' => 'General'
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
   //
-  drush_print("Creating Contact...");
-  $error = '';
+  // Create the 'Contact' entity type. This uses the local:contact term.
+  //  
   $args = array(
     'vocabulary' => 'local',
     'accession' => 'contact',
@@ -355,78 +326,63 @@ function tripal_chado_prepare_general_types() {
     ),
     'category' => 'General'
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'local', 'accession' => 'contact'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Contact" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
-  if ($report_progress) {
-    $job->setProgress(82);
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
 
   //
   // Create the 'Publication' entity type.
-  //
-  drush_print("Creating Publication...");
-    
-  // Import a publication so we get all of the properties before
-  // creating the content type.
-  chado_import_pub_by_dbxref('PMID:24163125');
-  
-  $error = '';
+  //      
   $args = array(
     'vocabulary' => 'TPUB',
     'accession' => '0000002',
     'term_name' => 'Publication',
     'storage_args' => array(
       'data_table' => 'pub',
-    )
+    ),
+    'category' => 'General'
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'TPUB', 'accession' => '0000002'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Publication" Tripal Content Type.';
-      throw new Exception($msg);
-    }
+  $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
+  if (!$bundle) {
+    // Import a publication so we get all of the properties before
+    // creating the content type.
+    chado_import_pub_by_dbxref('PMID:24163125');
+    
+    _tripal_chado_preapre_create_bundle($args, $job);
+    
+    // Now remove the publication that was added above.
+    $values = array(
+      'dbxref_id' => array(
+        'accession' => '24163125',
+        'db_id' => array(
+          'name' => 'PMID',
+        ),
+      ),
+    );
+    $result = chado_select_record('pub_dbxref', array('pub_id'), $values);
+    chado_delete_record('pub', array('pub_id' => $result[0]->pub_id));
   }
-  // Add cvterm mapping for the Publication entity type
-  $identifier = array(
-    'cv_id' => array('name' => 'tripal_pub'),
-    'name' => 'Publication'
-  );
-  $cvterm = chado_get_cvterm($identifier);
-  tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'pub', NULL);
   
-  // Now remove the publication that was added above.
-  $values = array(
-    'dbxref_id' => array(
-      'accession' => '24163125',
-      'db_id' => array(
-        'name' => 'PMID',
-      ),
+  //
+  // Create the 'Protocol' entity type.
+  //  
+  $args = array(
+    'vocabulary' => 'sep',
+    'accession' => '00101',
+    'term_name' => 'Protocol',
+    'storage_args' => array(
+      'data_table' => 'protocol',
     ),
+    'category' => 'General'
   );
-  $result = chado_select_record('pub_dbxref', array('pub_id'), $values);
-  chado_delete_record('pub', array('pub_id' => $result[0]->pub_id));
+  _tripal_chado_preapre_create_bundle($args, $job);
 }
 
 /**
  * Creates the "Genomic" category of content types.
  */
-function tripal_chado_prepare_genomic_types() {
+function tripal_chado_prepare_genomic_types($job) {
   //
   // Create the 'Gene' entity type.
-  //
-  drush_print("Creating Gene...");
-  $error = '';
+  //  
   $args = array(
     'vocabulary' => 'SO',
     'accession' => '0000704',
@@ -434,24 +390,14 @@ function tripal_chado_prepare_genomic_types() {
     'storage_args' => array(
       'data_table' => 'feature',
       'type_column' => 'type_id',
-    )
+    ),
+    'category' => 'Genomic',
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'SO', 'accession' => '0000704'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Gene" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
   
   //
   // Create the 'mRNA' entity type.
-  //
-  drush_print("Creating mRNA...");
-  $error = '';
+  //  
   $args = array(
     'vocabulary' => 'SO',
     'accession' => '0000234',
@@ -459,47 +405,27 @@ function tripal_chado_prepare_genomic_types() {
     'storage_args' => array(
       'data_table' => 'feature',
       'type_column' => 'type_id',
-    )
+    ),
+    'category' => 'Genomic',
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'SO', 'accession' => '0000234'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered  creating "mRNA" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
   
   //
   // Create the 'Phylogenetic tree' entity type.
-  //
-  drush_print("Creating Phylogenetic tree...");
-  $error = '';
+  //  
   $args = array(
     'vocabulary' => 'data',
     'accession' => '0872',
     'term_name' => 'Phylogenetic tree',
     'storage_args' => array(
       'data_table' => 'phylotree',
-    )
+    ),
+    'category' => 'Genomic',
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'data', 'accession' => '0872'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Phylogenetic tree" Tripal Content Type';
-      throw new Exception($msg);
-    }
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
   
-  // Create the 'Physical Map' entity type. This uses the local:project term.
-  drush_print("Creating Physical Map...");
+  // Create the 'Physical Map' entity type.  
   $cvterm = tripal_get_cvterm(['id' => 'local:Map Type']);
-  $error = '';
   $args = array(
     'vocabulary' => 'data',
     'accession' => '1280',
@@ -510,22 +436,12 @@ function tripal_chado_prepare_genomic_types() {
       'type_column' => 'type_id',
       'type_id' => $cvterm->cvterm_id,
       'type_value' => 'physical'
-    )
+    ),
+    'category' => 'Genomic',
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'data', 'accession' => '1280'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Physical Map" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
   
-  // Create the 'DNA Library' entity type. This uses the local:project term.
-  drush_print("Creating DNA Library...");
-  $error = '';
+  // Create the 'DNA Library' entity type.  
   $args = array(
     'vocabulary' => 'NCIT',
     'accession' => 'C16223',
@@ -533,22 +449,13 @@ function tripal_chado_prepare_genomic_types() {
     'storage_args' => array(
       'data_table' => 'library',
       'type_column' => 'type_id',
-    )
+    ),
+    'category' => 'Genomic',
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'NCIT', 'accession' => 'C16223'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "DNA Library" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
   
-  // Create the 'Genome Assembly' entity type. This uses the local:project term.
-  drush_print("Genome Assembly...");
-  $error = '';
+  // Create the 'Genome Assembly' entity type.  
+  $cvterm = tripal_get_cvterm(['id' => 'local:Analysis Type']);
   $args = array(
     'vocabulary' => 'operation',
     'accession' => '0525',
@@ -559,111 +466,282 @@ function tripal_chado_prepare_genomic_types() {
       'type_column' => 'type_id',
       'type_id' => $cvterm->cvterm_id,
       'type_value' => 'genome_assembly'
-    )
+    ),
+    'category' => 'Genomic',
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'NCIT', 'accession' => 'C16223'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "DNA Library" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
   
-  // Create the 'DNA Library' entity type. This uses the local:project term.
-  drush_print("Creating DNA Library...");
-  $error = '';
+  // Create the 'Genome Annotation' entity type.  
+  $cvterm = tripal_get_cvterm(['id' => 'local:Analysis Type']);
   $args = array(
-    'vocabulary' => 'NCIT',
-    'accession' => 'C16223',
-    'term_name' => 'DNA Library',
+    'vocabulary' => 'operation',
+    'accession' => '0362',
+    'term_name' => 'Genome Annotation',
     'storage_args' => array(
-      'data_table' => 'library',
+      'data_table' => 'analysis',
+      'type_linker_table' => 'analysisprop',
       'type_column' => 'type_id',
-    )
+      'type_id' => $cvterm->cvterm_id,
+      'type_value' => 'genome_annotation'
+    ),
+    'category' => 'Genomic',
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'NCIT', 'accession' => 'C16223'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "DNA Library" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
+  // Create the 'Genome Annotation' entity type.  
+  $cvterm = tripal_get_cvterm(['id' => 'local:Project Type']);
+  $args = array(
+    'vocabulary' => 'local',
+    'accession' => 'Genome Project',
+    'term_name' => 'Genome Project',
+    'storage_args' => array(
+      'data_table' => 'project',
+      'type_linker_table' => 'projectprop',
+      'type_column' => 'type_id',
+      'type_id' => $cvterm->cvterm_id,
+      'type_value' => 'genome_project'
+    ),
+    'category' => 'Genomic',
+  );
+  $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
+  _tripal_chado_preapre_create_bundle($args, $job);
 }
 
 /**
  * Creates the "Expression" category of content types.
  */
-function tripal_chado_prepare_expression_types() {
+function tripal_chado_prepare_expression_types($job) {
   //
   // Create the 'biological sample' entity type.
-  //
-  drush_print("Creating Biological Sample...");
-  $error = '';
+  //  
   $args = array(
     'vocabulary' => 'sep',
     'accession' => '00195',
     'term_name' => 'biological sample',
     'storage_args' => array(
       'data_table' => 'biomaterial',
-    )
+    ),
+    'Expression',
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'sep', 'accession' => '00195'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Biological Sample" Tripal Content Type.';
-      throw new Exception($msg);
-    }
-  }
+  $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
+  //
+  // Create the 'Assay' entity type.
+  //  
+  $args = array(
+    'vocabulary' => 'OBI',
+    'accession' => '0000070',
+    'term_name' => 'Assay',
+    'storage_args' => array(
+      'data_table' => 'assay',
+    ),
+    'Expression',
+  );
+  $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
+  //
+  // Create the 'Array Design' entity type.
+  //  
+  $args = array(
+    'vocabulary' => 'EFO',
+    'accession' => '0000269',
+    'term_name' => 'Assay Design',
+    'storage_args' => array(
+      'data_table' => 'arraydesign',
+    ),
+    'Expression',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
 }
 
 /**
  * Creates the "Germplasm/Breeding" category of content types.
  */
-function tripal_chado_prepare_germplasm_types() {
+function tripal_chado_prepare_germplasm_types($job) {
+  
+  //
+  // Create the 'Phenotypic Trait' entity type.
+  // 
+  /**
+   * SPF:  We need a bit more testing before we add this conteont type as 
+   * it resolves to the cvterm table. Currently, it can't be created.
+  $args = array(
+    'vocabulary' => 'NCIT',
+    'accession' => 'C85496',
+    'term_name' => 'Phenotypic Trait',
+    'storage_args' => array(
+      'data_table' => 'cvterm',
+      'type_column' => 'type_id',
+    ),
+    'category' => 'Germplasm/Breeding',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
+  */
+  
+  //
+  // Create the 'Germplasm Accession' entity type.
+  //  
+  $args = array(
+    'vocabulary' => 'CO_010',
+    'accession' => '0000044',
+    'term_name' => 'Germplasm Accession',
+    'storage_args' => array(
+      'data_table' => 'stock',
+      'type_column' => 'type_id',
+    ),
+    'category' => 'Germplasm/Breeding',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
+  //
+  // Create the 'Breeding Cross' entity type.
+  //  
+  $args = array(
+    'vocabulary' => 'CO_010',
+    'accession' => '0000255',
+    'term_name' => 'Generated germplasm (breeding cross)',
+    'storage_args' => array(
+      'data_table' => 'stock',
+      'type_column' => 'type_id',
+    ),
+    'category' => 'Germplasm/Breeding',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
+  //
+  // Create the 'Germplasm Variety' entity type.
+  //  
+  $args = array(
+    'vocabulary' => 'CO_010',
+    'accession' => '0000029',
+    'term_name' => 'Cultivar (germplasm variety)',
+    'storage_args' => array(
+      'data_table' => 'stock',
+      'type_column' => 'type_id',
+    ),
+    'category' => 'Germplasm/Breeding',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
   
+  //
+  // Create the 'Germplasm Variety' entity type.
+  //  
+  $args = array(
+    'vocabulary' => 'CO_010',
+    'accession' => '0000162',
+    'term_name' => 'Recombinant Inbred Line',
+    'storage_args' => array(
+      'data_table' => 'stock',
+      'type_column' => 'type_id',
+    ),
+    'category' => 'Germplasm/Breeding',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
 }
 
 /**
  * Creates the "Genetic" category of content types.
  */
-function tripal_chado_prepare_genetic_types() {
-  // Create the 'Map' entity type. This uses the local:project term.
-  drush_print("Creating Map...");
-  $error = '';
+function tripal_chado_prepare_genetic_types($job) {
+  
+  //
+  // Create the 'Genetic Map' entity type.
+  //  
+  $cvterm = tripal_get_cvterm(['id' => 'local:Map Type']);
   $args = array(
     'vocabulary' => 'data',
-    'accession' => '1274',
-    'term_name' => 'Map',
+    'accession' => '1278',
+    'term_name' => 'Genetic Map',
     'storage_args' => array(
       'data_table' => 'featuremap',
-    )
+      'type_linker_table' => 'featuremapprop',
+      'type_column' => 'type_id',
+      'type_id' => $cvterm->cvterm_id,
+      'type_value' => 'genetic'
+    ),
+    'category' => 'Genetic',
   );
-  $term = tripal_load_term_entity(array('vocabulary' => 'data', 'accession' => '1274'));
-  if ($term) {
-    $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
-  }
-  if (!$term or !$bundle) {
-    if (!tripal_create_bundle($args, $error)) {
-      $msg = (isset($error['!message'])) ? $error['!message'] : 'Error Encountered creating "Map" Tripal Content Type.';
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
+  //
+  // Create the 'QTL' entity type. 
+  //  
+  $args = array(
+    'vocabulary' => 'SO',
+    'accession' => '0000771',
+    'term_name' => 'QTL',
+    'storage_args' => array(
+      'data_table' => 'feature',
+      'type_column' => 'type_id',
+    ),
+    'category' => 'Genetic',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
+  //
+  // Create the 'Sequence Variant' entity type.
+  //  
+  $args = array(
+    'vocabulary' => 'SO',
+    'accession' => '0001060',
+    'term_name' => 'Sequence Variant',
+    'storage_args' => array(
+      'data_table' => 'feature',
+      'type_column' => 'type_id',
+    ),
+    'category' => 'Genetic',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
+  //
+  // Create the 'Genetic Marker' entity type.
+  //
+  $args = array(
+    'vocabulary' => 'SO',
+    'accession' => '0001645',
+    'term_name' => 'Genetic Marker',
+    'storage_args' => array(
+      'data_table' => 'feature',
+      'type_column' => 'type_id',
+    ),
+    'category' => 'Genetic',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
+  
+  
+  //
+  // Create the 'Heritable Phenotypic Marker' entity type.
+  //
+  $args = array(
+    'vocabulary' => 'SO',
+    'accession' => '0001500',
+    'term_name' => 'Heritable Phenotypic Marker',
+    'storage_args' => array(
+      'data_table' => 'feature',
+      'type_column' => 'type_id',
+    ),
+    'category' => 'Genetic',
+  );
+  _tripal_chado_preapre_create_bundle($args, $job);
+}
+/**
+ * A helper function to consolidate the  code used to create a bundle.
+ */
+function _tripal_chado_preapre_create_bundle($args, $job) {
+  
+  $bundle = tripal_load_bundle_entity(['accession' => $args['vocabulary'] . ':' . $args['accession']]);
+  if (!$bundle) {
+    drush_print("Creating " . $args['term_name'] . "...");
+    if (!tripal_create_bundle($args, $job)) {      
+      $msg = t('Error encountered creating !type Content Type.', ['!type' => $args['term_name']]);
       throw new Exception($msg);
     }
   }
-  // Add cvterm mapping for the Map entity type
-  $identifier = array(
-    'cv_id' => array('name' => 'EDAM'),
-    'name' => 'Map'
-  );
-  $cvterm = chado_get_cvterm($identifier);
-  tripal_chado_add_cvterm_mapping($cvterm->cvterm_id, 'featuremap', NULL);
+  else {
+    drush_print("Content type already created (skipping): " . $args['term_name'] . "...");
+  }
 }
 
 /**

+ 3 - 0
tripal_chado/includes/tripal_chado.fields.inc

@@ -2813,6 +2813,9 @@ function tripal_chado_bundle_get_properties($table_name, $prop_table, $type_tabl
     $args[':cvterm_id'] = $cvterm_id;
     $props = chado_query($sql, $args);
   }
+  if (!$props) {
+    return [];
+  }
   
   // Iterate through all of the properties and do some final checks to see
   // which ones should be added.

+ 142 - 26
tripal_chado/includes/tripal_chado.semweb.inc

@@ -19,6 +19,7 @@ function tripal_chado_populate_chado_semweb_table() {
   // inserted.
 
   // Now set defaults!
+  tripal_chado_populate_vocab_CO_010();
   tripal_chado_populate_vocab_DC();
   tripal_chado_populate_vocab_EDAM();
   tripal_chado_populate_vocab_ERO();
@@ -384,6 +385,15 @@ function tripal_chado_populate_vocab_SIO() {
     'definition' => 'A cell line is a collection of genetically identifical cells.',
   ));
   chado_associate_semweb_term(NULL, 'cell_line_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'SIO:001066',
+    'name' => 'study',
+    'cv_name' => 'SIO',
+    'definition' => 'A study is a process that realizes the steps of a study design.',
+  ));
+  chado_associate_semweb_term(NULL, 'study_id', $term);
+  
 }
 
 /**
@@ -402,6 +412,47 @@ function tripal_chado_populate_vocab_SO() {
   chado_associate_semweb_term(NULL, 'feature_id', $term);
 }
 
+
+/**
+ * Adds the Crop Ontology terms.
+ */
+function tripal_chado_populate_vocab_CO_010 () {
+  chado_insert_db(array(
+    'name' => 'CO_010',
+    'description' => 'Crop Germplasm Ontology',
+    'url' => 'http://www.cropontology.org/get-ontology/CO_010',
+    'urlprefix' => 'http://www.cropontology.org/terms/CO_010:{accession}',
+  ));
+  chado_insert_cv(
+    'germplasm_ontology',
+    'GCP germplasm ontology'
+  );
+  $term = chado_insert_cvterm(array(
+    'id' => 'CO_010:0000044',
+    'name' => 'accession',
+    'cv_name' => 'germplasm_ontology',
+    'definition' => '',
+  ));
+  $term = chado_insert_cvterm(array(
+    'id' => 'CO_010:0000255',
+    'name' => 'generated germplasm',
+    'cv_name' => 'germplasm_ontology',
+    'definition' => '',
+  ));
+  $term = chado_insert_cvterm(array(
+    'id' => 'CO_010:0000029',
+    'name' => 'cultivar',
+    'cv_name' => 'germplasm_ontology',
+    'definition' => '',
+  ));
+  $term = chado_insert_cvterm(array(
+    'id' => 'CO_010:0000162',
+    'name' => '414 inbred line',
+    'cv_name' => 'germplasm_ontology',
+    'definition' => '',
+  ));
+}
+
 /**
  * Adds the DC database.
  */
@@ -648,6 +699,20 @@ function tripal_chado_populate_vocab_EDAM() {
     'cv_name' => 'EDAM',
     'definition' => 'Visualise, format or render a molecular sequence or sequences such as a sequence alignment, possibly with sequence features or properties shown.',
   ));
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'operation:0525',
+    'name' => 'genome assembly',
+    'cv_name' => 'EDAM',
+    'definition' => '',
+  ));
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'operation:0362',
+    'name' => 'Genome annotation ',
+    'cv_name' => 'EDAM',
+    'definition' => '',
+  ));
 
 }
 /**
@@ -702,6 +767,13 @@ function tripal_chado_populate_vocab_EFO() {
     'definition' => '',
   ));
   chado_associate_semweb_term('arraydesign', 'manufacturer_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'EFO:0000269',
+    'name' => 'assay design',
+    'cv_name' => 'efo',
+    'definition' => 'An instrument design which describes the design of the array.',
+  ));
 }
 /**
  * Adds the Eagle-i Resource Ontology database and terms.
@@ -732,7 +804,6 @@ function tripal_chado_populate_vocab_ERO() {
     'definition' => 'A technique that samples real world physical conditions and conversion of the resulting samples into digital numeric values that can be manipulated by a computer.',
   ));
   chado_associate_semweb_term(NULL, 'acquisition_id', $term);
-  
 }
 
 /**
@@ -781,6 +852,13 @@ function tripal_chado_populate_vocab_OBI() {
   ));
   chado_associate_semweb_term(NULL, 'organism_id', $term);
   chado_associate_semweb_term('biomaterial', 'taxon_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'OBI:0000070',
+    'name' => 'assay',
+    'cv_name' => 'obi',
+    'definition' => 'A planned process with the objective to produce information about the material entity that is the evaluant, by physically examining it or its proxies.',
+  ));  
 }
 
 /**
@@ -891,6 +969,10 @@ function tripal_chado_populate_vocab_LOCAL() {
     'organism_property',
     'A local vocabulary that contains locally defined properties for organisms'
   );
+  chado_insert_cv(
+    'analysis_property',
+    'A local vocabulary that contains locally defined properties for analyses'
+  );
   chado_insert_cv(
     'tripal_phylogeny',
     'Terms used by the Tripal phylotree module for phylogenetic and taxonomic trees.'
@@ -959,7 +1041,12 @@ function tripal_chado_populate_vocab_LOCAL() {
   // Add the cv for project properties
   chado_insert_cv(
     'project_property',
-    'A local vocabulary that contains properties for projects'
+    'A local vocabulary that contains properties for projects.'
+  );
+  // Add the cv for project properties
+  chado_insert_cv(
+    'study_property',
+    'A local vocabulary that contains properties for studies.'
   );
   // Add cv for relationship types
   chado_insert_cv(
@@ -1239,7 +1326,7 @@ function tripal_chado_populate_vocab_LOCAL() {
 
   //--------------
   // Project Terms
-  //--------------
+  //-------------- 
   // Insert cvterm 'Project Description' into cvterm table of chado
   // database. This CV term is used to keep track of the project
   // description in the projectprop table.
@@ -1249,6 +1336,13 @@ function tripal_chado_populate_vocab_LOCAL() {
     'cv_name' => 'project_property',
     'db_name' => 'local'
   ));
+  
+  chado_insert_cvterm(array(
+    'name' => 'Project Type',
+    'definition'  => 'A type of project',
+    'cv_name' => 'project_property',
+    'db_name' => 'local'
+  ));
 
   //--------------
   // Natural Diversity Terms
@@ -1523,6 +1617,7 @@ function tripal_chado_populate_vocab_LOCAL() {
   // the 'analysis_property' vocabulary is for user definable properties wo we
   // will add an 'Analysis Type' to this vocubulary
   $term = chado_insert_cvterm(array(
+    'id' => 'local:Analysis Type',
     'name' => 'Analysis Type',
     'definition' => 'The type of analysis that was performed.',
     'cv_name' => 'analysis_property',
@@ -1539,19 +1634,7 @@ function tripal_chado_populate_vocab_LOCAL() {
     '(Random House Kernerman Webster\'s College Dictionary, © 2010 K ' .
     'Dictionaries Ltd).',
     'cv_name' => 'local',
-  ));
-
-  // TODO: change this to foaf:Project
-  $term = chado_insert_cvterm(array(
-    'id' => 'local:project',
-    'name' => 'project',
-    'definition' => 'A plan or proposal for accomplishing something. ' .
-    '(American Heritage® Dictionary of the English Language, Fifth Edition. ' .
-    'Copyright © 2011 by Houghton Mifflin Harcourt Publishing Company).',
-    'cv_name' => 'local',
-  ));
-  chado_associate_semweb_term(NULL, 'project_id', $term);
-  
+  )); 
 
   $term = chado_insert_cvterm(array(
     'id' => 'local:source_data',
@@ -1658,6 +1741,25 @@ function tripal_chado_populate_vocab_LOCAL() {
     'cv_name' => 'local',
   ));
   chado_associate_semweb_term('arraydesign', 'num_sub_rows', $term);
+  
+  
+  //
+  // Terms for Study
+  //
+  chado_insert_cvterm(array(
+    'name' => 'Study Type',
+    'definition'  => 'A type of study',
+    'cv_name' => 'study_property',
+    'db_name' => 'local'
+  ));
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'local:Genome Project',
+    'name' => 'Genome Project',
+    'definition' => 'A project for whole genome analysis that can include assembly and annotation.',
+    'cv_name' => 'local',
+  ));
+  
 }
 /**
  * Adds the Systems Biology Ontology database and terms.
@@ -1968,15 +2070,7 @@ function tripal_chado_populate_vocab_NCIT() {
     'definition' => 'A term that refers to any individual item or entity in a hierarchy or pedigree. [ NCI ]',
   ));
   chado_associate_semweb_term(NULL, 'phylonode_id', $term);
-    
-  $term = chado_insert_cvterm(array(
-    'id' => 'NCIT:C63536',
-    'name' => 'Study',
-    'cv_name' => 'ncit',
-    'definition' => 'A detailed examination, analysis, or critical inspection of a subject designed to discover facts about it. [ NCI ]',
-  ));
-  chado_associate_semweb_term(NULL, 'study_id', $term);
-  
+     
   $term = chado_insert_cvterm(array(
     'id' => 'NCIT:C15320',
     'name' => 'Study Design',
@@ -1993,7 +2087,29 @@ function tripal_chado_populate_vocab_NCIT() {
     'id' => 'NCIT:C54131',
     'name' => 'Company',
     'cv_name' => 'ncit',
-    'definition' => 'Any formal business entity for profit, which may be a corporation, a partnership, association or individual proprietorship. [ NCI http://dictionary.law.com ]',
+    'definition' => 'Any formal business entity for profit, which may be a corporation, a partnership, association or individual proprietorship.',
+  ));
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C47885',
+    'name' => 'Project',
+    'cv_name' => 'ncit',
+    'definition' => 'Any specifically defined piece of work that is undertaken or attempted to meet a single requirement.',
+  ));
+  chado_associate_semweb_term(NULL, 'project_id', $term);
+  
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C16223',
+    'name' => 'DNA Library',
+    'cv_name' => 'ncit',
+    'definition' => 'A collection of DNA molecules that have been cloned in vectors.',
+  ));
+    
+  $term = chado_insert_cvterm(array(
+    'id' => 'NCIT:C85496',
+    'name' => 'Trait',
+    'cv_name' => 'ncit',
+    'definition' => 'Any genetically determined characteristic.',
   ));
 }
 

+ 78 - 3
tripal_chado/tripal_chado.install

@@ -1382,8 +1382,8 @@ function tripal_chado_update_7320() {
       $bundle = tripal_load_bundle_entity(array('term_id' => $term->id));
     }
     if (!$term or !$bundle) {
-      if (!tripal_create_bundle($args, $error)) {
-        throw new Exception($error['!message']);
+      if (!tripal_create_bundle($args)) {
+        throw new Exception('Error Encountered creating "Phylogenetic tree" Tripal Content Type.');
       }
     }
   }
@@ -1571,11 +1571,86 @@ function tripal_chado_update_7327() {
 }
 
 /**
- * Adding terms for sequence visualization.
+ * Associates categories with content types.
  */
 function tripal_chado_update_7330() {
   try {
     tripal_insert_variable('bundle_category', 'Bundles can be categorized to allow for grouping');
+    
+    $bundles = [
+      'General' => [
+        // Organism
+        'OBI:0100026',
+        // Analyis
+        'operation:2945',
+        // Project
+        'NCIT:C47885',
+        // Study
+        'SIO:001066',
+        // Contact
+        'local:contact',
+        // Publication
+        'TPUB:0000002',
+        // Protocol
+        'sep:00101',        
+      ],
+      'Genomic' => [
+        // Gene
+        'SO:0000704',
+        // mRNA
+        'SO:0000234',
+        // Phylogenetci Tree
+        'data:0872',
+        // Physical Map
+        'data:1280',
+        // DNA Library
+        'NCIT:C16223',
+        // Genome Assembly
+        'operation:0525',
+        // Genome Annotation
+        'operation:0362',
+        // Genome Project
+        'local:Genome Project',                
+      ],
+      'Genetic' => [
+        // Genetic Map
+        'data:1278',
+        // QTL
+        'SO:0000771',
+        // Sequence Variant
+        'SO:0001060',
+        // Genetic Marker
+        'SO:0001645',
+        // Heritable Phenotypic Marker
+        'SO:0001500',        
+      ],
+      'Germplasm/Breeding' => [
+        // Germplasm Accession
+        'CO_010:0000044',
+        // Breeding Cross
+        'CO_010:0000255',
+        // Cutlivar
+        'CO_010:0000029',
+        // Recombinant Inbred Line
+        'CO_010:0000162',        
+      ],
+      'Expression' => [
+        // Biological Sample
+        'sep:00195',
+        // Assay
+        'OBI:0000070',
+        // Array Design 
+        'EFO:0000269',
+      ]
+    ];
+    foreach ($bundles as $category => $accessions) {
+      foreach ($accessions as $accession) {
+        $bundle = tripal_load_bundle_entity(['accession' => $accession]);
+        if ($bundle) {
+          tripal_set_bundle_variable('bundle_category', $bundle->id, $category);
+        }
+      }      
+    }    
   }
   catch (\PDOException $e) {
     $error = $e->getMessage();