Selaa lähdekoodia

Fixed the tripal core to allow inclusion of 'NULL' values in inserts and updates. Also, added support for 'Gap', 'Target', and 'Derives_from' attributes in the GFF3 file.

spficklin 13 vuotta sitten
vanhempi
commit
64d5b96f29
2 muutettua tiedostoa jossa 110 lisäystä ja 15 poistoa
  1. 23 7
      tripal_core/tripal_core.api.inc
  2. 87 8
      tripal_feature/gff_loader.php

+ 23 - 7
tripal_core/tripal_core.api.inc

@@ -180,10 +180,14 @@ function tripal_core_chado_insert($table,$values){
    foreach ($insert_values as $field => $value){
       array_push($ifields,$field);
       array_push($ivalues,$value);
-      if(strcmp($fields[$field]['type'],'serial')==0 or 
+      if(strcmp($value,'__NULL__')==0){
+         array_push($itypes,"NULL");
+      } 
+      elseif(strcmp($fields[$field]['type'],'serial')==0 or 
          strcmp($fields[$field]['type'],'int')==0){
          array_push($itypes,"%d");
-      } else {
+      } 
+      else {
          array_push($itypes,"'%s'");
       }
    }
@@ -299,10 +303,15 @@ function tripal_core_chado_delete($table,$match){
          $sql .= "$field IN (".db_placeholders($value,'varchar').") AND ";
          foreach ($value as $v) { $dargs[] = $v; }
       } else {
-         if(strcmp($fields[$field]['type'],'serial')==0 or 
+         if(strcmp($value,'__NULL__')==0){
+            $sql .= " $field = NULL AND ";
+         } 
+         elseif(strcmp($fields[$field]['type'],'serial')==0 or 
             strcmp($fields[$field]['type'],'int')==0){
             $sql .= " $field = %d AND ";
-         } else {
+
+         } 
+         else {
             $sql .= " $field = '%s' AND ";
          }
          array_push($dargs,$value);
@@ -427,7 +436,10 @@ function tripal_core_chado_update($table,$match,$values){
    $fields = $table_desc['fields'];
    $uargs = array();
    foreach($update_values as $field => $value){
-      if(strcmp($fields[$field]['type'],'serial')==0 or 
+      if(strcmp($value,'__NULL__')==0){
+         $sql .= " $field = NULL, ";
+      } 
+      elseif(strcmp($fields[$field]['type'],'serial')==0 or 
          strcmp($fields[$field]['type'],'int')==0){
          $sql .= " $field = %d, ";
       } else {
@@ -438,10 +450,14 @@ function tripal_core_chado_update($table,$match,$values){
    $sql = substr($sql,0,-2);  // get rid of the trailing comma & space
    $sql .= " WHERE ";
    foreach($update_matches as $field => $value){
-      if(strcmp($fields[$field]['type'],'serial')==0 or 
+      if(strcmp($value,'__NULL__')==0){
+         $sql .= " $field = NULL AND ";
+      } 
+      elseif(strcmp($fields[$field]['type'],'serial')==0 or 
          strcmp($fields[$field]['type'],'int')==0){
          $sql .= " $field = %d AND ";
-      } else {
+      } 
+      else {
          $sql .= " $field = '%s' AND ";
       }
       array_push($uargs,$value);

+ 87 - 8
tripal_feature/gff_loader.php

@@ -466,11 +466,11 @@ function tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only
             if(array_key_exists('Alias',$tags)){
                tripal_feature_load_gff3_alias($feature,$tags['Alias']);
             }
-            // add any aliases for this feature
+            // add any dbxrefs for this feature
             if(array_key_exists('Dbxref',$tags)){
                tripal_feature_load_gff3_dbxref($feature,$tags['Dbxref']);
             }
-            // add any aliases for this feature
+            // add any ontology terms for this feature
             if(array_key_exists('Ontology_term',$tags)){
                tripal_feature_load_gff3_ontology($feature,$tags['Ontology_term']);
             }
@@ -478,6 +478,31 @@ function tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only
             if(array_key_exists('Parent',$tags)){
                tripal_feature_load_gff3_parents($feature,$cvterm,$tags['Parent'],$gff_features,$organism_id,$fmin);
             }
+            // add target relationships
+            if(array_key_exists('Target',$tags)){
+               $target = explode(" ",$tags['Target'][0]);
+               $target_feature = $target[0];
+               $target_start = $target[1];
+               $target_end = $target[2];
+               $target_dir = $target[3];
+               #print "Target: $target_feature, $target_start-$target_end\n";
+               tripal_feature_load_gff3_featureloc($feature,$organism,
+                  $target_feature,$target_start,$target_end,$strand,$phase,$attr_fmin_partial,
+                  $attr_fmax_partial,$attr_residue_info,$attr_locgroup);
+            }
+            // add gap information.  This goes in simply as a property 
+            if(array_key_exists('Gap',$tags)){
+               tripal_feature_load_gff3_property($feature,'Gap',$tags['Gap'][0]);
+            }
+            // add notes. This goes in simply as a property
+            if(array_key_exists('Note',$tags)){
+               tripal_feature_load_gff3_property($feature,'Note',$tags['Note'][0]);
+            }
+            // add the Derives_from relationship (e.g. polycistronic genes).
+            if(array_key_exists('Derives_from',$tags)){
+               tripal_feature_load_gff3_derives_from($feature,$tags['Derives_from'][0],$gff_features,$organism);
+            }
+
             // add in the GFF3_source dbxref so that GBrowse can find the feature using the source column
             $source_ref = array('GFF_source:'.$source);
             tripal_feature_load_gff3_dbxref($feature,$source_ref);
@@ -546,7 +571,56 @@ function tripal_feature_load_gff3($gff_file, $organism_id,$analysis_id,$add_only
    tripal_db_set_active($previous_db);
    return '';
 }
+/**
+ *
+ *
+ * @ingroup gff3_loader
+ */
+function tripal_feature_load_gff3_derives_from($feature,$subject,$gff_features,$organism){
+
+   // first get the subject feature
+   $match = array(
+      'organism_id' => $organism->organism_id,
+      'uniquename' => $subject,
+      'type_id' => array(
+         'name' => $gff_features[$subject]['type'],
+         'cv_id' => array(
+            'name' => 'sequence'
+         ),
+      ),
+   );
+   $sfeature = tripal_core_chado_select('feature',array('*'),$match);
+   if(count($sfeature)==0){
+      print "ERROR: could not add 'Derives_from' relationship for $feature->uniquename and $subject.  Subject feature, '$subject', cannot be found\n";
+      return;
+   }
+
+   // now check to see if the relationship already exists  
+   $values = array(
+      'object_id' => $feature->feature_id,
+      'subject_id' => $sfeature[0]->feature_id,
+      'type_id' => array(
+         'cv_id' => array(
+            'name' => 'relationship'
+         ),
+         'name' => 'derives_from',
+      ),
+      'rank' => 0
+   );
+   $rel = tripal_core_chado_select('feature_relationship',array('*'),$values);
+   if(count($rel) > 0){
+      print "   Relationship already exists: $feature->uniquename derives_from $subject\n";
+      return;
+   }
 
+   // finally insert the relationship if it doesn't exist
+   $ret = tripal_core_chado_insert('feature_relationship',$values);
+   if(!$ret){
+      print "ERROR: could not add 'Derives_from' relationship for $feature->uniquename and $subject\n";
+   } else {
+      print "   Added relationship: $feature->uniquename derives_from $subject\n";
+   }
+}
 /**
  *
  *
@@ -933,16 +1007,21 @@ function tripal_feature_load_gff3_feature($organism,$analysis_id,$cvterm,$unique
          print "   Added analysisfeature record\n";
       }
    } else {
-      // if a score is avaialble then set that to be the significance field
+      // if a score is available then set that to be the significance field
       $new_vals = array();
       if(strcmp($score,'.')!=0){
         $new_vals['significance'] = $score;
-      }
-      if(!$add_only and !tripal_core_chado_update('analysisfeature',$af_values,$new_vals)){
-         print "ERROR: could not update analysisfeature record: $analysis_id, $feature->feature_id\n";
       } else {
-         print "   Updated analysisfeature record\n";
-      } 
+        $new_vals['significance'] = '__NULL__';
+      }
+      if(!$add_only){
+         $ret = tripal_core_chado_update('analysisfeature',$af_values,$new_vals);
+         if(!$ret){
+            print "ERROR: could not update analysisfeature record: $analysis_id, $feature->feature_id\n";
+         } else {
+            print "   Updated analysisfeature record\n";
+         } 
+      }
    }
 
    return $feature;