Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions js/source/modules/wizard-downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export function WizardDownloads(main_id,wizard){
var level = d3.select(".wizard-download-phenotypes-level").node().value;
var timestamp = d3.selectAll('.wizard-download-phenotypes-timestamp').property('checked')?1:0;
var entry_numbers = d3.selectAll('.wizard-download-phenotypes-entry-numbers').property('checked')?1:0;
var trait_synonyms = d3.selectAll('.wizard-download-phenotypes-trait-synonyms').property('checked')?1:0;
var intercrop = d3.selectAll('.wizard-download-phenotypes-intercrop').property('checked')?1:0;
var outliers = d3.selectAll('.wizard-download-phenotypes-outliers').property('checked')?1:0;
var names = JSON.stringify(d3.select(".wizard-download-phenotypes-name").node().value.split(","));
Expand Down Expand Up @@ -223,6 +224,7 @@ export function WizardDownloads(main_id,wizard){
phenotype_max_value: max,
timestamp: timestamp,
entry_numbers: entry_numbers,
trait_synonyms: trait_synonyms,
intercrop: intercrop,
trait_contains: names,
include_row_and_column_numbers: 1,
Expand Down
22 changes: 18 additions & 4 deletions lib/CXGN/Phenotypes/PhenotypeMatrix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,20 @@ has 'trait_repeat_types' => ( # returns the repeat type for every trait keyed by
default => sub { return {} },
);

has 'include_trait_synonyms' => ( # when true, will set the column header as "SYN = TRAIT NAME|CO_xxx:yyyyyy"
isa => 'Bool',
is => 'rw',
default => 0
);

sub get_phenotype_matrix {
my $self = shift;
my $include_pedigree_parents = $self->include_pedigree_parents();
my $include_timestamp = $self->include_timestamp;
my $include_phenotype_primary_key = $self->include_phenotype_primary_key;
my $include_intercrop_stocks = $self->include_intercrop_stocks;
my $include_entry_numbers = $self->include_entry_numbers;
my $include_trait_synonyms = $self->include_trait_synonyms;
my %trial_entry_numbers;

$self->trait_repeat_types( $self->retrieve_trait_repeat_types() );
Expand Down Expand Up @@ -272,12 +279,12 @@ sub get_phenotype_matrix {
}
);

my ($data, $unique_traits);
my ($data, $unique_traits, $trait_synonyms);
my @info;
my @metadata_headers = ( 'studyYear', 'programDbId', 'programName', 'programDescription', 'studyDbId', 'studyName', 'studyDescription', 'studyDesign', 'plotWidth', 'plotLength', 'fieldSize', 'fieldTrialIsPlannedToBeGenotyped', 'fieldTrialIsPlannedToCross', 'plantingDate', 'harvestDate', 'locationDbId', 'locationName', 'germplasmDbId', 'germplasmName', 'germplasmSynonyms', 'observationLevel', 'observationUnitDbId', 'observationUnitName', 'replicate', 'blockNumber', 'plotNumber', 'rowNumber', 'colNumber', 'entryType', 'plantNumber');

if ($self->search_type eq 'MaterializedViewTable'){
($data, $unique_traits) = $phenotypes_search->search();
($data, $unique_traits, $trait_synonyms) = $phenotypes_search->search();
print STDERR "No of lines retrieved: ".scalar(@$data)."\n";
print STDERR "Construct Pheno Matrix Start:".localtime."\n";

Expand Down Expand Up @@ -310,7 +317,10 @@ sub get_phenotype_matrix {

my @sorted_traits = sort keys(%$unique_traits);
foreach my $trait (@sorted_traits) {
push @line, $trait;
my $trait_id = $unique_traits->{$trait};
my $trait_syn = $trait_synonyms->{$trait_id};

push @line, defined $trait_syn && $include_trait_synonyms ? "$trait_syn = $trait" : $trait;
if ($include_phenotype_primary_key) {
push @line, $trait.'_phenotype_id';
}
Expand Down Expand Up @@ -474,6 +484,7 @@ sub get_phenotype_matrix {
push @{ $obsunit_data{$d->{obsunit_stock_id}}->{$d->{trait_name} } }, $value;
}

my %trait_synonyms;
foreach my $d (@$data) {
my $obsunit_id = $d->{obsunit_stock_id};
if (!exists($seen_obsunits{$obsunit_id})) {
Expand Down Expand Up @@ -551,6 +562,8 @@ sub get_phenotype_matrix {
if ($cvterm){
my $timestamp_value = $d->{timestamp};
my $value = $d->{phenotype_value};
my $syn = $d->{trait_synonym};
$trait_synonyms{$cvterm} = $syn if $syn;
#my $cvterm = $trait."|".$cvterm_accession;
# if ($include_timestamp && $timestamp_value) {
# $obsunit_data{$obsunit_id}->{$cvterm} = "$value,$timestamp_value";
Expand Down Expand Up @@ -671,7 +684,8 @@ sub get_phenotype_matrix {

my @sorted_traits = sort keys(%traits);
foreach my $trait (@sorted_traits) {
push @line, $trait;
my $syn = $trait_synonyms{$trait};
push @line, defined $syn && $include_trait_synonyms ? "$syn = $trait" : $trait;
}
push @line, 'notes';

Expand Down
38 changes: 36 additions & 2 deletions lib/CXGN/Phenotypes/Search/MaterializedViewTable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,37 @@ sub search {
$location_id_lookup{$r->nd_geolocation_id} = $r->description;
}

# Get the trait ontology CVs
my $type_cvterm = $schema->resultset("Cv::Cvterm")->search(
{
'me.name' => { -in => ['trait_ontology', 'composed_trait_ontology'] },
'cv.name' => 'composable_cvtypes'
},
{ join => 'cv' }
);
my @type_ids = $type_cvterm->get_column('cvterm_id')->all();
my $trait_cv = $schema->resultset("Cv::Cvprop")->search({ type_id => { -in => \@type_ids } });
my @trait_cv_ids = $trait_cv->get_column('cv_id')->all();

# Create a map of trait cvterm_ids -> synonyms
my %trait_synonyms;
my $cvtermsynonym_rs = $schema->resultset("Cv::Cvtermsynonym")->search(
{
'cvterm.cv_id' => { -in => \@trait_cv_ids }
},
{
select => [ 'cvterm.cvterm_id', { min => 'synonym', -as => 'synonym' } ],
as => ['cvterm_id', 'synonym'],
join => 'cvterm',
group_by => [ 'cvterm.cvterm_id' ]
}
);
while ( my $r = $cvtermsynonym_rs->next() ) {
my $cvterm_id = $r->get_column('cvterm_id');
my $synonym = $r->get_column('synonym');
$trait_synonyms{$cvterm_id} = $synonym;
}

my $h = $schema->storage->dbh()->prepare($q);
$h->execute();
my @result;
Expand Down Expand Up @@ -443,7 +474,7 @@ sub search {


my $phenotype_uniquename = $o->{uniquename};
$unique_traits{$trait_name}++;
$unique_traits{$trait_name} = $o->{trait_id};
if ($include_timestamp){

my $timestamp_value;
Expand All @@ -470,6 +501,9 @@ sub search {
}
}
}

$o->{trait_synonym} = $trait_synonyms{$o->{trait_id}};

push @return_observations, $o;
}

Expand Down Expand Up @@ -538,7 +572,7 @@ sub search {
#print STDERR Dumper \@result;

print STDERR "Search End:".localtime."\n";
return (\@result, \%unique_traits);
return (\@result, \%unique_traits, \%trait_synonyms);
}

sub _sql_from_arrayref {
Expand Down
7 changes: 5 additions & 2 deletions lib/CXGN/Phenotypes/Search/Native.pm
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ sub search {
LEFT JOIN phenotype USING(phenotype_id)
$phenotypeprop_sql
LEFT JOIN cvterm ON (phenotype.cvalue_id=cvterm.cvterm_id)
LEFT JOIN cvtermsynonym ON (cvterm.cvterm_id = cvtermsynonym.cvterm_id)
LEFT JOIN dbxref ON (cvterm.dbxref_id = dbxref.dbxref_id)
LEFT JOIN db USING(db_id)
LEFT JOIN nd_experiment_project ON (nd_experiment_project.nd_experiment_id=nd_experiment_stock.nd_experiment_id)
Expand Down Expand Up @@ -420,6 +421,7 @@ sub search {
folder.description,
cvterm.cvterm_id,
(((cvterm.name::text || '|'::text) || db.name::text) || ':'::text) || dbxref.accession::text,
MIN(cvtermsynonym.synonym),
phenotype.value,
phenotype.uniquename,
phenotype.phenotype_id,
Expand All @@ -433,7 +435,7 @@ sub search {
STRING_AGG(DISTINCT(ics.uniquename), ',')
".$design_layout_select;

my $order_clause = " ORDER BY 6, 2, 29";
my $order_clause = " ORDER BY 6, 2, 30";

my $group_by = " GROUP BY observationunit.stock_id,
observationunit.uniquename,
Expand Down Expand Up @@ -636,7 +638,7 @@ sub search {

my $calendar_funcs = CXGN::Calendar->new({});

while (my ($observationunit_stock_id, $observationunit_uniquename, $observationunit_type_name, $germplasm_uniquename, $germplasm_stock_id, $project_project_id, $project_name, $project_description, $plot_width, $plot_length, $field_size, $field_trial_is_planned_to_be_genotyped, $field_trial_is_planned_to_cross, $breeding_program_project_id, $breeding_program_name, $breeding_program_description, $year, $design, $location_id, $planting_date, $harvest_date, $folder_id, $folder_name, $folder_description, $trait_id, $trait_name, $phenotype_value, $phenotype_uniquename, $phenotype_id, $phenotype_collect_date, $phenotype_operator, $phenotype_additional_info, $phenotype_external_references, $full_count, $notes, $intercrop_stock_id, $intercrop_stock_name, $rep_select, $block_number_select, $plot_number_select, $is_a_control_select, $row_number_select, $col_number_select, $plant_number) = $h->fetchrow_array()) {
while (my ($observationunit_stock_id, $observationunit_uniquename, $observationunit_type_name, $germplasm_uniquename, $germplasm_stock_id, $project_project_id, $project_name, $project_description, $plot_width, $plot_length, $field_size, $field_trial_is_planned_to_be_genotyped, $field_trial_is_planned_to_cross, $breeding_program_project_id, $breeding_program_name, $breeding_program_description, $year, $design, $location_id, $planting_date, $harvest_date, $folder_id, $folder_name, $folder_description, $trait_id, $trait_name, $trait_synonym, $phenotype_value, $phenotype_uniquename, $phenotype_id, $phenotype_collect_date, $phenotype_operator, $phenotype_additional_info, $phenotype_external_references, $full_count, $notes, $intercrop_stock_id, $intercrop_stock_name, $rep_select, $block_number_select, $plot_number_select, $is_a_control_select, $row_number_select, $col_number_select, $plant_number) = $h->fetchrow_array()) {
my $timestamp_value;
my $operator_value;
if ($include_timestamp) {
Expand Down Expand Up @@ -733,6 +735,7 @@ sub search {
folder_description => $folder_description,
trait_id => $trait_id,
trait_name => $trait_name,
trait_synonym => $trait_synonym,
phenotype_value => $phenotype_value,
phenotype_uniquename => $phenotype_uniquename,
phenotype_id => $phenotype_id,
Expand Down
1 change: 1 addition & 0 deletions lib/CXGN/Trial/Download.pm
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ has 'include_timestamp' => (isa => 'Bool', is => 'ro', default => 0);
has 'include_pedigree_parents' => (isa => 'Bool', is => 'ro', default => 0);
has 'include_intercrop_stocks' => (isa => 'Bool|Undef', is => 'ro', default => 0);
has 'include_entry_numbers' => (isa => 'Bool|Undef', is => 'ro', default => 0);
has 'include_trait_synonyms' => (isa => 'Bool|Undef', is => 'ro', default => 0);
has 'exclude_phenotype_outlier' => (isa => 'Bool', is => 'ro', default => 0);
has 'has_header' => (isa => 'Bool', is => 'ro', default => 1);
has 'trait_contains' => (isa => 'ArrayRef[Str]|Undef', is => 'rw');
Expand Down
2 changes: 2 additions & 0 deletions lib/CXGN/Trial/Download/Plugin/TrialPhenotypeCSV.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ sub download {
my $include_pedigree_parents = $self->include_pedigree_parents();
my $include_intercrop_stocks = $self->include_intercrop_stocks();
my $include_entry_numbers = $self->include_entry_numbers();
my $include_trait_synonyms = $self->include_trait_synonyms();
my $search_type = $self->search_type();
my $phenotype_start_date = $self->start_date();
my $phenotype_end_date = $self->end_date();
Expand Down Expand Up @@ -133,6 +134,7 @@ sub download {
include_pedigree_parents=>$include_pedigree_parents,
include_intercrop_stocks=>$include_intercrop_stocks,
include_entry_numbers=>$include_entry_numbers,
include_trait_synonyms=>$include_trait_synonyms,
phenotype_start_date => $phenotype_start_date,
phenotype_end_date => $phenotype_end_date,
repetitive_measurements => $repetitive_measurements,
Expand Down
2 changes: 2 additions & 0 deletions lib/CXGN/Trial/Download/Plugin/TrialPhenotypeExcel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ sub download {
my $search_type = $self->search_type();
my $include_intercrop_stocks = $self->include_intercrop_stocks();
my $include_entry_numbers = $self->include_entry_numbers();
my $include_trait_synonyms = $self->include_trait_synonyms();
my $phenotype_start_date = $self->start_date();
my $phenotype_end_date = $self->end_date();
my $repetitive_measurements = $self->repetitive_measurements();
Expand Down Expand Up @@ -133,6 +134,7 @@ sub download {
phenotype_max_value=>$phenotype_max_value,
include_intercrop_stocks=>$include_intercrop_stocks,
include_entry_numbers=>$include_entry_numbers,
include_trait_synonyms=>$include_trait_synonyms,
phenotype_start_date => $phenotype_start_date,
phenotype_end_date => $phenotype_end_date,
repetitive_measurements => $repetitive_measurements
Expand Down
4 changes: 4 additions & 0 deletions lib/SGN/Controller/BreedersToolbox/Download.pm
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ sub download_phenotypes_action : Path('/breeders/trials/phenotype/download') Arg
my $include_pedigree_parents = $c->req->param('include_pedigree_parents');
my $include_intercrop_stocks = $c->req->param("intercrop") && $c->req->param("intercrop") ne 'null' && $c->req->param("intercrop") ne 'undefined' ? $c->req->param("intercrop") : 0;
my $include_entry_numbers = $c->req->param("entry_numbers") && $c->req->param("entry_numbers") ne 'null' ? $c->req->param("entry_numbers") : 0;
my $include_trait_synonyms = $c->req->param("trait_synonyms") && $c->req->param("trait_synonyms") ne 'null' ? $c->req->param("trait_synonyms") : 0;
my $trait_list = $c->req->param("trait_list");
my $trait_component_list = $c->req->param("trait_component_list");
my $year_list = $c->req->param("year_list");
Expand Down Expand Up @@ -437,6 +438,7 @@ sub download_phenotypes_action : Path('/breeders/trials/phenotype/download') Arg
include_pedigree_parents=>$include_pedigree_parents,
include_intercrop_stocks => $include_intercrop_stocks,
include_entry_numbers => $include_entry_numbers,
include_trait_synonyms => $include_trait_synonyms,
exclude_phenotype_outlier => $exclude_phenotype_outlier,
trait_contains => \@trait_contains_list,
phenotype_min_value => $phenotype_min_value,
Expand Down Expand Up @@ -532,6 +534,7 @@ sub download_action : Path('/breeders/download_action') Args(0) {
my $exclude_phenotype_outlier = $c->req->param("exclude_phenotype_outlier") || 0;
my $include_intercrop_stocks = $c->req->param("intercrop") || 0;
my $include_entry_numbers = $c->req->param("entry_numbers") || 0;
my $include_trait_synonyms = $c->req->param("trait_synonyms") || 0;
my $timestamp_included = $c->req->param("timestamp") || 0;

# parameters for outliers download
Expand Down Expand Up @@ -647,6 +650,7 @@ sub download_action : Path('/breeders/download_action') Args(0) {
dataset_excluded_outliers=>$dataset_outliers,
include_intercrop_stocks=>$include_intercrop_stocks,
include_entry_numbers=>$include_entry_numbers,
include_trait_synonyms=>$include_trait_synonyms,
data_level=>$datalevel,
);
@data = $phenotypes_search->get_phenotype_matrix();
Expand Down
Loading
Loading