Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creates rawphenotypes germplasm field #88

Merged
merged 16 commits into from
Jun 24, 2022

Conversation

reynoldtan
Copy link
Member

@reynoldtan reynoldtan commented Dec 22, 2021

This PR will create a Custom Tripal Field that will add raw phenotypes download functionality to germplasm page.
raw-germplasm-page-mockup

Metadata

  • Issue #
  • I feel this PR is ready to be merged.
  • This PR is dependent upon [PR #/ nothing]

Documentation:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Description

Dependencies

Testing?

  • I tested on a generic Tripal Site
  • I tested on a KnowPulse Clone
  • This PR includes automated testing

Setup

  1. On a KP clone, update rawphenotypes module and switch branch to rawphenotypes-germplasm-field
  2. Clear cache (optional)
  3. Setup Tripal Field in Structure -> Tripal Content Types and click on Manage Fields operation for Germplasm Accession content type.
  4. Once in this page click +Check for new fields. This will ensure that the rawphenotypes germplasm field will be discovered.
    add-field
  5. Click Manage Display tab and set up the following items:
    A. A group titled Raw Phenotypes and set the format to Tripal Pane
    B. Under this group add an item clicking the + symbol preceding Germplasm Raw Phenotypes Field
    field-setup

NOTE: at the moment the cog icon to update id, classes and visibility option is causing an AJAX error leaving this field to be hidden by default (hide = yes).

  1. Search a germplasm - you can use the germplasm search in homepage for example CDC Robin AGL.

The Interface

  1. Test accessibility by changing the screen size of the browser while on germplasm page for CDC Robin AGL. Ensure that the field elements are still accessible.
  2. Test controls work - click on Raw Phenotypes definition and link to Download Page.
  3. Export Test: Select a Trait of interest and expand the select option for Location/Experiment.
    select
  4. Note some experiments are disabled when experiment is not assigned to the current user as specified in the warning on screen.
  5. When selecting an active location/experiment the document icon activates and clicking it will launch a new window to begin data export identical to the download features seen in Download Page of rawphenotypes.
  6. Allow module to fetch dataset and prepare export file.
    download
  7. Click file link to view result. The resulting phenotypes should be filtered to match the germplasm, experiment, location and trait.

@ruobinLiu
Copy link

For step #7: downloaded file contains germplasm, location and trait applied, but misses experiment. An additional trait, # of Seeds Planted (count), is always included by default.
Screen Shot 2022-01-17 at 2 51 19 PM
.

@reynoldtan
Copy link
Member Author

Experiment column added to results
image

@ruobinLiu
Copy link

I am now able to see the experiment column on my new dev fresh, PR works as expected. Great job 👍

includes/TripalFields/ncit__raw_data/ncit__raw_data.inc Outdated Show resolved Hide resolved
$summary['experiments'] = count(array_unique($cache_exp));
$summary['locations'] = count(array_unique($cache_loc));

$entity->{$field_name}['und'][0]['value']['NCIT:Raw Data'] = array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the value should not be keyed by the field name. Also, you should always use the new array notation: [ ] rather than the old style for PHP compatibility reasons.

Suggested change
$entity->{$field_name}['und'][0]['value']['NCIT:Raw Data'] = array(
$entity->{$field_name}['und'][0]['value'] = array(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the keys exposed through the value should be cvterms and should only represent data. The icons feel out of place here as it relates to the format, not the data. All sub-keys as well so the counts in the summary should also have cvterms as keys.

if ($trait_set) {
foreach($trait_set as $trait_id => $trait_name) {
// Trait id, project id and name + location:
$trait_experiment_location[ $trait_id . '_' . $trait_name ][] = $trait_id . '#' . $item->project_id . '#' . $item->name . '#' . $item->location;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels very pre-formatted for what you want in the formatter. It should likely be broken out into a nested array with cvterm keys and then compiled to this format in the formatter.

// Create markup.
// Refer to this ID for CSS styling.
$id = 'rawphenotypes-germplasm-raw-phenotypes-field';
$markup = '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels very weird to see this much HTML in PHP strings... perhaps this should be in a template?

rawpheno.module Outdated
* Implements hook_field_group_build_pre_render_alter().
* Apply css and js.
*/
function rawpheno_field_group_build_pre_render_alter(&$element) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this add these resources indiscriminately?

@reynoldtan
Copy link
Member Author

Revised field formatter to use template file for the markup. I have kept all array construct - array() since it is used throughout the module and I have checked off item My code follows the code style of this project above. In my recent work of the module for Drupal 8/9 all instances of this array have been converted to the short array syntax.

Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

  • hook_field_group_build_pre_render_alter() removed and resources added in formatter
  • html moved into template file
  • formatting removed from the field class
  • Keys of values array should all be cvterms

The keys are still incorrect…

  // # SUMMARY COUNT:
  $summary = array();
  $summary['traits'] = count($trait_experiment_location);
  $summary['experiments'] = count(array_unique($cache_exp));
  $summary['locations'] = count(array_unique($cache_loc));

  $entity->{$field_name}['und'][0]['value'] = array(
    'user'      => $current_user,
    'germplasm' => $germplasm,
    'summary'   => $summary,
    'traits'    => $trait_experiment_location,
  );

All of the array keys should be cvterms! Even the nested ones. This is needed to work with web services.

Here is an example of what I mean:
https://github.com/tripal/trpfancy_fields/blob/master/includes/TripalFields/ChadoChartField.inc#L234-L237

      $entity->{$field_name}['und'][0]['value']['hydra:member'][] = array(
        'rdfs:label' => $r->{$label_column},
        'local:count' => $r->{$count_column},
      );

We use the hydra:member term to indicate an array of data such as your trait locations. This array should not be associative (i.e. keys should be simple iterative numbers) but that should not be a problem in your case as you don't access them by key anyway?

Then you need to create local terms for each associative key. Specifically, the following keys should all be cvterms:

  • user
    • permission
    • experiments
  • germplasm
    • id
    • name
  • summary
    • traits
    • experiments
    • locations
  • traits
    • trait_id
    • project_id
    • project_name
    • location

@reynoldtan
Copy link
Member Author

Revised the field instance and formatter to use cvterms as array keys. I have setup a cv name and named it in the same way as other cvs used by rawphenotypes (ie phenotype_measurement_units, phenotype_measurement_types etc.). I chose the name phenotype_customfield_terms and created the cv terms experiment, id, name, location, summary, experiment, user_experiment and trait to be used as keys. This cv will hold other terms in the future should raw phenotype custom field require other more terms.

Copy link
Member

@laceysanderson laceysanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Code looks good with the most recent changes 🎉

On to testing! The field seems to work as intended except for the download functionality. I select a location/experiment for the # Nodes on Primary Stem at R1 (1st; count) and then click download but the resulting file does not have that trait. I used CDC Robin AGL to test.
Screen Shot 2022-04-21 at 3 16 50 PM
Screen Shot 2022-04-21 at 3 16 59 PM
Screen Shot 2022-04-21 at 3 17 44 PM

I'm also wondering a bit about the design... I'm worried that Kirstin would be most likely to want all locations for a given experiment or even all data for that trait in general. Maybe you add some "ALL" options in the select list?

@reynoldtan
Copy link
Member Author

reynoldtan commented Apr 21, 2022

On it, I will setup the ALL option in the next commit 👍

@reynoldtan
Copy link
Member Author

image

I have added a filter by switch to allow export of phenotypes by either experiment or location + experiment. In addition to this option, users can download everything (all experiment user has permission to) in a trait + germplasm using the download all button preceding each trait. I also add expand table view and search trait to make finding a trait of interest less painful 😄 .

Tested

  • Export all phenotypes (1 experiment where I don't have permission to and this got excluded in the result)
  • By Location + Experiment
  • Location + Experiment where the trait was not measured (no stock id - plant id) but is a trait in an experiment (the missing trait error in the previous review)
  • By experiment
  • Raw Phenotypes Download page and works just as is without experiment column seen in export coming from raw data field.

@laceysanderson
Copy link
Member

I'm loving the new "Export everything in a trait + germplasm" button! Did a quick review on the new code since the last review and I think this is good :-)

I'm going to merge now but we won't update KP until July so nothing goes wrong right before the workshop ;-p

@laceysanderson laceysanderson merged commit 75addd0 into master Jun 24, 2022
@laceysanderson laceysanderson deleted the rawphenotypes-germplasm-field branch June 24, 2022 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants