Populating linking table

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Populating linking table

Hrishikesh A. Lokhande
Hello all,

I am working on implementing a gene module and using the example module and api’s from tripal.info for my reference. 

My module is partly functional, I am having issues with the chado_node_sync_form function. The following is what I have implemented. 



function triapl_gene_menu(){
   $items=array();
   .
   .
   .
   .
    $items['admin/tripal/chado/tripal_gene/sync'] = array(
    'title' => ' Sync',
    'description' => 'Create pages on this site for genes stored in Chado',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('chado_node_sync_form', 'tripal_gene', 'chado_gene'),
    'access arguments' => array('administer tripal gene'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 2
  );
  .
  .
  .
  .
  return $items;


}


function tripal_gene_node_info() {
  return array(
    'chado_gene' => array(
      'name'        => t('Gene'),
      'base'        => 'chado_gene',
      'description' => t('A gene from the Chado database'),
      'has_title'   => TRUE,
      'locked'      => TRUE,
      'chado_node_api' => array(
        'base_table' => 'gene',
        'hook_prefix' => 'chado_gene',
        'record_type_title' => array(
          'singular' => t('Gene'),
          'plural' => t('Genes')
        ),
        'sync_filters' => array(
          'type_id' => FALSE,
          'organism_id' => FALSE
        ),
      ),
    ),
  );
}

The sync works from the UI but doesn’t populate the chado_gene table, I can see entries in the node table for chado_gene. 

Is there any other function that I need to implement (like hook_insert) to populate chado_gene?

Thanks 


Hrishikesh A. Lokhande
Bioinformatics Analyst
National Center for Genome Resources 


------------------------------------------------------------------------------

_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal
Reply | Threaded
Open this post in threaded view
|

Re: Populating linking table

Stephen Ficklin-2
Hi Hrishikesh,

It looks like we are missing some information in the tripal_example.chado_node.inc file that gives this information.   If you take a look in the same file in the feature module you'll see the function chado_feature_insert() and at the bottom of that function is where the entry is added to the linking table.  Here's the snippet of code from that function:

  // Make sure the entry for this feature doesn't already exist in the
  // chado_feature table if it doesn't exist then we want to add it.
  $check_org_id = chado_get_id_from_nid('feature', $node->nid);
  if (!$check_org_id) {
    $record = new stdClass();
    $record->nid = $node->nid;
    $record->vid = $node->vid;
    $record->feature_id = $feature_id;
    drupal_write_record('chado_feature', $record);
  }


However, it sounds as though you may be duplicating effort.  The feature module should already provide gene pages for you and if you want to customize the way those gene pages look you just need to edit the existing template files.  Have you tried that route and can't get it to do what you are needing?

Stephen

On 11/3/2014 12:27 PM, Hrishikesh A. Lokhande wrote:
Hello all,

I am working on implementing a gene module and using the example module and api’s from tripal.info for my reference. 

My module is partly functional, I am having issues with the chado_node_sync_form function. The following is what I have implemented. 



function triapl_gene_menu(){
   $items=array();
   .
   .
   .
   .
    $items['admin/tripal/chado/tripal_gene/sync'] = array(
    'title' => ' Sync',
    'description' => 'Create pages on this site for genes stored in Chado',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('chado_node_sync_form', 'tripal_gene', 'chado_gene'),
    'access arguments' => array('administer tripal gene'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 2
  );
  .
  .
  .
  .
  return $items;


}


function tripal_gene_node_info() {
  return array(
    'chado_gene' => array(
      'name'        => t('Gene'),
      'base'        => 'chado_gene',
      'description' => t('A gene from the Chado database'),
      'has_title'   => TRUE,
      'locked'      => TRUE,
      'chado_node_api' => array(
        'base_table' => 'gene',
        'hook_prefix' => 'chado_gene',
        'record_type_title' => array(
          'singular' => t('Gene'),
          'plural' => t('Genes')
        ),
        'sync_filters' => array(
          'type_id' => FALSE,
          'organism_id' => FALSE
        ),
      ),
    ),
  );
}

The sync works from the UI but doesn’t populate the chado_gene table, I can see entries in the node table for chado_gene. 

Is there any other function that I need to implement (like hook_insert) to populate chado_gene?

Thanks 


Hrishikesh A. Lokhande
Bioinformatics Analyst
National Center for Genome Resources 



------------------------------------------------------------------------------


_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal


------------------------------------------------------------------------------

_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal
Reply | Threaded
Open this post in threaded view
|

Re: Populating linking table

adf_ncgr
Hi Stephen-
thanks for your help with Hrishikesh's questions. Regarding the question of whether this may be duplicating effort, it's
certainly possible; but just to give some further context, we're basically looking for a way to expose
information such as gene family membership that will likely be fairly specific to the gene subclass of features. Our initial
goals are fairly modest and can probably be accomplished in several ways. We would certainly be interested if you could
point us to other examples of how people are using tripal to present gene-specific information in more customized ways.

thanks again

Andrew Farmer


On 11/3/14 11:43 AM, Stephen Ficklin wrote:
Hi Hrishikesh,

It looks like we are missing some information in the tripal_example.chado_node.inc file that gives this information.   If you take a look in the same file in the feature module you'll see the function chado_feature_insert() and at the bottom of that function is where the entry is added to the linking table.  Here's the snippet of code from that function:

  // Make sure the entry for this feature doesn't already exist in the
  // chado_feature table if it doesn't exist then we want to add it.
  $check_org_id = chado_get_id_from_nid('feature', $node->nid);
  if (!$check_org_id) {
    $record = new stdClass();
    $record->nid = $node->nid;
    $record->vid = $node->vid;
    $record->feature_id = $feature_id;
    drupal_write_record('chado_feature', $record);
  }


However, it sounds as though you may be duplicating effort.  The feature module should already provide gene pages for you and if you want to customize the way those gene pages look you just need to edit the existing template files.  Have you tried that route and can't get it to do what you are needing?

Stephen

On 11/3/2014 12:27 PM, Hrishikesh A. Lokhande wrote:
Hello all,

I am working on implementing a gene module and using the example module and api’s from tripal.info for my reference. 

My module is partly functional, I am having issues with the chado_node_sync_form function. The following is what I have implemented. 



function triapl_gene_menu(){
   $items=array();
   .
   .
   .
   .
    $items['admin/tripal/chado/tripal_gene/sync'] = array(
    'title' => ' Sync',
    'description' => 'Create pages on this site for genes stored in Chado',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('chado_node_sync_form', 'tripal_gene', 'chado_gene'),
    'access arguments' => array('administer tripal gene'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 2
  );
  .
  .
  .
  .
  return $items;


}


function tripal_gene_node_info() {
  return array(
    'chado_gene' => array(
      'name'        => t('Gene'),
      'base'        => 'chado_gene',
      'description' => t('A gene from the Chado database'),
      'has_title'   => TRUE,
      'locked'      => TRUE,
      'chado_node_api' => array(
        'base_table' => 'gene',
        'hook_prefix' => 'chado_gene',
        'record_type_title' => array(
          'singular' => t('Gene'),
          'plural' => t('Genes')
        ),
        'sync_filters' => array(
          'type_id' => FALSE,
          'organism_id' => FALSE
        ),
      ),
    ),
  );
}

The sync works from the UI but doesn’t populate the chado_gene table, I can see entries in the node table for chado_gene. 

Is there any other function that I need to implement (like hook_insert) to populate chado_gene?

Thanks 


Hrishikesh A. Lokhande
Bioinformatics Analyst
National Center for Genome Resources 



------------------------------------------------------------------------------


_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal



------------------------------------------------------------------------------


_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal

-- 
...all concepts in which an entire process is semiotically concentrated
elude definition; only that which has no history is definable.

Friedrich Nietzsche

------------------------------------------------------------------------------

_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal
Reply | Threaded
Open this post in threaded view
|

Re: Populating linking table

Mara Kim
At Vanderbilt, we use a query that looks like this to find the gene associated with any given feature:

WITH RECURSIVE feature_gene(feature_id, gene_id) AS (
  SELECT F.feature_id, F.feature_id
  FROM feature F
    JOIN cvterm CVT ON(F.type_id = CVT.cvterm_id)
    JOIN cv CV USING(cv_id)
  WHERE CV.name = 'sequence'
   AND CVT.name = 'gene'
   AND F.is_obsolete = false
  UNION ALL
  SELECT F.feature_id, G.gene_id
  FROM feature F
   JOIN feature_relationship FR ON(F.feature_id = FR.subject_id)
   JOIN feature_gene G ON(G.feature_id = FR.object_id)
   JOIN cvterm CVT ON(FR.type_id = CVT.cvterm_id)
   JOIN cv CV USING(cv_id)
  WHERE CV.name = 'sequence'
   AND CVT.name = 'part_of'
   AND F.is_obsolete = false
)
SELECT G.feature_id, G.gene_id
FROM feature_gene G;

Basically, it starts with all the features of type 'gene', and recursively finds all its children.  This is nice because it makes it trivial to find the gene associated with a given feature, as well as all features associated with a given gene.  Would that be an amenable solution?

Now, unsurprisingly, the query in this form is abhorrently slow, and so requires additional filters (on organism, type, etc.) within the recursive part to be useful, making a traditional VIEW a bit useless.  However, I have been thinking about implementing this as a MATERIALIZED VIEW, which would be feasible to update rarely.  Unfortunately, we are running Postgres 9.2, which doesn't have built in support for mviews, requiring some manual hacking with functions to achieve such functionality.  If people were interested in this, I could work on a solution.


On Wed, Nov 5, 2014 at 12:46 AM, Andrew Farmer <[hidden email]> wrote:
Hi Stephen-
thanks for your help with Hrishikesh's questions. Regarding the question of whether this may be duplicating effort, it's
certainly possible; but just to give some further context, we're basically looking for a way to expose
information such as gene family membership that will likely be fairly specific to the gene subclass of features. Our initial
goals are fairly modest and can probably be accomplished in several ways. We would certainly be interested if you could
point us to other examples of how people are using tripal to present gene-specific information in more customized ways.

thanks again

Andrew Farmer



On 11/3/14 11:43 AM, Stephen Ficklin wrote:
Hi Hrishikesh,

It looks like we are missing some information in the tripal_example.chado_node.inc file that gives this information.   If you take a look in the same file in the feature module you'll see the function chado_feature_insert() and at the bottom of that function is where the entry is added to the linking table.  Here's the snippet of code from that function:

  // Make sure the entry for this feature doesn't already exist in the
  // chado_feature table if it doesn't exist then we want to add it.
  $check_org_id = chado_get_id_from_nid('feature', $node->nid);
  if (!$check_org_id) {
    $record = new stdClass();
    $record->nid = $node->nid;
    $record->vid = $node->vid;
    $record->feature_id = $feature_id;
    drupal_write_record('chado_feature', $record);
  }


However, it sounds as though you may be duplicating effort.  The feature module should already provide gene pages for you and if you want to customize the way those gene pages look you just need to edit the existing template files.  Have you tried that route and can't get it to do what you are needing?

Stephen

On 11/3/2014 12:27 PM, Hrishikesh A. Lokhande wrote:
Hello all,

I am working on implementing a gene module and using the example module and api’s from tripal.info for my reference. 

My module is partly functional, I am having issues with the chado_node_sync_form function. The following is what I have implemented. 



function triapl_gene_menu(){
   $items=array();
   .
   .
   .
   .
    $items['admin/tripal/chado/tripal_gene/sync'] = array(
    'title' => ' Sync',
    'description' => 'Create pages on this site for genes stored in Chado',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('chado_node_sync_form', 'tripal_gene', 'chado_gene'),
    'access arguments' => array('administer tripal gene'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 2
  );
  .
  .
  .
  .
  return $items;


}


function tripal_gene_node_info() {
  return array(
    'chado_gene' => array(
      'name'        => t('Gene'),
      'base'        => 'chado_gene',
      'description' => t('A gene from the Chado database'),
      'has_title'   => TRUE,
      'locked'      => TRUE,
      'chado_node_api' => array(
        'base_table' => 'gene',
        'hook_prefix' => 'chado_gene',
        'record_type_title' => array(
          'singular' => t('Gene'),
          'plural' => t('Genes')
        ),
        'sync_filters' => array(
          'type_id' => FALSE,
          'organism_id' => FALSE
        ),
      ),
    ),
  );
}

The sync works from the UI but doesn’t populate the chado_gene table, I can see entries in the node table for chado_gene. 

Is there any other function that I need to implement (like hook_insert) to populate chado_gene?

Thanks 


Hrishikesh A. Lokhande
Bioinformatics Analyst
National Center for Genome Resources 



------------------------------------------------------------------------------


_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal



------------------------------------------------------------------------------


_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal

-- 
...all concepts in which an entire process is semiotically concentrated
elude definition; only that which has no history is definable.

Friedrich Nietzsche

------------------------------------------------------------------------------

_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal




--
M

------------------------------------------------------------------------------

_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal
Reply | Threaded
Open this post in threaded view
|

Re: Populating linking table

Stephen Ficklin-2
In reply to this post by adf_ncgr
Hi Andrew & Hrishikesh,

Thanks for your patience on this response. 

I think it may be possible to do what you want with a more simple module.    The Tripal feature module already provides "gene" pages for you and does all the syncing for features so you shouldn't have to recreate that code in your module.   If I understand correctly you need to add additional information to the gene page, such as gene family membership?  If so, you don't need to create a new node type.  All you need is a new template file for it and some code to tell Drupal/Tripal about your new template.  Here's how you can create a new template in your module, which should simplify it quite a bit:

1)  Define your template file in the hook_theme() function of your module.  This tells Drupal that you have a new template file it should know about. The hook_theme() function goes in your [your module]/[your module].module file. 

2)  Create the template file to display the gene membership information in the format you want.  You can follow other template files in Tripal for examples. These template files should contain only HTML and very simple PHP code to insert the necessary variables.  You should use the chado_generate_var() and chado_expand_var() to retrieve data from the Chado schema (we suggest not to use SQL in template files).

3)  If the chado_generate_var() and chado_expand_var() functions don't adequately address queries or you find you are doing a lot of non-simple PHP code  then you should add a 'preprocess' function to your module in the [your module]/theme/[your module].theme.inc file.  The preprocess function is called before Drupal uses your template to create content. This is where you prepare variables that are exported to the templates.  The preprocess function should be named:  [your module]_preprocess_[template name]().

4)   In the hook_node_view() function you tell Drupal to use the template whenever it encounters a node of type 'chado_feature' (a gene page will be of this type).

I realize that's a bit lacking on finer details, but it should simplify the code in your module.  If you have questions feel free to ask further and I can clarify any of the suggestions above.

Stephen


On 11/5/2014 1:46 AM, Andrew Farmer wrote:
Hi Stephen-
thanks for your help with Hrishikesh's questions. Regarding the question of whether this may be duplicating effort, it's
certainly possible; but just to give some further context, we're basically looking for a way to expose
information such as gene family membership that will likely be fairly specific to the gene subclass of features. Our initial
goals are fairly modest and can probably be accomplished in several ways. We would certainly be interested if you could
point us to other examples of how people are using tripal to present gene-specific information in more customized ways.

thanks again

Andrew Farmer


On 11/3/14 11:43 AM, Stephen Ficklin wrote:
Hi Hrishikesh,

It looks like we are missing some information in the tripal_example.chado_node.inc file that gives this information.   If you take a look in the same file in the feature module you'll see the function chado_feature_insert() and at the bottom of that function is where the entry is added to the linking table.  Here's the snippet of code from that function:

  // Make sure the entry for this feature doesn't already exist in the
  // chado_feature table if it doesn't exist then we want to add it.
  $check_org_id = chado_get_id_from_nid('feature', $node->nid);
  if (!$check_org_id) {
    $record = new stdClass();
    $record->nid = $node->nid;
    $record->vid = $node->vid;
    $record->feature_id = $feature_id;
    drupal_write_record('chado_feature', $record);
  }


However, it sounds as though you may be duplicating effort.  The feature module should already provide gene pages for you and if you want to customize the way those gene pages look you just need to edit the existing template files.  Have you tried that route and can't get it to do what you are needing?

Stephen

On 11/3/2014 12:27 PM, Hrishikesh A. Lokhande wrote:
Hello all,

I am working on implementing a gene module and using the example module and api’s from tripal.info for my reference. 

My module is partly functional, I am having issues with the chado_node_sync_form function. The following is what I have implemented. 



function triapl_gene_menu(){
   $items=array();
   .
   .
   .
   .
    $items['admin/tripal/chado/tripal_gene/sync'] = array(
    'title' => ' Sync',
    'description' => 'Create pages on this site for genes stored in Chado',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('chado_node_sync_form', 'tripal_gene', 'chado_gene'),
    'access arguments' => array('administer tripal gene'),
    'type' => MENU_LOCAL_TASK,
    'weight' => 2
  );
  .
  .
  .
  .
  return $items;


}


function tripal_gene_node_info() {
  return array(
    'chado_gene' => array(
      'name'        => t('Gene'),
      'base'        => 'chado_gene',
      'description' => t('A gene from the Chado database'),
      'has_title'   => TRUE,
      'locked'      => TRUE,
      'chado_node_api' => array(
        'base_table' => 'gene',
        'hook_prefix' => 'chado_gene',
        'record_type_title' => array(
          'singular' => t('Gene'),
          'plural' => t('Genes')
        ),
        'sync_filters' => array(
          'type_id' => FALSE,
          'organism_id' => FALSE
        ),
      ),
    ),
  );
}

The sync works from the UI but doesn’t populate the chado_gene table, I can see entries in the node table for chado_gene. 

Is there any other function that I need to implement (like hook_insert) to populate chado_gene?

Thanks 


Hrishikesh A. Lokhande
Bioinformatics Analyst
National Center for Genome Resources 



------------------------------------------------------------------------------


_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal



------------------------------------------------------------------------------


_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal

-- 
...all concepts in which an entire process is semiotically concentrated
elude definition; only that which has no history is definable.

Friedrich Nietzsche


------------------------------------------------------------------------------


_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
_______________________________________________
Gmod-tripal mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-tripal