Browse Source

Updated the GFF loader to add a date timestamp to the uniquename if none is provided in the GFF file. This ensures that the value will always be unique. Also, updated the GFF file to use the landmark_type provided by the user to look for the landmark if one is provided. Also changed the GFF loader so that it will recognize an entry for landmark using either the uniquename or the name

spficklin 12 years ago
parent
commit
fc8149faec
2 changed files with 52 additions and 22 deletions
  1. 51 21
      tripal_feature/includes/gff_loader.inc
  2. 1 1
      tripal_feature/tripal_feature.module

+ 51 - 21
tripal_feature/includes/gff_loader.inc

@@ -579,8 +579,11 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
         $attr_name = $attr_uniquename;  
       }
       // if the row has a parent then generate a uniquename using the parent name
+      // add the date to the name in the event there are more than one child with
+      // the same parent.
       elseif (array_key_exists('Parent', $tags)) {
-        $attr_uniquename = $tags['Parent'][0] . "-$type-$landmark:$fmin..$fmax";
+        $date = getdate();
+        $attr_uniquename = $tags['Parent'][0] . "-$type-$landmark-" . $date[0] . ":$fmin..$fmax";
         $attr_name = $attr_uniquename;
       }
       // generate a unique name based on the date, type and location
@@ -592,35 +595,62 @@ function tripal_feature_load_gff3($gff_file, $organism_id, $analysis_id,
       }      
     }
 
-    // if a name is not specified then use the unique name
+    // if a name is not specified then use the unique name as the name
     if (strcmp($attr_name, '')==0) {
       $attr_name = $attr_uniquename;
     }
 
-    // if an ID attribute is not specified then use the attribute name and
-    // hope for the best
+    // if an ID attribute is not specified then use the attribute name plus the date
     if (!$attr_uniquename) {
-      $attr_uniquename = $attr_name;
+      $date = getdate();
+      $attr_uniquename = $attr_name . '-' . $date[0];
     }
 
-    // make sure the landmark sequence exists in the database.  We don't
-    // know the type of the landmark so we'll hope that it's unique across
-    // all types. If not we'll error out.  This test is only necessary if
-    // if the landmark and the uniquename are different.  If they are the same
-    // then this is the information for the landmark
-    if (!$remove and strcmp($landmark, $attr_uniquename) != 0 ) {
+    // make sure the landmark sequence exists in the database.  If the user 
+    // has not specified a landmark type (and it's not requiredin the GFF foramt)
+    // then We don't know the type of the landmark so we'll hope that it's unique across
+    // all types for the orgnaism. Only do this test if the landmark and the feature are
+    // different.
+    if (!$remove and !(strcmp($landmark, $attr_uniquename) == 0 or strcmp($landmark, $attr_name) == 0)) {
       $select = array(
-         'organism_id' => $organism_id,
-         'uniquename'  => $landmark,
-      );
+        'organism_id' => $organism_id,
+        'uniquename'  => $landmark,
+      );      
       $columns = array('count(*) as num_landmarks');
-      $options = array('statement_name' => 'sel_feature_numland');      
-      $count = tripal_core_chado_select('feature', $columns, $select, $options);   
-      if (!$count or count($count) == 0 or $count[0]->num_landmarks == 0) {
-        watchdog('T_gff3_loader', "The landmark '%landmark' cannot be found for this organism (" . $organism->genus . " " . $organism->species . ") " .
-              "Please add the landmark and then retry the import of this GFF3 ".
-              "file", array('%landmark' => $landmark), WATCHDOG_ERROR);
-        return '';
+      $options = array('statement_name' => 'sel_feature_numland');
+      if ($landmark_type) {
+        $select['type_id'] = array(
+          'name' => $landmark_type,
+        );
+        $options = array('statement_name' => 'sel_feature_numlandty');
+      }      
+      $count = tripal_core_chado_select('feature', $columns, $select, $options);        
+      if (!$count or count($count) == 0 or $count[0]->num_landmarks == 0) {        
+        // now look for the landmark using the name rather than uniquename.
+        $select = array(
+          'organism_id' => $organism_id,
+          'name'  => $landmark,
+        );
+        $columns = array('count(*) as num_landmarks');
+        $options = array('statement_name' => 'sel_feature_numlandna');              
+        if ($landmark_type) {
+          $select['type_id'] = array(
+            'name' => $landmark_type,
+          );
+          $options = array('statement_name' => 'sel_feature_numlandnaty');
+        }
+        $count = tripal_core_chado_select('feature', $columns, $select, $options); 
+        if (!$count or count($count) == 0 or $count[0]->num_landmarks == 0) {
+          watchdog('T_gff3_loader', "The landmark '%landmark' cannot be found for this organism (%species) " .
+                "Please add the landmark and then retry the import of this GFF3 ".
+                "file", array('%landmark' => $landmark, '%species' => $organism->genus . " " . $organism->species), WATCHDOG_ERROR);
+          return '';
+        }
+        elseif($count[0]->num_landmarks > 1) {
+          watchdog('T_gff3_loader', "The landmark '%landmark' has more than one entry for this organism (%species) " .
+                "Cannot continue", array('%landmark' => $landmark, '%species' => $organism->genus . " " . $organism->species), WATCHDOG_ERROR);
+          return '';  
+        }
 
       }
       if ($count[0]->num_landmarks > 1) {

+ 1 - 1
tripal_feature/tripal_feature.module

@@ -2293,7 +2293,7 @@ function tripal_feature_match_features_page($id) {
   // if we have more than one match then generate the table, otherwise, redirect
   // to the matched feature
   if ($num_matches == 1) {
-    drupal_goto(url("node/". $curr_match->nid));
+    drupal_goto(url("node/" . $curr_match->nid));
   }
   if ($num_matches == 0) {
     return "<p>No features matched the given name '$id'</p>";