Browse Source

Various bug fixes and themeing issues

spficklin 14 years ago
parent
commit
bc06d86bf6

+ 43 - 9
tripal_analysis_blast/tripal_analysis_blast.module

@@ -38,7 +38,32 @@ function tripal_analysis_blast_menu() {
 	);
 	return $items;
 }
-
+/*******************************************************************************
+*
+*/
+function tripal_analysis_blast_block($op = 'list', $delta = 0, $edit=array()){
+   switch($op) {
+      case 'list':
+         $blocks['results']['info'] = t('Tripal Blast Analysis Results');
+         $blocks['results']['cache'] = BLOCK_NO_CACHE;
+       return $blocks;
+
+      case 'view':
+         if(user_access('access chado_analysis_blast content') and arg(0) == 'node' and is_numeric(arg(1))) {
+            $nid = arg(1);
+            $node = node_load($nid);
+            $block = array();
+            switch($delta){
+               case 'results':
+                  $block['subject'] = t('Blast Results');
+                  $block['content'] = theme('tripal_analysis_blast_results', $node);
+                  break;
+                default :
+            }
+            return $block;
+         }
+   }
+}
 
 /*******************************************************************************
  * tripal_analysis_blast_nodeapi()
@@ -84,19 +109,28 @@ function tripal_analysis_blast_theme () {
 	return array(
       'tripal_analysis_blast_results_index_version' => array (
          'arguments' => array('node'),
-	),
+	   ),
       'tripal_analysis_blast_results' => array (
-         'arguments' => array('node'),
-	)
+         'arguments' => array('node'=> null),
+         'template' => 'tripal_analysis_blast_results',
+	   ),
 	);
 }
 /*******************************************************************************
  * Prepare blast result for the feature shown on the page
  */
-function theme_tripal_analysis_blast_results ($node) {
-	$feature = $node->feature;
-	$content = tripal_get_blast_results($feature->feature_id, 0, 10, 0);
-	return $content;
+//function theme_tripal_analysis_blast_results ($node) {
+//	$feature = $node->feature;
+//	$content = tripal_get_blast_results($feature->feature_id, 0, 10, 0);
+//	return $content;
+//}
+
+/*******************************************************************************
+ *  
+ */
+function tripal_analysis_blast_preprocess_tripal_analysis_blast_results(&$variables){
+   $feature = $variables['node']->feature;
+   $variables['tripal_analysis_blast']['results'] = tripal_get_blast_results($feature->feature_id, 0, 10, 0);
 }
 
 /*******************************************************************************
@@ -306,7 +340,7 @@ function parse_NCBI_Blast_XML($xml_string,$db,$max,$feature_id,$ajax, $analysis)
 		foreach ($xml_output->children() as $xml_tag) {
 			if ($xml_tag->getName() == 'Iteration_query-def') {
 				// Here we show the feature name again to check if we pull the correct data
-				$html_out .= "Query: $xml_tag<br>";
+//				$html_out .= "Query: $xml_tag<br>";
 			} else if ($xml_tag->getName() == 'Iteration_hits') {
 				$iteration = $xml_tag;
 			}

+ 2 - 2
tripal_core/tripal_core.api.inc

@@ -160,8 +160,8 @@ function tripal_core_chado_insert($table,$values){
    foreach($fields as $field => $def){
       // a field is considered missing if it cannot be null and there is no default
       // value for it or it is of type 'serial'
-      if($def['not null'] == 1 and !$insert_values[$field] and !$def['default'] and strcmp($def['type'],serial)!=0){
-         watchdog('tripal_core',"tripal_core_chado_insert: Field $field cannot be null: " . print_r($values,1),array(),'WATCHDOG_ERROR');
+      if($def['not null'] == 1 and !array_key_exists($field,$insert_values) and !$def['default'] and strcmp($def['type'],serial)!=0){
+         watchdog('tripal_core',"tripal_core_chado_insert: Field $table.$field cannot be null: " . print_r($values,1),array(),'WATCHDOG_ERROR');
          return false;
       }
    }

+ 18 - 6
tripal_feature/fasta_loader.php

@@ -349,7 +349,7 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
    // now load the last sequence in the file
    tripal_feature_fasta_loader_insert_feature($name,$uname,$db_id,
       $accession,$subject,$rel_type,$parent_type,$library_id,$organism_id,$type,
-      $source,$residues,$update);
+      $source,$residues,$update,$re_name);
    return '';
 }
 /*************************************************************************
@@ -357,7 +357,7 @@ function tripal_feature_load_fasta($dfile, $organism_id, $type,
 */
 function tripal_feature_fasta_loader_insert_feature($name,$uname,$db_id,$accession,
               $parent,$rel_type,$parent_type,$library_id,$organism_id,$type, 
-              $source,$residues,$update) 
+              $source,$residues,$update,$re_name) 
 {
    $previous_db = tripal_db_set_active('chado');
 
@@ -391,10 +391,22 @@ function tripal_feature_fasta_loader_insert_feature($name,$uname,$db_id,$accessi
       }
    } else {
        if($update){
-         $sql = "UPDATE {feature} 
-                  SET name = '%s', residues = '%s', seqlen = '%s', md5checksum = '%s'
-                  WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
-         $result = db_query($sql,$name,$residues,strlen($residues),md5($residues),$organism_id,$uname,$cvterm->cvterm_id);
+
+         // we do not want to wipe out the name if the user did not intend for this to
+         // happen.  The uniquename must match the sequence but the name may not.  
+         // so, we'll only update the name if the users specified an 're_name' regular
+         // expression.
+         if($re_name){
+            $sql = "UPDATE {feature} 
+                     SET name = '%s', residues = '%s', seqlen = '%s', md5checksum = '%s'
+                     WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
+            $result = db_query($sql,$name,$residues,strlen($residues),md5($residues),$organism_id,$uname,$cvterm->cvterm_id);
+         } else {
+            $sql = "UPDATE {feature} 
+                     SET residues = '%s', seqlen = '%s', md5checksum = '%s'
+                     WHERE organism_id = %d and uniquename = '%s' and type_id = %d";
+            $result = db_query($sql,$residues,strlen($residues),md5($residues),$organism_id,$uname,$cvterm->cvterm_id);
+         }
          if(!$result){
             print "ERROR: failed to update feature '$name ($uname)'\n";
             return 0;

+ 64 - 12
tripal_feature/gff_loader.php

@@ -458,19 +458,70 @@ function tripal_core_load_gff3_parents($feature,$cvterm,$parents,$gff_features,$
 *
 */
 function tripal_core_load_gff3_dbxref($feature,$dbxrefs){
+
+   // iterate through each of the dbxrefs
    foreach($dbxrefs as $dbxref){
-      // check to see if this accession reference exists, if not add it
-//      $dbxrefsql = "SELECT * FROM {dbxref} WHERE db_id = %s and accession = '%s'";
-//      $dbxref = db_fetch_object(db_query($dbxrefsql,$db_id,$accession));
-//      if(!$dbxref){
-//         $sql = "INSERT INTO {dbxref} (db_id,accession) VALUES (%d,'%s')";
-//         $result = db_query($sql,$db_id,$accession);
-//         if(!$result){
-//           print "WARNING: could not add external database acession: '$name accession: $accession'\n";
-//         }
-//         $dbxref = db_fetch_object(db_query($dbxrefsql,$db_id,$accession));
-//      }
+
+      // get the database name from the reference.  If it doesn't exist then create one.
+      $ref = explode(":",$dbxref);
+      $dbname = $ref[0];
+      $accession = $ref[1];
+
+      // first look for the database name if it doesn't exist then create one.
+      // first check for the fully qualified URI (e.g. DB:<dbname>. If that
+      // can't be found then look for the name as is.  If it still can't be found
+      // the create the database
+      $db = tripal_core_chado_select('db',array('db_id'),array('name' => "DB:$dbname"));      
+      if(sizeof($db) == 0){
+         $db = tripal_core_chado_select('db',array('db_id'),array('name' => "$dbname"));      
+      }        
+      if(sizeof($db) == 0){
+         $ret = tripal_core_chado_insert('db',array('name' => $dbname, 
+           'description' => 'Added automatically by the GFF loader'));
+         if($ret){ 
+            print "Added new database: $dbname\n";
+            $db = tripal_core_chado_select('db',array('db_id'),array('name' => "$dbname"));      
+         } else {
+            print "ERROR: cannot find or add the database $dbname\n";
+            return 0;
+         }
+      } 
+      $db = $db[0];
+       
+      // now check to see if the accession exists
+      $dbxref = tripal_core_chado_select('dbxref',array('dbxref_id'),array(
+         'accession' => $accession,'db_id' => $db->db_id));
+
+      // if the accession doesn't exist then we want to add it
+      if(sizeof($dbxref) == 0){
+         $ret = tripal_core_chado_insert('dbxref',array('db_id' => $db->db_id,
+            'accession' => $accession,'version' => ''));
+         $dbxref = tripal_core_chado_select('dbxref',array('dbxref_id'),array(
+            'accession' => $accession,'db_id' => $db->db_id));
+      }
+      $dbxref = $dbxref[0];
+
+      // check to see if tihs feature dbxref already exists
+      $fdbx = tripal_core_chado_select('feature_dbxref',array('feature_dbxref_id'),
+         array('dbxref_id' => $dbxref->dbxref_id,'feature_id' => $feature->feature_id));
+
+      // now associate this feature with the database reference if it doesn't
+      // already exist
+      if(sizeof($fdbx)==0){
+         $ret = tripal_core_chado_insert('feature_dbxref',array(
+            'feature_id' => $feature->feature_id,
+            'dbxref_id' => $dbxref->dbxref_id));
+         if($ret){
+            print "Adding dbxref $dbname:$accession\n";
+         } else {
+            print "ERROR: failed to insert dbxref: $dbname:$accession\n";
+            return 0;
+         }
+      } else {
+         print "Dbxref already exists, skipping $dbname:$accession\n";
+      }
    }
+   return 1;
 }
 
 /*************************************************************************
@@ -564,8 +615,9 @@ function tripal_core_load_gff3_alias($feature,$aliases){
             print "ERROR: cannot add alias $alias to feature synonym table\n";
             return 0;
          }
+      } else {
+         print "Synonym $alias already exists. Skipping\n";
       }
-      $fsyn = db_fetch_object(db_query($synsql,$synonym->synonym_id,$feature->feature_id,$pub->pub_id));
    }
    return 1;
 }

+ 18 - 1
tripal_feature/syncFeatures.php

@@ -145,6 +145,22 @@ function tripal_feature_sync_feature ($feature_id){
    $feature = db_fetch_object(db_query($fsql,$feature_id));
    tripal_db_set_active($previous_db);  // now use drupal database
 
+   // get the synonyms for this feature
+   $synsql = "SELECT S.name ".
+             "FROM {feature_synonym} FS ".
+             "  INNER JOIN {synonym} S on FS.synonym_id = S.synonym_id ".
+             "WHERE FS.feature_id = %d";
+   $previous_db = tripal_db_set_active('chado');  // use chado database
+   $synonyms = db_query($synsql,$feature_id);
+   tripal_db_set_active($previous_db);  // now use drupal database
+
+   // now add these synonyms to the feature object as a single string   
+   $synstring = '';
+   while($synonym = db_fetch_object($synonyms)){
+      $synstring .= "$synonym->name\n";
+   }        
+   $feature->synonyms = $synstring;
+
    // check to make sure that we don't have any nodes with this feature name as a title
    // but without a corresponding entry in the chado_feature table if so then we want to
    // clean up that node.  (If a node is found we don't know if it belongs to our feature or
@@ -204,12 +220,13 @@ function tripal_feature_sync_feature ($feature_id){
       $new_node->type = 'chado_feature';
       $new_node->uid = $user->uid;
       $new_node->title = "$feature->name, $feature->uniquename ($feature->cvname) $organism->genus $organism->species";
-      $new_node->name = "$feature->name";
+      $new_node->fname = "$feature->name";
       $new_node->uniquename = "$feature->uniquename";
       $new_node->feature_id = $feature->feature_id;
       $new_node->residues = $feature->residues;
       $new_node->organism_id = $feature->organism_id;
       $new_node->feature_type = $feature->cvname;
+      $new_node->synonyms = $feature->synonyms;
 
       // validate the node and if okay then submit
       node_validate($new_node);

+ 12 - 8
tripal_feature/tripal_feature.module

@@ -387,7 +387,7 @@ function chado_feature_insert($node){
 
       // use chado database
       $previous_db = tripal_db_set_active('chado');
-      db_query($sql,$node->organism_id,$node->name,$node->uniquename,
+      db_query($sql,$node->organism_id,$node->fname,$node->uniquename,
       $residues,strlen($residues),$obsolete,$node->feature_type);
 
       // now that we've added the feature, get the feature id for this feature
@@ -477,7 +477,7 @@ function chado_feature_update($node){
          $obsolete = 'TRUE';
       }
       $previous_db = tripal_db_set_active('chado');  // use chado database
-      db_query($sql,$residues,$node->name,$node->uniquename,
+      db_query($sql,$residues,$node->fname,$node->uniquename,
       strlen($residues),$node->organism_id,$obsolete,$node->feature_type,
       $feature->feature_id);
       tripal_db_set_active($previous_db);  // now use drupal database
@@ -492,6 +492,8 @@ function chado_feature_update($node){
  */
 function chado_feature_add_synonyms($synonyms,$feature_id){
 
+drupal_set_message($synonyms);
+
    // make sure we only have a single space between each synonym
    $synonyms = preg_replace("/[\s\n\r]+/"," ",$synonyms);
    // split the synonyms into an array based on a space as the delimieter
@@ -655,7 +657,7 @@ function chado_feature_form ($node,$param){
       '#type' => 'textfield',
       '#title' => t('Title'),
       '#required' => TRUE,
-      '#default_value' => $feature->featurename,
+      '#default_value' => $node->title,
       '#description' => t('The title must be a unique identifier for this feature.  It is recommended to use a combination of uniquename, organism and feature type in the title as this is guranteed to be unique.'),
       '#weight' => 1,
       '#maxlength' => 255
@@ -665,13 +667,13 @@ function chado_feature_form ($node,$param){
       '#type' => 'textfield',
       '#title' => t('Unique Feature Name'),
       '#required' => TRUE,
-      '#default_value' => $feature->featurename,
+      '#default_value' => $feature->uniquename,
       '#description' => t('Enter a unique name for this feature.  This name must be unique for the organism and feature type.'),
       '#weight' => 1,
       '#maxlength' => 255
    );
 
-   $form['name']= array(
+   $form['fname']= array(
       '#type' => 'textfield',
       '#title' => t('Feature Name'),
       '#required' => TRUE,
@@ -852,7 +854,7 @@ function chado_feature_load($node){
    // add details about the organism
    $additions->organism = tripal_feature_load_organism($organism_id);
    // add the list of synomyms
-//   $additions->synonyms = tripal_feature_load_synonyms($feature_id);
+   $additions->synonyms = tripal_feature_load_synonyms($feature_id);
 
    return $additions;
 }
@@ -876,7 +878,8 @@ function tripal_feature_load_synonyms ($feature_id){
           "FROM {Feature_Synonym} FS ".
           "  INNER JOIN {Synonym} S ".
           "    ON FS.synonym_id = S.Synonym_id ".
-          "WHERE FS.feature_id = %d";
+          "WHERE FS.feature_id = %d ".
+          "ORDER BY S.name ";
    $previous_db = tripal_db_set_active('chado');  // use chado database
    $results = db_query($sql,$feature_id);
    tripal_db_set_active($previous_db);  // now use drupal database
@@ -923,7 +926,8 @@ function tripal_feature_load_references ($feature_id){
           "  INNER JOIN {feature_dbxref} FDBX on F.feature_id = FDBX.feature_id ".
           "  INNER JOIN {dbxref} DBX on DBX.dbxref_id = FDBX.dbxref_id ".
           "  INNER JOIN {db} on DB.db_id = DBX.db_id ".
-          "WHERE F.feature_id = %d";
+          "WHERE F.feature_id = %d ".
+          "ORDER BY DB.name ";
    $previous_db = tripal_db_set_active('chado');  // use chado database
    $results = db_query($sql,$feature_id);
    tripal_db_set_active($previous_db);  // now use drupal database