|  | @@ -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;
 | 
	
		
			
				|  |  | -}
 |