ソースを参照

Fixed bug with seqlen calcuation after importing FASTA. Fixed bug in duplicates of OBO loaders and updated to support relative paths

Stephen Ficklin 10 年 前
コミット
77e5587088

+ 26 - 7
tripal_contact/tripal_contact.install

@@ -51,22 +51,22 @@ function tripal_contact_requirements($phase) {
  */
 function tripal_contact_install() {
 
-  // create the module's data directory
+  // Create the module's data directory.
   tripal_create_files_dir('tripal_contact');
 
-  // add the contactprop table to Chado
+  // Add the contactprop table to Chado.
   tripal_contact_add_custom_tables();
 
-  // add loading of the the tripal contact ontology to the job queue
-  $obo_path = drupal_realpath(drupal_get_path('module', 'tripal_contact') . '/files/tcontact.obo');
+  // Add loading of the the tripal contact ontology to the job queue.
+  $obo_path = '{tripal_contact}/files/tcontact.obo';
   $obo_id = tripal_insert_obo('Tripal Contacts', $obo_path);
-  tripal_submit_obo_job(array('ob_id' => $obo_id));
+  tripal_submit_obo_job(array('obo_id' => $obo_id));
 
-  // Add cvterms for relationship types
+  // Add cvterms for relationship types.
   tripal_contact_add_cvs();
   tripal_contact_add_cvterms();
 
-  // set the default vocabularies
+  // Set the default vocabularies.
   tripal_set_default_cv('contact', 'type_id', 'tripal_contact');
   tripal_set_default_cv('contactprop', 'type_id', 'tripal_contact');
   tripal_set_default_cv('contact_relationship', 'type_id', 'contact_relationship');
@@ -393,4 +393,23 @@ function tripal_contact_update_7201() {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Failed to update foriegn key: '. $error);
   }
+}
+/**
+ * Updates path of tripal_contact OBO to be relative.
+ */
+function tripal_contact_update_7202() {
+  try {
+    // Remove duplicates.
+    db_delete('tripal_cv_obo')
+      ->condition('name', 'Tripal Contacts')
+      ->execute();
+    
+    // Add in the updated path.
+    $obo_path = '{tripal_contact}/files/tcontact.obo';
+    $obo_id = tripal_insert_obo('Tripal Contacts', $obo_path);
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Failed to update tripal_contact OBO path: '. $error);
+  }
 }

+ 26 - 6
tripal_cv/api/tripal_cv.api.inc

@@ -817,7 +817,9 @@ function tripal_submit_obo_job($obo) {
 }
 
 /**
- * Add the obo to the tripal_cv_obo table in the Drupal database
+ * Add the OBO to the tripal_cv_obo table in the Drupal database.
+ * 
+ * If the OBO name already exists in the table then the path is updated. 
  *
  * @param $name
  *   The human readable name of this ontology
@@ -830,11 +832,29 @@ function tripal_submit_obo_job($obo) {
  * @ingroup tripal_cv_api
  */
 function tripal_insert_obo($name, $path) {
-  $record = new stdClass;
-  $record->name = $name;
-  $record->path = $path;
-  drupal_write_record('tripal_cv_obo', $record);
-  return $record->obo_id;
+  // make sure an OBO with the same name doesn't already exist
+  $obo_id = db_select('tripal_cv_obo', 'tco')
+    ->fields('tco', array('obo_id'))
+    ->condition('name', $name)
+    ->execute()
+    ->fetchField();
+  
+  if ($obo_id) {
+    db_update('tripal_cv_obo')
+      ->fields(array(
+        'path' => $path,
+      ))
+      ->condition('name', $name)
+      ->execute();
+    return $obo_id;
+  }
+  else {
+    $record = new stdClass;
+    $record->name = $name;
+    $record->path = $path;
+    drupal_write_record('tripal_cv_obo', $record);
+    return $record->obo_id;
+  }
 }
 
 /**

+ 8 - 1
tripal_cv/includes/tripal_cv.obo_loader.inc

@@ -142,10 +142,17 @@ function tripal_cv_obo_form_submit($form, &$form_state) {
  */
 function tripal_cv_load_obo_v1_2_id($obo_id, $jobid = NULL) {
 
-  // get the OBO reference
+  // Get the OBO reference.
   $sql = "SELECT * FROM {tripal_cv_obo} WHERE obo_id = :obo_id";
   $obo = db_query($sql, array(':obo_id' => $obo_id))->fetchObject();
 
+  // Convert the module name to the real path if present
+  if (preg_match("/\{(.*?)\}/", $obo->path, $matches)) {
+    $module = $matches[1];
+    $path = drupal_realpath(drupal_get_path('module', $module));
+    $obo->path = preg_replace("/\{.*?\}/", $path, $obo->path);
+  } 
+
   // if the reference is for a remote URL then run the URL processing function
   if (preg_match("/^http:\/\//", $obo->path) or preg_match("/^ftp:\/\//", $obo->path)) {
     tripal_cv_load_obo_v1_2_url($obo->name, $obo->path, $jobid, 0);

+ 2 - 2
tripal_feature/includes/tripal_feature.fasta_loader.inc

@@ -1046,8 +1046,8 @@ function tripal_feature_load_fasta_residues($fh, $feature_id, $seq_start, $seq_e
   }
   
   // Now update the seqlen and md5checksum fields
-  $sql = "UPDATE {feature} SET seqlen = :seqlen,  md5checksum = md5('residues') WHERE feature_id = :feature_id";
-  chado_query($sql, array(':seqlen' => $seqlen, ':feature_id' => $feature_id));
+  $sql = "UPDATE {feature} SET seqlen = char_length(residues),  md5checksum = md5(residues) WHERE feature_id = :feature_id";
+  chado_query($sql, array(':feature_id' => $feature_id));
   
   $percent = sprintf("%.2f", ($num_read / $seqlen) * 100);
   print "Sequence complete: " . $percent . "%. Memory: " . number_format(memory_get_usage()) . " bytes. \r";

+ 4 - 2
tripal_feature/tripal_feature.module

@@ -552,12 +552,14 @@ function tripal_feature_match_features_page($id) {
       INNER JOIN public.chado_feature CF on CF.feature_id = F.feature_id
     WHERE
       F.uniquename = :uname or
-      F.name = :fname' or
+      F.name = :fname or
       S.name = :sname
     GROUP BY F.name, F.uniquename, F.feature_id, O.genus, O.species,
       O.organism_id, CVT.cvterm_id, CVT.name, CF.nid
   ";
-  $results = chado_query($sql, array(':uname' => $id, ':fname' => $id, ':sname' => $id));
+  
+  $args = array(':uname' => $id, ':fname' => $id, ':sname' => $id); 
+  $results = chado_query($sql, $args);
 
   $num_matches = 0;
 

+ 21 - 2
tripal_pub/tripal_pub.install

@@ -53,9 +53,9 @@ function tripal_pub_install() {
   tripal_create_files_dir('tripal_pub');
 
   // add loading of the the tripal pub ontology to the job queue
-  $obo_path =  drupal_realpath(drupal_get_path('module', 'tripal_pub') . '/files/tpub.obo');
+  $obo_path = '{tripal_pub}/files/tpub.obo';
   $obo_id = tripal_insert_obo('Tripal Publication', $obo_path);
-  tripal_submit_obo_job(array('ob_id' => $obo_id));
+  tripal_submit_obo_job(array('obo_id' => $obo_id));
 
   tripal_pub_add_cvs();
   tripal_pub_add_cvterms();
@@ -433,4 +433,23 @@ function tripal_pub_update_7201() {
     $error = $e->getMessage();
     throw new DrupalUpdateException('Failed to update foriegn key: '. $error);
   }
+}
+/**
+ * Updates path of tripal_pub OBO to be relative.
+ */
+function tripal_pub_update_7202() {
+  try {
+    // Remove duplicates.
+    db_delete('tripal_cv_obo')
+      ->condition('name', 'Tripal Publication')
+      ->execute();
+
+    // Add in the updated path.
+    $obo_path = '{tripal_pub}/files/tpub.obo';
+    $obo_id = tripal_insert_obo('Tripal Publication', $obo_path);
+  }
+  catch (\PDOException $e) {
+    $error = $e->getMessage();
+    throw new DrupalUpdateException('Failed to update tripal_pub OBO path: '. $error);
+  }
 }