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; } /******************************************************************************* * 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') { if(!user_access('create chado_analysis_unigene content', $account)){ return FALSE; } } if ($op == 'update') { if (!user_access('edit chado_analysis_unigene content', $account)) { return FALSE; } } if ($op == 'delete') { if (!user_access('delete chado_analysis_unigene content', $account)) { return FALSE; } } if ($op == 'view') { if(!user_access('access chado_analysis_unigene content', $account)){ return FALSE; } } return NULL; } /** * */ function chado_analysis_unigene_form ($node){ $unigene = $node->analysis->tripal_analysis_unigene; // set the form defaults $unigene_name = $node->unigene_name; if(!$unigene_name){ $unigene_name = $unigene->unigene_name; } $num_reads = $node->num_reads; if(!$num_reads){ $num_reads = $unigene->num_reads; } $avg_length = $node->avg_length; if(!$avg_length){ $avg_length = $unigene->avg_length; } $num_clusters = $node->num_clusters; if(!$num_clusters){ $num_clusters = $unigene->num_clusters; } $num_contigs = $node->num_contigs; if(!$num_contigs){ $num_contigs = $unigene->num_contigs; } $num_singlets = $node->num_singlets; if(!$num_singlets){ $num_singlets = $unigene->num_singlets; } $contig_min_len= $node->contig_min_len; if(!$contig_min_len){ $contig_min_len = $unigene->contig_min_len; } $contig_max_len= $node->contig_max_len; if(!$contig_max_len){ $contig_max_len = $unigene->contig_max_len; } $contig_avg_len= $node->contig_avg_len; if(!$contig_avg_len){ $contig_avg_len = $unigene->contig_avg_len; } $singlet_min_len= $node->singlet_min_len; if(!$singlet_min_len){ $singlet_min_len = $unigene->singlet_min_len; } $singlet_max_len= $node->singlet_max_len; if(!$singlet_max_len){ $singlet_max_len = $unigene->singlet_max_len; } $singlet_avg_len= $node->singlet_avg_len; if(!$singlet_avg_len){ $singlet_avg_len = $unigene->singlet_avg_len; } // add in the default fields for an analysis $form = chado_analysis_form($node); $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['unigene_stats'] = array( '#title' => t('Unigene Stats'), '#type' => 'fieldset', '#description' => t('Unigene, contig and singlet statistics'), '#collapsible' => TRUE, ); $form['unigene_stats']['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['unigene_stats']['avg_length'] = array( '#title' => t('Average Contig Length'), '#type' => 'textfield', '#required' => FALSE, '#description' => t('Provide the average sequence length in the ungiene (average of contigs and signlets).'), '#default_value' => $avg_length, ); $form['unigene_stats']['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['unigene_stats']['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['unigene_stats']['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, ); $form['contig_stats'] = array( '#title' => t('Contig Stats'), '#type' => 'fieldset', '#description' => t('Unigene Contig statistics'), '#collapsible' => TRUE, ); $form['contig_stats']['contig_min_len'] = array( '#title' => t('Minimum Contig Length'), '#type' => 'textfield', '#required' => FALSE, '#description' => t('Provide the length of the smallest contig'), '#default_value' => $contig_min_len, ); $form['contig_stats']['contig_max_len'] = array( '#title' => t('Maximum Contig Length'), '#type' => 'textfield', '#required' => FALSE, '#description' => t('Provide the length of the largest contig'), '#default_value' => $contig_max_len, ); $form['contig_stats']['contig_avg_len'] = array( '#title' => t('Average Contig Length'), '#type' => 'textfield', '#required' => FALSE, '#description' => t('Provide the average contig length'), '#default_value' => $contig_avg_len, ); $form['singlet_stats'] = array( '#title' => t('Singlet Stats'), '#type' => 'fieldset', '#description' => t('Unigene Singlet statistics'), '#collapsible' => TRUE, ); $form['singlet_stats']['singlet_min_len'] = array( '#title' => t('Minimum Singlet Length'), '#type' => 'textfield', '#required' => FALSE, '#description' => t('Provide the length of the smallest singlet'), '#default_value' => $singlet_min_len, ); $form['singlet_stats']['singlet_max_len'] = array( '#title' => t('Maximum Singlet Length'), '#type' => 'textfield', '#required' => FALSE, '#description' => t('Provide the length of the largest singlet'), '#default_value' => $singlet_max_len, ); $form['singlet_stats']['singlet_avg_len'] = array( '#title' => t('Average Singlet Length'), '#type' => 'textfield', '#required' => FALSE, '#description' => t('Provide the average singlet length'), '#default_value' => $singlet_avg_len, ); return $form; } /** * */ function chado_analysis_unigene_validate($node, &$form){ // use the analysis parent to validate the node tripal_analysis_validate($node, $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_id,'analysis_type','tripal_analysis_unigene'); tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_name',$node->unigene_name); tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_num_contigs',$node->num_contigs); tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_num_reads',$node->num_reads); tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_avg_length',$node->avg_length); tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_num_clusters',$node->num_clusters); tripal_analysis_insert_property($node->analysis_id,'analysis_unigene_num_singlets',$node->num_clusters); } /** * */ function chado_analysis_unigene_update($node){ chado_analysis_update($node); tripal_analysis_update_property($node->analysis_id,'analysis_unigene_name',$node->unigene_name,1); tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_contigs',$node->num_contigs,1); tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_reads',$node->num_reads,1); tripal_analysis_update_property($node->analysis_id,'analysis_unigene_avg_length',$node->avg_length,1); tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_clusters',$node->num_clusters,1); tripal_analysis_update_property($node->analysis_id,'analysis_unigene_num_singlets',$node->num_singlets,1); } /** * */ function chado_analysis_unigene_delete($node){ 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'); $avg_length = tripal_analysis_get_property($analysis_id,'analysis_unigene_avg_length'); $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->value; $analysis->tripal_analysis_unigene->num_contigs = $num_contigs->value; $analysis->tripal_analysis_unigene->num_reads = $num_reads->value; $analysis->tripal_analysis_unigene->avg_length = $avg_length->value; $analysis->tripal_analysis_unigene->num_clusters = $num_clusters->value; $analysis->tripal_analysis_unigene->num_singlets = $num_singlets->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; } /** * * * @ingroup tripal_analysis_unigene */ function tripal_analysis_unigene_block($op = 'list', $delta = 0, $edit=array()){ switch($op) { case 'list': $blocks['base_ugene']['info'] = t('Analysis: Unigene Details'); $blocks['base_ugene']['cache'] = BLOCK_NO_CACHE; $blocks['feature_ugene']['info'] = t('Tripal Feature Unigene'); $blocks['feature_ugene']['cache'] = BLOCK_NO_CACHE; $blocks['org_ugene']['info'] = t('Tripal Organism Unigene'); $blocks['org_ugene']['cache'] = BLOCK_NO_CACHE; return $blocks; case 'view': if(user_access('access chado_analysis_unigene content') and arg(0) == 'node' and is_numeric(arg(1))) { $nid = arg(1); $node = node_load($nid); $block = array(); switch($delta){ case 'base_ugene': $block['subject'] = t('Unigene Details'); $block['content'] = theme('tripal_analysis_unigene_base',$node); break; case 'feature_ugene': $block['subject'] = t('Unigene'); $block['content'] = theme('tripal_feature_unigenes',$node); break; case 'org_ugene': $block['subject'] = t('Unigene'); $block['content'] = theme('tripal_organism_unigenes',$node); break; default : } return $block; } } } /******************************************************************************* * tripal_analysis_unigene_nodeapi() * HOOK: Implementation of hook_nodeapi() * Display unigene results for allowed node types */ function tripal_analysis_unigene_nodeapi(&$node, $op, $teaser, $page) { switch ($op) { case 'view': // Find out which node types for showing the unigene $types_to_show = variable_get('tripal_analysis_unigene_setting', 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)) { // Add unigene to the content item if it's not a teaser if ($teaser) { return ''; } // add the alignment to the feature search indexing if($node->build_mode == NODE_BUILD_SEARCH_INDEX){ $node->content['tripal_analysis_unigene_index_version'] = array( '#value' => theme('tripal_analysis_unigene_search_index',$node), '#weight' => 4, ); } else if ($node->build_mode == NODE_BUILD_SEARCH_RESULT) { $node->content['tripal_analysis_unigene_index_version'] = array( '#value' => theme('tripal_analysis_unigene_search_result',$node), '#weight' => 4, ); } else { if(strcmp($node->type,'chado_organism')==0){ $node->content['tripal_organism_unigenes'] = array( '#value' => theme('tripal_organism_unigenes', $node), '#weight' => 4 ); } if(strcmp($node->type,'chado_feature')==0){ $node->content['tripal_feature_unigenes'] = array( '#value' => theme('tripal_feature_unigenes', $node), '#weight' => 4 ); } } } break; } } /** * Implements hook_theme_registry_alter(). */ function tripal_analysis_unigene_theme_registry_alter(&$info) { // Inject our module into the node theme registry as being an available theme // path so that we can override the node template for our content type. array_splice($info['node']['theme paths'], 1, 0, array(drupal_get_path('module', 'tripal_analysis_unigene'))); } /************************************************************************ * We need to let drupal know about our theme functions and their arguments. * We create theme functions to allow users of the module to customize the * look and feel of the output generated in this module */ function tripal_analysis_unigene_theme () { $path = drupal_get_path('module', 'tripal_analysis_unigene') . '/theme'; return array( 'tripal_analysis_unigene_search_index' => array ( 'arguments' => array('node'), ), 'tripal_analysis_unigene_search_result' => array ( 'arguments' => array('node'), ), 'tripal_organism_unigenes' => array ( 'arguments' => array('node'=> null), 'template' => 'tripal_organism_unigenes', 'path' => $path . '/tripal_organism', ), 'tripal_analysis_unigene_base' => array ( 'arguments' => array('node'=> null), 'template' => 'tripal_analysis_unigene_base', 'path' => $path . '/tripal_analysis_unigene', ), ); } /******************************************************************************* * */ 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; } /******************************************************************************* * */ function tripal_analysis_unigene_preprocess_tripal_feature_unigenes(&$variables){ $node = $variables['node']; $feature = $node->feature; $unigenes = tripal_analysis_unigene_load_feature_unigenes($feature); $node->feature->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. */ function theme_tripal_analysis_unigene_search_index ($node) { $feature = $node->feature; $obj_feature = tripal_analysis_unigene_get_alignments($feature); $alignments = $obj_feature->alignments; $content = ""; if(count($alignments) > 0){ // iterate through each alignment foreach ($alignments as $result){ // EST alignments in chado use an EST_match type to map ESTs to // contigs and a rank to indicate the major srcfeature. // We don't want to show EST_matches on the alignment view // since that doesn't make much sense to the end user. If this // is an EST_match and the feature is an EST then we want to show // the contig in the alignments. The contig name is part of the // uniquename in the EST_match if($node->feature->cvname == 'EST' && $result->cvname == 'EST_match'){ $sql = "SELECT srcfeature_id ". "FROM {featureloc} ". "WHERE feature_id = $result->feature_id ". "ORDER BY rank"; $previous_db = tripal_db_set_active ('chado'); $contig_fid = db_result(db_query($sql)); $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid"; $contig_name = db_result(db_query($sql)); tripal_db_set_active($previous_db); $sql = "SELECT nid ". "FROM {chado_feature} ". "WHERE feature_id = $contig_fid"; $contig_nid = db_result(db_query($sql)); // Check if the EST exists as a drupal node. If yes, add a link to // it. If no, just show the name if ($contig_nid != 0) { $sql = "SELECT nid FROM {node} WHERE nid=$contig_nid"; $node_exists = db_result(db_query($sql)); } $content .= "$contig_name " ; } elseif($node->feature->cvname == 'contig' && $result->cvname == 'EST_match'){ $sql = "SELECT vid ". "FROM {node} ". "WHERE title = '$result->feature_name'". "ORDER BY vid DESC"; // since the feature name is also the node title we can look it up $est_node = db_fetch_object(db_query($sql)); $content .= "$result->feature_name "; } else { $content .= "$result->cvname $result->feature_name "; } } } $content .= ""; return $content; } /************************************************************************ * This function is an extension of the chado_feature_view by providing * the markup for the feature object to show on a search result page. */ function theme_tripal_analysis_unigene_search_result ($node) { $feature = $node->feature; $obj_feature = tripal_analysis_unigene_get_alignments($feature); $alignments = $obj_feature->alignments; $content = ""; if(count($alignments) > 0){ // iterate through each alignment foreach ($alignments as $result){ // EST alignments in chado use an EST_match type to map ESTs to // contigs and a rank to indicate the major srcfeature. // We don't want to show EST_matches on the alignment view // since that doesn't make much sense to the end user. If this // is an EST_match and the feature is an EST then we want to show // the contig in the alignments. The contig name is part of the // uniquename in the EST_match if($node->feature->cvname == 'EST' && $result->cvname == 'EST_match'){ $sql = "SELECT srcfeature_id ". "FROM {featureloc} ". "WHERE feature_id = $result->feature_id ". "ORDER BY rank"; $previous_db = tripal_db_set_active ('chado'); $contig_fid = db_result(db_query($sql)); $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid"; $contig_name = db_result(db_query($sql)); tripal_db_set_active($previous_db); $sql = "SELECT nid ". "FROM {chado_feature} ". "WHERE feature_id = $contig_fid"; $contig_nid = db_result(db_query($sql)); // Check if the EST exists as a drupal node. If yes, add a link to // it. If no, just show the name if ($contig_nid != 0) { $sql = "SELECT nid FROM {node} WHERE nid=$contig_nid"; $node_exists = db_result(db_query($sql)); } $content .= "Alignment to contig $contig_name. " ; } elseif($node->feature->cvname == 'contig' && $result->cvname == 'EST_match'){ $sql = "SELECT vid ". "FROM {node} ". "WHERE title = '$result->feature_name'". "ORDER BY vid DESC"; // since the feature name is also the node title we can look it up $est_node = db_fetch_object(db_query($sql)); $content .= "Aligned EST: $result->feature_name "; } else { $content .= "Aligned $result->cvname: $result->feature_name "; } } } $content .= ""; return $content; } /******************************************************************************* * tripal_analysis_unigene_results () * Prepare unigene result for the feature shown on the page */ function theme_tripal_analysis_unigene_feature_alignments($node) { $feature = $node->feature; $obj_feature = tripal_analysis_unigene_get_alignments($feature); $alignments = $obj_feature->alignments; if(count($alignments) > 0){ $content = "
"; // we're showing contig alignments in GBrowse so create a link here for // that if this feature is a contig if($node->feature->cvname == 'contig'){ $content .= "
". "

ESTs in this contig

". "
"; $content .= "
"; } else { $content .= "
". "

Alignments

". "
"; $content .= "
"; } $content .= "". "". " ". " ". " ". " ". " "; // iterate through each alignment foreach ($alignments as $result){ // EST alignments in chado use an EST_match type to map ESTs to // contigs and a rank to indicate the major srcfeature. // We don't want to show EST_matches on the alignment view // since that doesn't make much sense to the end user. If this // is an EST_match and the feature is an EST then we want to show // the contig in the alignments. The contig name is part of the // uniquename in the EST_match if($node->feature->cvname == 'EST' && $result->cvname == 'EST_match'){ $sql = "SELECT srcfeature_id ". "FROM {featureloc} ". "WHERE feature_id = $result->feature_id ". "ORDER BY rank"; $previous_db = tripal_db_set_active ('chado'); $contig_fid = db_result(db_query($sql)); $sql = "SELECT name FROM {feature} WHERE feature_id = $contig_fid"; $contig_name = db_result(db_query($sql)); tripal_db_set_active($previous_db); $sql = "SELECT nid ". "FROM {chado_feature} ". "WHERE feature_id = $contig_fid"; $contig_nid = db_result(db_query($sql)); // Check if the EST exists as a drupal node. If yes, add a link to // it. If no, just show the name if ($contig_nid != 0) { $sql = "SELECT nid FROM {node} WHERE nid=$contig_nid"; $node_exists = db_result(db_query($sql)); } $content .= "". " ". " ". " ". ""; } elseif($node->feature->cvname == 'contig' && $result->cvname == 'EST_match'){ $sql = "SELECT vid ". "FROM {node} ". "WHERE title = '$result->feature_name'". "ORDER BY vid DESC"; // since the feature name is also the node title we can look it up $est_node = db_fetch_object(db_query($sql)); $content .= "". " ". " ". " ". ""; } else { $content .= "". "". " ". " ". " ". " ". " ". ""; } } $content .= "
TypeFeaturePosition
Contig"; if ($node_exists != 0) { $content .= "". "$contig_name"; } else { $content .= $contig_name; } $content .= " ". number_format($result->fmin). "-". number_format($result->fmax). "
EST"; //Check if the EST exists as a drupal node before adding a hyperlink if ($est_node->vid != 0) { $content .= "vid")."\">". $result->feature_name. ""; } else { $content .= $result->feature_name; } $content .= " ". number_format($result->fmin). "-". number_format($result->fmax). "
$result->cvname$result->feature_name$result->fmin$result->fmax$result->strand
"; /* if this is a contig then get the alignment if($node->feature->cvname == 'contig'){ // get the directory prefix $prefix = preg_replace("/^(\d*)\d{3}$/","$1",$node->feature_id); if(!$prefix){ $prefix = '0'; } $data_url = variable_get('chado_feature_data_url','sites/default/files/data'); $fh = fopen("$data_url/misc/$prefix/$node->feature->feature_id/alignment.txt", 'r'); if($fh){ $content .= "Alignment:
";
       while(!feof($fh)){
       $content .= fgets($fh);
       }
       $content .="
"; } fclose($fh); } */ $content .= "
"; } return $content; } /******************************************************************************* * */ function tripal_analysis_unigene_get_alignments($map) { // get the alignments for this feature $sql = "SELECT F.name as feature_name, FL.fmin, FL.fmax, FL.strand, ". " FL.phase, CVT.name as cvname, F.feature_id, F.uniquename, ". " FL.featureloc_id ". "FROM {featureloc} FL ". " INNER JOIN Feature F ON F.feature_id = FL.feature_id ". " INNER JOIN Cvterm CVT ON CVT.cvterm_id = F.type_id ". "WHERE srcfeature_id = %d AND ". " NOT(CVT.name = 'match' or CVT.name = 'match_part') ". "ORDER BY FL.fmin, FL.fmax"; $previous_db = tripal_db_set_active('chado'); $results = db_query($sql,$map->feature_id); $alignments = array(); $i=0; while($subfeature = db_fetch_object($results)){ $alignments[$i++] = $subfeature; } $additions->alignments = $alignments; /* get the GO Terms $sql = "SELECT DISTINCT * FROM {go_results_mview} ". "WHERE feature_id = %d"; $results = db_query($sql,$map->feature_id); $go_terms = array(); $i=0; while($term = db_fetch_object($results)){ $go_terms[$i++] = $term; } $additions->go_terms = $go_terms; // get the feature properties $sql = "SELECT FP.value,FP.rank,CVT.name,CVT.definition ". "FROM {featureprop} FP". " INNER JOIN Cvterm CVT ". " ON FP.type_id = CVT.cvterm_id ". "WHERE feature_id = %d"; $results = db_query($sql,$map->feature_id); $properties = array(); $i=0; while($property = db_fetch_object($results)){ $properties[$i++] = $property; } $additions->properties = $properties; */ tripal_db_set_active($previous_db); return $additions; } /************************************************************************ * */ 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,$organism->organism_id); tripal_db_set_active($previous_db); // now use drupal database $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; } // 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->value; $unigene->num_reads = $num_reads->value; $unigene->num_clusters = $num_clusters->value; $unigene->num_contigs = $num_contigs->value; $unigene->num_singlets = $num_singlets->value; $unigenes[$i++] = $unigene; } return $unigenes; } /************************************************************************ * */ function tripal_analysis_unigene_load_feature_unigenes($feature){ // first get all the unigene analyses for this organism $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,$feature->organism_id->organism_id); tripal_db_set_active($previous_db); // now use drupal database // iterate through the unigenes and find those that use this feature $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; // check if this feature is present in the unigene $values = array( 'feature_id' => $feature->feature_id, 'analysis_id' => $analysis_id, ); $hasFeature = tripal_core_chado_select('analysisfeature',array('*'),$values); // if the feature is present then get information about it if(sizeof($hasFeature) > 0){ // see if there is a drupal node for this unigene $c_node = db_fetch_object(db_query($sql,$analysis_id)); if($c_node){ $unigene->nid = $c_node->nid; } // add in the properties $unigene_name = tripal_analysis_get_property($analysis_id,'analysis_unigene_name'); $singlet = tripal_core_get_property('analysisfeature',$analysis_id,'singlet','tripal'); $unigene->unigene_name = $unigene_name->value; $unigene->singlet = $num_singlets->value; $unigenes[$i++] = $unigene; } } return $unigenes; } /******************************************************************************* * Tripal Unigene administrative setting form. This function is called by * tripal_analysis module which asks for an admin form to show on the page */ function tripal_analysis_unigene_get_settings() { // Get an array of node types with internal names as keys $options = node_get_types('names'); // Add 'chado_feature' to allowed content types for showing unigene results $allowedoptions ['chado_feature'] = "Show 'ESTs in this contig' on feature pages"; $allowedoptions ['chado_organism'] = "Show assemblies on organism pages"; $form['description'] = array( '#type' => 'item', '#value' => t("This option allows user to display the unigene assembly ". "information. For contigs, this would include an alignment and for ". "organisms this would be a list of assemblies. Check the box to ". "enable the display of unigene information. Uncheck to disable."), '#weight' => 0, ); $form['tripal_analysis_unigene_setting'] = array( '#type' => 'checkboxes', '#options' => $allowedoptions, '#default_value'=>variable_get('tripal_analysis_unigene_setting',array()), ); $settings->form = $form; $settings->title = "Tripal Unigene"; return $settings; }