spficklin 14 vuotta sitten
vanhempi
commit
05d50175b0

+ 73 - 3
tripal_analysis/tripal_analysis.api.inc

@@ -12,7 +12,7 @@
  * @return
  *    Array describing the analysisfeature table
  */
-function tripal_stock_chado_analysisfeature_schema() {
+function tripal_analysis_chado_analysisfeature_schema() {
   $description = array();
 
   $description['foreign keys']['feature'] = array(
@@ -40,7 +40,7 @@ function tripal_stock_chado_analysisfeature_schema() {
  * @return
  *    Array describing the analysisprop table
  */
-function tripal_stock_chado_analysisprop_schema() {
+function tripal_analysis_chado_analysisprop_schema() {
   $description = array();
 
   $description['foreign keys']['cvterm'] = array(
@@ -58,4 +58,74 @@ function tripal_stock_chado_analysisprop_schema() {
   );
 
   return $description;
-}
+}
+/**
+* Adds a single property to an existing analysis record.
+*
+* @ingroup tripal_api
+*/
+function tripal_analysis_get_property($analysis_id,$property){
+   // construct the array of values to be inserted  
+   $values = array (
+      'analysis_id' => $analysis_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+         'is_obsolete' => 0
+      ),
+   );
+   $columns = array('type_id','value');
+   $results = tripal_core_chado_select('analysisprop',$columns,$values);
+   // this next bit is a hack until we get the recursive add vars routine written
+   foreach($results as $prop){
+      $prop->type_id = new stdClass();
+      $prop->type_id->table_name = 'cvterm';
+      $prop->type_id->name = $property;
+   }
+   return $results;
+}
+/**
+* Adds a single property to an existing analysis record.
+*
+* @ingroup tripal_api
+*/
+function tripal_analysis_insert_property($analysis_id,$property,$value){
+   // construct the array of values to be inserted  
+   $values = array (
+      'analysis_id' => $analysis_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+         'is_obsolete' => 0
+      ),
+      'value' => $value, 
+      'rank' => 0,
+   );
+   return tripal_core_chado_insert('analysisprop',$values);
+}
+/**
+* Adds a single property to an existing analysis record.
+*
+* @ingroup tripal_api
+*/
+function tripal_analysis_update_property($analysis_id,$property,$value){
+   // construct the array that will match the exact record to update
+   $match = array (
+      'analysis_id' => $analysis_id,
+      'type_id' => array ( 
+         'cv_id' => array (
+            'name' => 'tripal',
+         ),
+         'name' => $property,
+      ),
+   );
+   // construct the array of values to be updated
+   $values = array (      
+      'value' => $value, 
+   );
+   return tripal_core_chado_update('analysisprop',$match,$values);
+}

+ 49 - 44
tripal_analysis/tripal_analysis.module

@@ -13,14 +13,6 @@
  * @}
  */
 
-/*******************************************************************************
- * Note: When we pull information for an analysis from chado database. We use
- * 'analysisname' instead of just 'name' to avoid name collision with drupal's
- * node->name variable. Therefore, the SQL statement used is 'SELECT name AS
- * analysisname FROM Analysis', instead of 'SELECT name FROM Analysis'. All
- * other node variables have exact same name as the column name.
- ******************************************************************************/
-
 require('tripal_analysis.api.inc');
 
 /*************************************************************************
@@ -163,17 +155,22 @@ function chado_analysis_insert($node){
 
 	// If the analysis doesn't exist then let's create it in chado.
 	if(!$analysis){
-		// First add the item to the chado analysis table
-		$sql = "INSERT INTO {analysis} ".
-             "  (name, description, program, programversion, algorithm, ".
-             "   sourcename, sourceversion, sourceuri, timeexecuted) ".
-             "VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s')";
-		$previous_db = tripal_db_set_active('chado');  // use chado database
-		db_query($sql,$node->analysisname, $node->description,
-		$node->program,$node->programversion,$node->algorithm,
-		$node->sourcename, $node->sourceversion, $node->sourceuri,
-		$timestamp);
-      tripal_db_set_active($previous_db);
+      // insert and then get the newly inserted analysis record
+      $values = array(
+          'name' => $node->analysisname, 
+          'description' => $node->description,
+          'program' => $node->program,
+          'programversion' => $node->programversion,
+          'algorithm' => $node->algorithm,
+          'sourcename' => $node->sourcename,
+          'sourceversion' => $node->sourceversion,
+          'sourceuri' => $node->sourceuri,
+          'timeexecuted' => $timestamp
+      );
+      if(tripal_core_chado_insert('analysis',$values)){
+         $analysis = tripal_core_chado_select('analysis',array('*'),$values);
+         $analysis_id = $analysis[0]->analysis_id;
+      }
 	}
 
 	// Make sure the entry for this analysis doesn't already exist in the
@@ -201,6 +198,10 @@ function chado_analysis_insert($node){
 		drupal_write_record('node',$record,'nid');
 		drupal_write_record('node_revisions',$record,'nid');
 	}
+
+   // add the analysis to the node object for
+   // use by other analysis modules that may be using this function
+   $node->analysis = $analysis;
 }
 /*******************************************************************************
  *
@@ -301,17 +302,20 @@ function chado_analysis_update($node){
  */
 function chado_analysis_form ($node){
 
-	$type = node_get_types('type', $node);
 	$form = array();
 	$form['title']= array(
       '#type' => 'hidden',
       '#default_value' => $node->title,
+	);
+	$form['analysis_id']= array(
+      '#type' => 'hidden',
+      '#default_value' => $node->analysis->analysis_id,
 	);
 	$form['analysisname']= array(
       '#type' => 'textfield',
       '#title' => t('Analysis Name'),
       '#required' => FALSE,
-      '#default_value' => $node->analysisname,
+      '#default_value' => $node->analysis->name,
       '#description' => t("This should be a handy short identifier that 
          describes the analysis succintly as possible which helps the user find analyses."),
       '#weight' => 1
@@ -320,7 +324,7 @@ function chado_analysis_form ($node){
       '#type' => 'textfield',
       '#title' => t('Program'),
       '#required' => TRUE,
-      '#default_value' => $node->program,
+      '#default_value' => $node->analysis->program,
       '#description' => t("Program name, e.g. blastx, blastp, sim4, genscan."),
       '#weight' => 2
 	);
@@ -328,7 +332,7 @@ function chado_analysis_form ($node){
       '#type' => 'textfield',
       '#title' => t('Program Version'),
       '#required' => TRUE,
-      '#default_value' => $node->programversion,
+      '#default_value' => $node->analysis->programversion,
       '#description' => t("Version description, e.g. TBLASTX 2.0MP-WashU [09-Nov-2000]"),
       '#weight' => 3
 	);
@@ -336,7 +340,7 @@ function chado_analysis_form ($node){
       '#type' => 'textfield',
       '#title' => t('Algorithm'),
       '#required' => FALSE,
-      '#default_value' => $node->algorithm,
+      '#default_value' => $node->analysis->algorithm,
       '#description' => t("Algorithm name, e.g. blast."),
       '#weight' => 4
 	);
@@ -344,7 +348,7 @@ function chado_analysis_form ($node){
       '#type' => 'textfield',
       '#title' => t('Source Name'),
       '#required' => TRUE,
-      '#default_value' => $node->sourcename,
+      '#default_value' => $node->analysis->sourcename,
       '#description' => t('The name of the source data.  This could be a file name, data set name or a 
            small description for how the data was collected.  For long descriptions use the description field below'),
 
@@ -354,7 +358,7 @@ function chado_analysis_form ($node){
       '#type' => 'textfield',
       '#title' => t('Source Version'),
       '#required' => FALSE,
-      '#default_value' => $node->sourceversion,
+      '#default_value' => $node->analysis->sourceversion,
       '#description' => t('If the source dataset has a version, include it here'),
       '#weight' => 6
 	);
@@ -362,14 +366,14 @@ function chado_analysis_form ($node){
       '#type' => 'textfield',
       '#title' => t('Source URI'),
       '#required' => FALSE,
-      '#default_value' => $node->sourceuri,
+      '#default_value' => $node->analysis->sourceuri,
       '#description' => t("This is a permanent URL or URI for the source of the analysis. 
          Someone could recreate the analysis directly by going to this URI and 
          fetching the source data (e.g. the blast database, or the training model)."),
       '#weight' => 7
 	);
 	// Get time saved in chado
-	$default_time = $node->timeexecuted;
+	$default_time = $node->analysis->timeexecuted;
 	$year = preg_replace("/^(\d+)-\d+-\d+ .*/", "$1", $default_time);
 	$month = preg_replace("/^\d+-0?(\d+)-\d+ .*/", "$1", $default_time);
 	$day = preg_replace("/^\d+-\d+-0?(\d+) .*/", "$1", $default_time);
@@ -396,7 +400,7 @@ function chado_analysis_form ($node){
       '#rows' => 15,
       '#title' => t('Description and/or Program Settings'),
       '#required' => FALSE,
-      '#default_value' => check_plain($node->description),
+      '#default_value' => check_plain($node->analysis->description),
       '#description' => t('Please provide all necessary information to allow
          someone to recreate the analysis, including materials and methods
          for collection of the source data and performing the analysis'),
@@ -413,19 +417,20 @@ function chado_analysis_form ($node){
  * @ingroup tripal_analysis
  */
 function chado_analysis_load($node){
-	// get the analysis_id for this node:
-	$sql = "SELECT analysis_id FROM {chado_analysis} WHERE vid = %d";
-	$ana_node = db_fetch_object(db_query($sql, $node->vid));
 	$additions = new stdClass();
+
+	// get the analysis_id for this node:
+	$sql = "SELECT analysis_id FROM {chado_analysis} WHERE nid = %d";
+	$ana_node = db_fetch_object(db_query($sql, $node->nid));
 	if ($ana_node) {
 		// get analysis information
-		$sql = "SELECT Analysis_id, name AS analysisname, description, program, ".
+		$sql = "SELECT Analysis_id, name, description, program, ".
              "  programversion, algorithm, sourcename, sourceversion, ".
              "  sourceuri, timeexecuted ".
              "FROM {Analysis} ".
              "WHERE Analysis_id = $ana_node->analysis_id";
 		$previous_db = tripal_db_set_active('chado');  // use chado database
-		$additions = db_fetch_object(db_query($sql));
+		$additions->analysis = db_fetch_object(db_query($sql));
 
       // get number of features assc with this analysis
 //     $sql = "SELECT count(feature_id) as featurecount ".
@@ -437,11 +442,11 @@ function chado_analysis_load($node){
 	}
 	// If the analysis has a name, use it as the node title. If not, construct
 	// the title using program programversion, and sourcename
-	if ($additions->analysisname) {
-		$additions->title = $additions->analysisname;
+	if ($additions->analysis->name) {
+		$additions->title = $additions->analysis->name;
 	} else {
 		// Construct node title as "program version (source)
-		$additions->title = "$additions->program ($additions->programversion)";
+		$additions->title = "$additions->analysis->program ($additions->analysis->programversion)";
 	}
 	return $additions;
 }
@@ -480,7 +485,7 @@ function tripal_analysis_sync_analyses ($analysis_id = NULL, $job_id = NULL){
 	$page_content = '';
     
 	if(!$analysis_id){
-		$sql = "SELECT Analysis_id, name AS analysisname, description, program, ".
+		$sql = "SELECT Analysis_id, name, description, program, ".
    		 "  programversion, algorithm, sourcename, sourceversion, sourceuri, ".
           "  timeexecuted ".
           "FROM {Analysis} ";
@@ -488,7 +493,7 @@ function tripal_analysis_sync_analyses ($analysis_id = NULL, $job_id = NULL){
 		$results = db_query($sql);
 		tripal_db_set_active($previous_db);  // now use drupal database
 	} else {
-		$sql = "SELECT Analysis_id, name AS analysisname, description, program, ".
+		$sql = "SELECT Analysis_id, name, description, program, ".
    		  "  programversion, algorithm, sourcename, sourceversion, sourceuri, ".
           "  timeexecuted ".
           "FROM {Analysis} ".
@@ -506,7 +511,7 @@ function tripal_analysis_sync_analyses ($analysis_id = NULL, $job_id = NULL){
 
 	while($analysis = db_fetch_object($results)){
         print "syncing analysis ";
-        print $analysis->analysisname;
+        print $analysis->name;
         print ", ";
         print $analysis->analysis_id;
         print "\n";
@@ -555,7 +560,7 @@ function tripal_analysis_sync_analyses ($analysis_id = NULL, $job_id = NULL){
 
 			$new_node->uid = $user->uid;
 			$new_node->analysis_id = $analysis->analysis_id;
-			$new_node->analysisname = $analysis->analysisname;
+			$new_node->analysisname = $analysis->name;
 			$new_node->description = $analysis->description;
 			$new_node->program = $analysis->program;
 			$new_node->programversion = $analysis->programversion;
@@ -693,7 +698,7 @@ function get_chado_analyses() {
 		$sql = "SELECT analysis_id, CA.nid, type FROM {chado_analysis} CA INNER JOIN node ON CA.nid = node.nid";
 		$result = db_query($sql);
 		$previous_db = tripal_db_set_active('chado');
-		$sql = "SELECT Analysis_id, name AS analysisname, description, program, 
+		$sql = "SELECT Analysis_id, name, description, program, 
 		                       programversion, algorithm, sourcename, sourceversion, 
 		                       sourceuri, timeexecuted
 		           FROM {Analysis} 		           WHERE analysis_id=%d";
@@ -738,13 +743,13 @@ function theme_tripal_analysis_analysis_page($analyses) {
       // Generate html output
 		$output .= "<div class=\"tripal_chado_analysis-info-box\" style=\"padding:5px\">
                          <div class=\"tripal_expandableBox\">
-                           <h3>$analysis->analysisname ($date)</h3>
+                           <h3>$analysis->name ($date)</h3>
                          </div>
                          <div class=\"tripal_expandableBoxContent\">
                            <span>
                              <table class=\"tripal_chado_analysis_content\">
                                <tr><td>
-                                 Name: <a href=\"$ana_node_url\">$analysis->analysisname</a>
+                                 Name: <a href=\"$ana_node_url\">$analysis->name</a>
                                </td></tr>
                                <tr><td>
                                  Program: $analysis->program ($analysis->programversion)

+ 3 - 3
tripal_analysis_blast/tripal_analysis_blast.module

@@ -792,7 +792,7 @@ function chado_analysis_blast_form ($node){
    // add in the analysis fields
    $analysis_form_elements = chado_analysis_form(null);
    foreach ($analysis_form_elements as $key => $element){
-      $form = $element;
+      $form[$key] = $element;
    }
 
 	// Blast specific settings
@@ -1151,8 +1151,8 @@ function chado_analysis_blast_update($node){
  */
 function chado_analysis_blast_load($node){
 	// get the analysis_id for this node:
-	$sql = "SELECT analysis_id FROM {chado_analysis} WHERE vid = %d";
-	$ana_node = db_fetch_object(db_query($sql, $node->vid));
+	$sql = "SELECT analysis_id FROM {chado_analysis} WHERE nid = %d";
+	$ana_node = db_fetch_object(db_query($sql, $node->nid));
 	$additions = new stdClass();
 	if ($ana_node) {
 		// get analysis information

+ 79 - 87
tripal_analysis_unigene/tripal_analysis_unigene.install

@@ -24,104 +24,96 @@ function tripal_analysis_unigene_install() {
    }
    tripal_db_set_active($previous_db);
    
+
+   tripal_analysis_unigene_add_cvterms();
+   tripal_analysis_unigene_add_organism_unigene_mview();
+
+}
+
+/**
+*
+*/
+function tripal_analysis_unigene_update_6000(){
+
+   // we have some new cvterms to add
+   tripal_analysis_unigene_add_cvterms();
+
+   // remove the old unigene materialized view and add the new one.
+   $mview = tripal_mviews_get_mview_id('unigene_mview');
+   if($mview){
+      tripal_mviews_action('delete',$mview);
+   }
+   tripal_analysis_unigene_add_organism_unigene_mview();
+
+   $ret = array(
+      '#finished' => 1,
+   );
+   
+   return $ret;
+}
+/**
+*
+*/
+function tripal_analysis_unigene_add_cvterms(){
    tripal_add_cvterms('unigene_version','The version number for the unigene ".
      "(e.g. v1, v2, etc...) ');
+   tripal_add_cvterms('analysis_unigene_name', 'The name for a unigene.');
+   tripal_add_cvterms('analysis_unigene_num_contigs','The number of contigs in the unigene assembly');
+   tripal_add_cvterms('analysis_unigene_num_singlets','The number of singlets remaining in the unigene assembly');
+   tripal_add_cvterms('analysis_unigene_num_clusters','The number of clusters in the unigene assembly');
+   tripal_add_cvterms('analysis_unigene_num_reads','The number of reads, after filtering, used as input for the assembly');
    tripal_add_cvterms('singlet',"Indicates the feature is a singlet in a ".
      "specific unigene version (e.g. v1, v2, etc...). The value specified ".
      "should match that of the unigene_version");
 
-   //tripal_add_mview('unigene_libraries_mview',
-     //'tripal_analysis_unigene',
-     //'unigene_libraries_mview',
-     //'analysis_name character varying(255), analysis_id integer,  '.
-     //'organism_common_name character varying(255), organism_id integer, '.
-     //'library_name character varying(255), library_id integer, '.
-     //'library_type character varying(255)',
-     //'analysis_id,organism_id,library_id',
-     //"select A.name as analysis_name, A.analysis_id, ".
-     //"         O.common_name as organism_common_name, O.organism_id, ".
-     //"         L.name as library_name, L.library_id,".
-     //"         CV.name as library_type ".
-     //"FROM {Analysis} A ".
-     //"INNER JOIN Analysisfeature AF ON A.analysis_id = AF.analysis_ID ".
-     //"INNER JOIN Featureloc FL ON AF.feature_id = FL.feature_ID ".
-     //"INNER JOIN Feature F ON FL.srcfeature_id = F.feature_id ".
-     //"INNER JOIN Organism O ON F.organism_id = O.organism_id ".
-     //"INNER JOIN Library_feature LF ON F.feature_id = LF.feature_id ".
-     //"INNER JOIN Library L ON LF.library_id = L.library_id ".
-     //"INNER JOIN CVterm CV ON L.type_id = CV.cvterm_id ".
-     //"GROUP BY A.analysis_id, A.name, O.common_name, O.organism_id, ".
-     //"   L.library_id, L.name, CV.name",
-     //''
-   //);
-
-   tripal_add_mview('unigene_mview',
+   // Add cveterm 'analysis_unigene_settings' for inserting into analysisprop table   
+   tripal_add_cvterms('analysis_unigene_settings', 'Settings of a unigene analysis');
+}
+/**
+*
+*/
+function tripal_analysis_unigene_add_organism_unigene_mview(){
+
+   $view_name = 'organism_unigene_mview';
+
+   // Drop the MView table if it exists
+   $mview_id = tripal_mviews_get_mview_id($view_name);
+   if($mview_id){
+      tripal_mviews_action("delete",$mview_id);
+   }
+
+   tripal_add_mview(
+      // view name
+      $view_name,
+      // tripal module name
       'tripal_analysis_unigene',
-      'unigene_mview',
-      'analysis_id integer, name character varying(255), description text, '.
-      'program character varying(255), programversion character varying(255), '.
-      'algorithm character varying(255), sourcename character varying(255), '.
-      'sourceversion character varying(255), sourceuri text, '.
-      'timeexecuted timestamp,  organism_id integer, '.
-      'uversion text, adate text, num_ests integer, '.
-		'num_contigs integer, num_singlets integer',
-	   'analysis_id, organism_id',
-	   "SELECT Distinct A.analysis_id, A.name, A.description, A.program, A.programversion, A.algorithm, ".
-      "  A.sourcename, A.sourceversion, A.sourceuri, A.timeexecuted, O.organism_id, ".
-      "  AP.value as uversion, AP2.value as adate,    ".
-      " (SELECT count(*) FROM {feature} F  ".
-      "   INNER JOIN CVTerm CVT on F.type_id = CVT.cvterm_id  ".
-      "   INNER JOIN CV on CVT.cv_id = CV.cv_id ".
-      "   INNER JOIN analysisfeature AF on AF.feature_id = F.feature_id ".
-      " WHERE CVT.name = 'EST' and ".
-      "       CV.name = 'sequence' and ".
-      "       AF.analysis_id = A.analysis_id) as num_ests, ".
-      " (SELECT count(*) FROM {feature} F  ".
-      "    INNER JOIN CVTerm CVT on F.type_id = CVT.cvterm_id  ".
-      "    INNER JOIN CV on CVT.cv_id = CV.cv_id ".
-      "    INNER JOIN analysisfeature AF on AF.feature_id = F.feature_id ".
-      "  WHERE CVT.name = 'contig' and ".
-      "         CV.name = 'sequence' and ".
-      "         AF.analysis_id = A.analysis_id) as num_contigs, ".
-      " (SELECT count(*) FROM {feature} F  ".
-      "    INNER JOIN CVTerm CVT on F.type_id = CVT.cvterm_id  ".
-      "    INNER JOIN CV on CVT.cv_id = CV.cv_id ".
-      "    INNER JOIN analysisfeature AF on AF.feature_id = F.feature_id ".
-      "    INNER JOIN analysisprop AP on AP.analysis_id = AF.analysis_id ".
-      "    INNER JOIN CVTerm CVT2 on CVT2.cvterm_id = AP.type_id ".
-      "    INNER JOIN CV CV2 on CVT2.cv_id = CV2.cv_id ".
-      "  WHERE CVT.name = 'contig' and  ".
-      "         CV.name = 'sequence' and  ".
-      "       CVT2.name = 'singlet' and  ".
-      "         CV.name = 'tripal'  and  ".
-      "         AF.analysis_id = A.analysis_id) as num_singlets ".
+      // table name
+      $view_name,
+      // table schema definition
+      'analysis_id integer, organism_id integer',
+      // columns for indexing
+      'analysis_id, organism_id',
+      // SQL statement to populate the view
+	   "SELECT DISTINCT A.analysis_id, O.organism_id ".
       "FROM {Analysis} A ".
-      "  INNER JOIN Analysisprop AP ".
-      "    ON A.analysis_id = AP.analysis_id ".
-      "  INNER JOIN CVterm CV ".
-      "    ON AP.type_id = CV.cvterm_ID ".
-      "  INNER JOIN Analysisprop AP2 ".
-      "    ON A.analysis_id = AP2.analysis_id ".
-      "  INNER JOIN CVterm CV2 ".
-      "    ON AP2.type_id = CV2.cvterm_ID   ".
-      "  INNER JOIN Analysisfeature AF ".
-      "    ON A.analysis_id = AF.analysis_ID ".
-      "  INNER JOIN Feature F  ".
-      "    ON AF.Feature_ID = F.Feature_ID ".
-      "  INNER JOIN CVterm CV4 ".
-      "    ON F.type_id = CV4.cvterm_id  ".
-      "  INNER JOIN Organism O ".
-      "    ON F.Organism_ID = O.Organism_ID ".
-      "WHERE ".
-      "  CV.name = 'unigene_version' ".
-      "  AND CV2.name = 'analysis_date' ".
-      "GROUP BY A.analysis_id, A.name, A.description, A.program, ".
-      "   A.programversion, A.algorithm, A.sourcename, A.sourceversion, ".
-      "   A.sourceuri, A.timeexecuted, AP.value, AP2.value, O.organism_id", 
+      "  INNER JOIN analysisprop AP    ON AP.analysis_id = A.analysis_id ".
+      "  INNER JOIN cvterm CVT         ON AP.type_id = CVT.cvterm_id ".
+      "  INNER JOIN cv CV              ON CV.cv_id = CVT.cv_id ".
+      "  INNER JOIN analysisfeature AF ON A.analysis_id = AF.analysis_id ".
+      "  INNER JOIN feature F          ON AF.feature_id = F.feature_id ".
+      "  INNER JOIN organism O         ON F.organism_id = O.organism_id ".
+      "WHERE CV.name = 'tripal' AND CVT.name='analysis_unigene_name'",
+      // special index 
 	   ''
    );
-}
 
+   // add a job to the job queue so this view gets updated automatically next
+   // time the job facility is run
+   $mview_id = tripal_mviews_get_mview_id($view_name);
+   if($mview_id){
+      tripal_mviews_action('update',$mview_id);
+   }
+}
 /*******************************************************************************
  * Implementation of hook_uninstall().
  */

+ 288 - 265
tripal_analysis_unigene/tripal_analysis_unigene.module

@@ -1,49 +1,251 @@
 <?php
-// $Id:
-//
-// Copyright 2009 Clemson University
-//
 
 function tripal_analysis_unigene_init(){
    // Add style sheet
-   drupal_add_css(drupal_get_path('theme', 'tripal').
-                                  '/css/tripal_analysis_unigene.css');
+   drupal_add_css(drupal_get_path('theme', 'tripal').'/css/tripal_analysis_unigene.css');
+}
+/**
+*
+*/
+function tripal_analysis_unigene_node_info() {
+	$nodes = array();
+	$nodes['chado_analysis_unigene'] = array(
+      'name' => t('Analysis: Unigene'),
+      'module' => 'chado_analysis_unigene',
+      'description' => t('A unigene assembly constructed from transcriptomic reads.'),
+      'has_title' => FALSE,
+      'title_label' => t('Analysis: Unigene'),
+      'has_body' => FALSE,
+      'body_label' => t('Unigene Analysis Description'),
+      'locked' => TRUE
+	);
+	return $nodes;
 }
-
 /*******************************************************************************
- * HOOK: Implemntation of hook_menu() to provide a call back for EST Assembly Tab
+ * Set the permission types that the chado module uses.  Essentially we
+ * want permissionis that protect creation, editing and deleting of chado
+ * data objects
  */
-function tripal_analysis_unigene_menu() {
-	$items['node/%/assembly'] = array(
-      'title' => t('EST Assemblies'),
-      'page callback' => 'tripal_analysis_unigene_organism_assembly',
-      'page arguments' => array(1),
-      'access callback' => 'tripal_analysis_unigene_node_has_menu',
-      'access arguments' => array('access chado_analysis content',1),
-      'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM
+function chado_analysis_unigene_perm(){
+   return array(
+      'access chado_analysis_unigene content',
+      'create chado_analysis_unigene content',
+      'delete chado_analysis_unigene content',
+      'edit chado_analysis_unigene content',
    );
-   return $items;
 }
+
 /*******************************************************************************
- * Dynamic addition/removal of menu item
+ *  The following function proves access control for users trying to
+ *  perform actions on data managed by this module
  */
-function tripal_analysis_unigene_node_has_menu($type,$vid){
-   // check to see if this node is an organism node
-   $sql = 'SELECT organism_id FROM {chado_organism} WHERE vid = %d';
-   $result = db_query($sql, $vid);
-
-   // menu status
-   $box_status =variable_get("tripal_analysis_unigene-box-assembly","menu_off");
-
-   // if this node is not an organism or a feature node then return false
-   // we don't want the menu item to be shown, otherwise get the normal perms
-   if($org_id = db_fetch_object($result)){
-      if(strcmp($box_status,"menu_on")==0){
-         return user_access($type);
+function chado_analysis_unigene_access($op, $node, $account){
+   if ($op == 'create') {
+      return user_access('create chado_analysis_unigene content', $account);
+   }
+
+   if ($op == 'update') {
+      if (user_access('edit chado_analysis_unigene content', $account)) {
+         return TRUE;
+      }
+   }
+   if ($op == 'delete') {
+      if (user_access('delete chado_analysis_unigene content', $account)) {
+         return TRUE;
       }
+   }
+   if ($op == 'view') {
+      if (user_access('access chado_analysis_unigene content', $account)) {
+         return TRUE;
+      }
+   }
+   return FALSE;
+}
+/**
+*
+*/
+function chado_analysis_unigene_form ($node){
+
+	$form = array();
+
+   $unigene = $node->analysis->tripal_analysis_unigene;
+   $unigene_name = $unigene->unigene_name;
+   $num_reads    = $unigene->num_reads;
+   $num_clusters = $unigene->num_clusters;
+   $num_contigs = $unigene->num_contigs;
+   $num_singlets = $unigene->num_singlets;
+
+	$form['unigene_name'] = array(
+      '#title' => t('Unigene Name'),
+      '#type' => 'textfield',
+      '#required' => TRUE,
+      '#description' => t('A distinct name used to identify this unigene'),
+      '#default_value' => $unigene_name,
+	);
+
+	$form['num_reads'] = array(
+      '#title' => t('Number of Reads'),
+      '#type' => 'textfield',
+      '#required' => FALSE,
+      '#description' => t('Provide the number of reads, after filtering that were used for input into the assembly'),
+      '#default_value' => $num_reads,
+	);
+
+	$form['num_clusters'] = array(
+      '#title' => t('Number of Clusters'),
+      '#type' => 'textfield',
+      '#required' => FALSE,
+      '#description' => t('Provide the number of clusters generated by the asssembly if a clustering mechanism was used for unigene constructions'),
+      '#default_value' => $num_clusters,
+	);
+
+	$form['num_contigs'] = array(
+      '#title' => t('Number of Contigs'),
+      '#type' => 'textfield',
+      '#required' => FALSE,
+      '#description' => t('Provide the number of contigs generated by the assembly'),
+      '#default_value' => $num_contigs,
+	);
+
+	$form['num_singlets'] = array(
+      '#title' => t('Number of Singlets'),
+      '#type' => 'textfield',
+      '#required' => FALSE,
+      '#description' => t('Provide the number of singlets remaining in the assembly'),
+      '#default_value' => $num_singlets,
+	);
+
+
+
+   // add in the analysis fields
+   $analysis_form_elements = chado_analysis_form($node);
+   foreach ($analysis_form_elements as $key => $element){
+      $form[$key] = $element;
+   }
+   return $form;
+}
+/**
+*
+*/
+function chado_analysis_unigene_insert($node){
+   // insert the analysis
+   chado_analysis_insert($node);
+
+   // add the unigene name as a property of the anslysis
+   tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_name',$node->unigene_name);	
+   tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_num_contigs',$node->num_contigs);	
+   tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_num_reads',$node->num_reads);	
+   tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_num_clusters',$node->num_clusters);	
+   tripal_analysis_insert_property($node->analysis->analysis_id,'analysis_unigene_num_singlets',$node->num_clusters);	
+}
+/**
+*
+*/
+function chado_analysis_unigene_update($node){
+   chado_analysis_update($node); 
+
+   // check to see if the property exists first if not then insert, if it does then update
+   $unigene_name = tripal_analysis_get_property($node->analysis_id,'analysis_unigene_name');
+   $num_contigs  = tripal_analysis_get_property($node->analysis_id,'analysis_unigene_num_contigs');
+   $num_reads    = tripal_analysis_get_property($node->analysis_id,'analysis_unigene_num_reads');
+   $num_clusters = tripal_analysis_get_property($node->analysis_id,'analysis_unigene_num_clusters');
+   $num_singlets = tripal_analysis_get_property($node->analysis_id,'analysis_unigene_num_singlets');
+
+
+   // update the unigene name as a property of the anslysis, but if for some
+   // reason it's missing then add it (do the same for all properties)
+   if(count($unigene_name)==0){
+      tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_name',$node->unigene_name);	
+   } else {
+      tripal_analysis_update_property($node->analysis_id,'analysis_unigene_name',$node->unigene_name);	
+   }
+
+   if(count($num_contigs)==0){
+      tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_num_contigs',$node->num_contigs);	
+   } else {
+      tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_contigs',$node->num_contigs);	
+   }
+
+   if(count($num_reads)==0){
+      tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_num_reads',$node->num_reads);	
    } else {
-      return FALSE;
+      tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_reads',$node->num_reads);	
+   }
+
+   if(count($num_clusters)==0){
+      tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_num_clusters',$node->num_clusters);	
+   } else {
+      tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_clusters',$node->num_clusters);	
+   }
+
+   if(count($num_singlets)==0){
+      tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_num_singlets',$node->num_singlets);	
+   } else {
+      tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_singlets',$node->num_singlets);	
+   }
+
+   
+}
+/**
+*
+*/
+function chado_analysis_unigene_delete($node){
+  // delete the unigene name as a property of the anslysis
+//  tripal_analysis_delete_property($node->analysis_id,'analysis_unigene_name',$node->unigene_name);	
+
+  chado_analysis_delete($node);
+}
+/**
+*
+*/
+function chado_analysis_unigene_view ($node, $teaser = FALSE, $page = FALSE) {
+   // use drupal's default node view:
+   $node = node_prepare($node, $teaser);
+   return $node;
+}
+/**
+*
+*/
+function chado_analysis_unigene_load($node){
+
+   // load the default set of analysis fields
+	$additions = chado_analysis_load($node);
+
+   // create some variables for easier lookup
+   $analysis = $additions->analysis;
+   $analysis_id = $analysis->analysis_id;
+
+   // add in the properties
+   $unigene_name = tripal_analysis_get_property($analysis_id,'analysis_unigene_name');
+   $num_contigs  = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_contigs');
+   $num_reads    = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_reads');
+   $num_clusters = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_clusters');
+   $num_singlets = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_singlets');
+
+   $analysis->tripal_analysis_unigene->unigene_name = $unigene_name[0]->value;
+   $analysis->tripal_analysis_unigene->num_contigs = $num_contigs[0]->value;
+   $analysis->tripal_analysis_unigene->num_reads = $num_reads[0]->value;
+   $analysis->tripal_analysis_unigene->num_clusters = $num_clusters[0]->value;
+   $analysis->tripal_analysis_unigene->num_singlets = $num_singlets[0]->value;
+
+   // add in organism information using the materialized view
+   $sql = "SELECT * FROM {organism_unigene_mview} OUM ".
+          "  INNER JOIN {organism} O on OUM.organism_id = O.organism_id ".
+          "WHERE OUM.analysis_id = %d ".
+          "ORDER BY O.genus, O.species";
+   $previous_db = tripal_db_set_active('chado');  // use chado database
+   $organisms = db_query($sql,$analysis_id);
+   tripal_db_set_active($previous_db);  // now use drupal database
+
+   while($organism = db_fetch_object($organisms)){
+      $sql = "SELECT nid FROM {chado_organism} WHERE organism_id = %d";
+      $c_org = db_fetch_object(db_query($sql,$organism->organism_id));
+      $organism->nid = $c_org->nid;
+      $analysis->tripal_analysis_unigene->organisms[] = $organism;
    }
+
+
+   return $additions;
 }
 /*******************************************************************************
  * tripal_analysis_unigene_nodeapi()
@@ -59,16 +261,11 @@ function tripal_analysis_unigene_nodeapi(&$node, $op, $teaser, $page) {
             array('chado_feature','chado_organism'));
 
          // Abort if this node is not one of the types we should show.
-         if (!in_array($node->type, $types_to_show, TRUE)) {
-            // Turn the menu off if it's on
-            $box_status = variable_get("tripal_analysis_unigene-box-assembly","menu_off");
-            if (strcmp($box_status,"menu_on")==0 && $node->type =='chado_organism'){
-               variable_set("tripal_analysis_unigene-box-assembly","menu_off");
+         if (in_array($node->type, $types_to_show, TRUE)) {
+            // Add unigene to the content item if it's not a teaser
+            if ($teaser) {
+               return '';
             }
-            break;
-         }
-         // Add unigene to the content item if it's not a teaser
-         if (!$teaser) {
          	
             // add the alignment to the feature search indexing
             if($node->build_mode == NODE_BUILD_SEARCH_INDEX){
@@ -84,14 +281,14 @@ function tripal_analysis_unigene_nodeapi(&$node, $op, $teaser, $page) {
             } else {
 
                if(strcmp($node->type,'chado_organism')==0){
-                  // Show unigene content if not at teaser view
-                  $node->content['tripal_analysis_unigene_node_add'] = array(
-					   	'#value' => theme('tripal_analysis_unigene_node_add', $node),
+                  $node->content['tripal_organism_unigenes'] = array(
+					   	'#value' => theme('tripal_organism_unigenes', $node),
 						   '#weight' => 4
                   );
                }
             }
-      }
+         }
+      break;   
    }
 }
 /************************************************************************
@@ -107,11 +304,25 @@ function tripal_analysis_unigene_theme () {
       'tripal_analysis_unigene_search_result' => array (
          'arguments' => array('node'),
       ),
-      'tripal_analysis_unigene_node_add' => array (
-         'arguments' => array('node'),
+      'tripal_organism_unigenes' => array (
+         'arguments' => array('node'=> null),
+         'template' => 'tripal_organism_unigenes',
+      ),
+      'tripal_analysis_unigene_base' => array (
+         'arguments' => array('node'=> null),
+         'template' => 'tripal_analysis_unigene_base',
       ),
    );
 }
+/*******************************************************************************
+ *  
+ */
+function tripal_analysis_unigene_preprocess_tripal_organism_unigenes(&$variables){
+   $node = $variables['node'];
+   $organism = $node->organism;
+   $unigenes = tripal_analysis_unigene_load_organism_unigenes($organism);
+   $node->organism->tripal_analysis_unigene->unigenes =  $unigenes;
+}
 /************************************************************************
  *  This function is an extension of the chado_feature_view by providing
  *  the markup for the feature object THAT WILL BE INDEXED.
@@ -431,192 +642,43 @@ function tripal_analysis_unigene_get_alignments($map) {
 }
 /************************************************************************
 *
-*/
-function tripal_analysis_unigene_organism_assembly($node){
-   $node = node_load($node);
-   return tripal_analysis_unigene_organism_add($node);
-}
-/************************************************************************
-*
-*/
-function theme_tripal_analysis_unigene_node_add ($node){
-
-   if(strcmp($node->type,'chado_organism')==0){
-      $box_status = variable_get("tripal_analysis_unigene-box-assembly","menu_off");
-      if (strcmp($box_status,"menu_off")==0){
-         $content = tripal_analysis_unigene_organism_add($node);
-      }
-   }
-   return $content;
-}
-/************************************************************************
-*
 */   
-function tripal_analysis_unigene_organism_add($node){
-   // get the organism_id for this node:
-   $sql = 'SELECT * FROM {chado_organism} WHERE vid = %d';
-   $org_id = db_fetch_object(db_query($sql, $node->nid));
-   
-   // get information about this organism 
-   $sql = "SELECT * FROM {organism} ".
-          "WHERE organism_id = %d";
-   $previous_db = tripal_db_set_active('chado');  // use chado database
-   $organism = db_fetch_object(db_query($sql,$org_id->organism_id));
-   tripal_db_set_active($previous_db);  // now use drupal database
-
-   // get information about this assembly and add it to the items in this node
-   $sql = "SELECT * FROM {unigene_mview} ".
-          "WHERE organism_id = %d ".
-          "ORDER BY analysis_id DESC";
+function tripal_analysis_unigene_load_organism_unigenes($organism){
 
+   // get information about this assemblies and add it to the items in this node
+   $sql = "SELECT * FROM {organism_unigene_mview} OUM ".
+          "  INNER JOIN {analysis} A  ON A.analysis_id = OUM.analysis_id ".
+          "WHERE OUM.organism_id = %d ".
+          "ORDER BY A.timeexecuted DESC";
    $previous_db = tripal_db_set_active('chado');  // use chado database
-   $results = db_query($sql,$org_id->organism_id);
+   $results = db_query($sql,$organism->organism_id);
    tripal_db_set_active($previous_db);  // now use drupal database
 
-   //$i = 0;
-   //while ($assembly = db_fetch_object($results)){
-      // get information about this organism and add it to the items in this node
-      //$libraries = array();
-      //$libraries_sql = "SELECT library_id, library_name ".
-                       //"FROM {unigene_libraries_mview} ".
-                       //"WHERE analysis_id = %d ";
-      //$previous_db = tripal_db_set_active('chado');  // use chado database
-      //$libraries_result = db_query($libraries_sql,$assembly->analysis_id);
-      //tripal_db_set_active($previous_db);  // now use drupal database
-      //$library_sql = "SELECT * FROM {chado_library} WHERE library_id = %d";
-      //$k = 0;
-      //while ($library = db_fetch_object($libraries_result)){
-          //$library_node = db_fetch_object(db_query($library_sql,$library->library_id));
-          //$library->node_id = $library_node->nid;
-          //$libraries[$k++] = $library;
-      //}      
-      //$assembly->libraries = $libraries;
-      //$assemblies[$i++] = $assembly;
-   //} 
-
-   // if this content is intended to be a menu item the 
-   // we need to know so we can format the content slightly different
-   $box_status =variable_get("tripal_analysis_unigene-box-assembly","menu_off");
-
-   if(count($assemblies) > 0){
-      $content = "<div id=\"organism_tab_content\">".
-       "<p>New assemblies are built after a significant number of sequences are added to the project or new software is available. ".
-       "Click on name for more information.</p><br>";
-
-      foreach($assemblies as $assembly){
-            $content .= "<div class=\"tripal_unigene-info-box\">".
-             "<div class=\"tripal_expandableBox\"><h3><a name=\"$assembly->name\">$assembly->name</a></h3></div>".
-             "<div class=\"tripal_expandableBoxContent\">";
-            $content .= "<table>".
-             "<tr><td class=\"dbfieldname\"> Version                        </td>".
-             "    <td class=\"dbfieldvalue\">$assembly->uversion            </td></tr>".
-             "<tr><td class=\"dbfieldname\"> Analysis ID                    </td>".
-             "    <td class=\"dbfieldvalue\">$assembly->analysis_id         </td></tr>".
-             "<tr><td class=\"dbfieldname\"> Date                           </td>".
-             "    <td class=\"dbfieldvalue\">$assembly->adate               </td></tr>".
-             "<tr><td class=\"dbfieldname\"> Software                       </td>".
-             "    <td class=\"dbfieldvalue\">$assembly->program             </td></tr>".
-             "<tr><td class=\"dbfieldname\"> Software Version               </td>".
-             "    <td class=\"dbfieldvalue\">$assembly->programversion      </td></tr>".
-             "<tr><td class=\"dbfieldname\"> Number of Contigs              </td>".
-             "    <td class=\"dbfieldvalue\">$assembly->num_contigs         </td></tr>".
-             "<tr><td class=\"dbfieldname\"> Description                    </td>".
-             "    <td class=\"dbfieldvalue\">$assembly->description         </td></tr>".
-             "<tr><td class=\"dbfieldname\"> Libraries Included in Assembly </td>".
-             "    <td class=\"dbfieldvalue\"> ";
-//# TODO: THIS SHOULD NOT HAVE A LINK IF THERE IS NO LIBRARY NODE IN DRUPAL
-             //foreach($assembly->libraries as $library){
-               //$content .= "<a href=\"/node/$library->node_id\">$library->library_name</a> ";
-             //}
-             $content .= " </td></tr>".
-             "</table>";
-
-             # Generate the download linkes
-             $a_dir = tripal_get_moddir('tripal_analysis_unigene') . 
-                "/$assembly->analysis_id";
- 
-             if(is_dir($a_dir)){
-                $content .= "<ul class=\"organism\">";
-
-                if($target_file = file_scan_directory($a_dir,'\.contigs.fasta$',
-                      array('.','..','CVS'),0,FALSE)){
-                   foreach($target_file as $key=>$value){
-                      $target = $target_file[$key];
-                   }
-                   $link = url($target->filename);
-                   $content .= " 
-                      <li>
-                        <a href=\"$link\">Download contigs </a>
-                      </li>
-                   ";
-                }
-                if($target_file = file_scan_directory($a_dir,'\.contigs.qual$',
-                      array('.','..','CVS'),0,FALSE)){
-                   foreach($target_file as $key=>$value){
-                      $target = $target_file[$key];
-                   }
-                   $link = url($target->filename);
-                   $content .= " 
-                      <li>
-                        <a href=\"$link\">Download contigs quality </a>
-                      </li>
-                   ";
-                }
-                if($target_file = file_scan_directory($a_dir,'\.singlets.fasta$',
-                      array('.','..','CVS'),0,FALSE)){
-                   foreach($target_file as $key=>$value){
-                      $target = $target_file[$key];
-                   }
-                   $link = url($target->filename);
-                   $content .= " 
-                      <li>
-                        <a href=\"$link\">Download singlets </a>
-                      </li>
-                   ";
-
-                }
-                if($target_file = file_scan_directory($a_dir,'\.singlets.qual$',
-                      array('.','..','CVS'),0,FALSE)){
-                   foreach($target_file as $key=>$value){
-                      $target = $target_file[$key];
-                   }
-                   $link = url($target->filename);
-                   $content .= " 
-                      <li>
-                        <a href=\"$link\">Download singlets quality </a>
-                      </li>
-                   ";
-
-                }
-                if($target_file = file_scan_directory($a_dir,'\.ace$',
-                      array('.','..','CVS'),0,FALSE)){
-                   foreach($target_file as $key=>$value){
-                      $target = $target_file[$key];
-                   }
-                   $link = url($target->filename);
-                   $content .= " 
-                      <li>
-                        <a href=\"$link\">Download ace file </a>
-                      </li>
-                   ";
-;
-                }
-             $content .= "</ul>";
-             }
-             if(user_access('access administrative pages')){
-                $link = url("tripal_toggle_box_menu/tripal_analysis_unigene/assembly/$node->nid");
-                if(strcmp($box_status,"menu_off")==0){
-                   $content .= "<a href=\"$link\">Show on menu</a>";
-                } else {
-                   $content .= "<a href=\"$link\">Remove from menu</a>";
-                }
-             }
-       	    $content .= "</div></div>";
+   $unigenes = array();
+   $i=0;
+   $sql = "SELECT nid FROM {chado_analysis} WHERE analysis_id = %d";
+   while($unigene = db_fetch_object($results)){
+      $analysis_id = $unigene->analysis_id;
+      $c_node = db_fetch_object(db_query($sql,$analysis_id));
+      if($c_node){  
+         $unigene->nid = $c_node->nid;
       }
-   
-      $content .= "</div>";
+      // add in the properties
+      $unigene_name = tripal_analysis_get_property($analysis_id,'analysis_unigene_name');
+      $num_contigs  = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_contigs');
+      $num_reads    = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_reads');
+      $num_clusters = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_clusters');
+      $num_singlets = tripal_analysis_get_property($analysis_id,'analysis_unigene_num_singlets');
+      
+      $unigene->unigene_name = $unigene_name[0]->value;
+      $unigene->num_reads = $num_reads[0]->value;
+      $unigene->num_clusters = $num_clusters[0]->value;
+      $unigene->num_contigs = $num_contigs[0]->value;     
+      $unigene->num_singlets = $num_singlets[0]->value;
+
+      $unigenes[$i++] = $unigene;
    }
-   return $content;
+   return $unigenes;
 }
 /*******************************************************************************
  * Tripal Unigene administrative setting form. This function is called by
@@ -648,43 +710,4 @@ function tripal_analysis_unigene_get_settings() {
    return $settings;
 }
 
-/*******************************************************************************
- * Set the permission types that the chado module uses.  Essentially we
- * want permissionis that protect creation, editing and deleting of chado
- * data objects
- */
-function tripal_analysis_unigene_perm(){
-   return array(
-      'access chado_analysis_unigene content',
-      'create chado_analysis_unigene content',
-      'delete chado_analysis_unigene content',
-      'edit chado_analysis_unigene content',
-   );
-}
-
-/*******************************************************************************
- *  The following function proves access control for users trying to
- *  perform actions on data managed by this module
- */
-function chado_analysis_unigene_access($op, $node, $account){
-   if ($op == 'create') {
-      return user_access('create chado_analysis_unigene content', $account);
-   }
 
-   if ($op == 'update') {
-      if (user_access('edit chado_analysis_unigene content', $account)) {
-         return TRUE;
-      }
-   }
-   if ($op == 'delete') {
-      if (user_access('delete chado_analysis_unigene content', $account)) {
-         return TRUE;
-      }
-   }
-   if ($op == 'view') {
-      if (user_access('access chado_analysis_unigene content', $account)) {
-         return TRUE;
-      }
-   }
-   return FALSE;
-}

+ 2 - 2
tripal_core/jobs.php

@@ -138,12 +138,12 @@ function tripal_jobs_report () {
 *
 * @ingroup tripal_core
 */
-function tripal_jobs_launch (){
+function tripal_jobs_launch ($do_parallel = 0){
    
    // first check if any jobs are currently running
    // if they are, don't continue, we don't want to have
    // more than one job script running at a time
-   if(tripal_jobs_check_running()){
+   if(!$do_parallel and tripal_jobs_check_running()){
       return;
    }
    

+ 12 - 1
tripal_core/tripal_core.api.inc

@@ -399,6 +399,17 @@ function tripal_core_chado_update($table,$match,$values){
 */
 function tripal_core_chado_select($table,$columns,$values,$has_record = 0){
 
+
+   if (!is_array($columns)){
+      watchdog('tripal_feature', 'the $columns argument for tripal_core_chado_select must be an array.');
+      return false;
+   }
+
+   if (!is_array($values)){
+      watchdog('tripal_feature', 'the $values argument for tripal_core_chado_select must be an array.');
+      return false;
+   }
+
    // get the table description
    $table_desc = module_invoke_all('chado_'.$table.'_schema');
 
@@ -455,7 +466,7 @@ function tripal_core_chado_select($table,$columns,$values,$has_record = 0){
      }
      $sql = substr($sql,0,-4);  // get rid of the trailing 'AND'
    }
-   
+
    $resource = db_query($sql,$args);
    $results = array();
    while ($r = db_fetch_object($resource)) {

+ 1 - 1
tripal_core/tripal_core.schema.api.inc

@@ -12668,4 +12668,4 @@ function tripal_core_chado_environment_schema () {
   );
   
   return $description;
-}
+}

+ 2 - 1
tripal_core/tripal_launch_jobs.php

@@ -33,6 +33,7 @@ in order to pick up all necessary dependencies
 
   // check to make sure the username is valid
   $username = $argv[1];
+  $do_parallel = $argv[2];
   if(!db_fetch_object(db_query("SELECT * FROM {users} WHERE name = '$username'"))){
      fwrite($stdout, "'$username' is not a valid Drupal username. exiting...\n");
      exit;
@@ -40,7 +41,7 @@ in order to pick up all necessary dependencies
   global $user;
   $user = user_load(array('name' => $username));
 
-  tripal_jobs_launch();
+  tripal_jobs_launch($do_parallel);
 
 /**
  *

+ 2 - 2
tripal_cv/tripal_cv.api.inc

@@ -306,7 +306,7 @@ function tripal_cv_get_cvterm_options($cv_id = 0) {
  *
  * @ingroup tripal_schema_api 
  */
-function tripal_stock_chado_cvterm_schema() {
+function tripal_cv_chado_cvterm_schema() {
   $description = array();
 
   $description['foreign keys']['cv'] = array(
@@ -324,4 +324,4 @@ function tripal_stock_chado_cvterm_schema() {
   ); 
 
   return $description;
-}
+}

+ 6 - 4
tripal_feature/gff_loader.php

@@ -179,7 +179,7 @@ function tripal_core_gff3_load_form_submit ($form, &$form_state){
    $update   = $form_state['values']['update'];
    $refresh  = $form_state['values']['refresh'];
    $remove   = $form_state['values']['remove'];
-   $analysis = $form_state['values']['analysis_id'];
+   $analysis_id = $form_state['values']['analysis_id'];
 
    $args = array($gff_file,$organism_id,$analysis_id,$add_only,$update,$refresh,$remove);
    $type = '';
@@ -363,7 +363,7 @@ function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0
       // if neither name nor uniquename are provided then generate one
       if(!$attr_uniquename and !$attr_name){
          if(array_key_exists('Parent',$tags)){
-            $attr_uniquename = $tags['Parent'][0]."-$type-$landmark:$fmin..$max";
+            $attr_uniquename = $tags['Parent'][0]."-$type-$landmark:$fmin..$fmax";
          } else { 
            print "ERROR: cannot generate a uniquename for feature on line $i\n";
            exit;
@@ -425,6 +425,7 @@ function tripal_core_load_gff3($gff_file, $organism_id,$analysis_id,$add_only =0
     
 
          // add/update the feature
+         print "$i ";
          $feature = tripal_core_load_gff3_feature($organism,$analysis_id,$cvterm,
             $attr_uniquename,$attr_name,$residues,$attr_is_analysis,
             $attr_is_obsolete, $add_only);
@@ -745,10 +746,11 @@ function tripal_core_load_gff3_feature($organism,$analysis_id,$cvterm,$uniquenam
 
    // add the analysisfeature entry to the analysisfeature table if it doesn't already exist
    $af_values = array('analysis_id' => $analysis_id, 'feature_id' => $feature->feature_id);
-   if(tripal_core_chado_select('analysisfeature','analysisfeature_id',$af,true)){
+   if(tripal_core_chado_select('analysisfeature',array('analysisfeature_id'),$af_values,true)){
       if(!tripal_core_chado_insert('analysisfeature',$af_values)){
          print "ERROR: could not add analysisfeature record: $analysis_id, $feature->feature_id\n";
-         return 0;
+      } else {
+         print "   Added analysisfeature record\n";
       }
    }