Skip to content

Commit

Permalink
Add allele loading for JSON importing
Browse files Browse the repository at this point in the history
Refs #1779
  • Loading branch information
kimrutherford committed Feb 24, 2019
1 parent 601ad92 commit 6905682
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 7 deletions.
35 changes: 35 additions & 0 deletions lib/Canto/Curs/AlleleManager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,39 @@ sub allele_from_json
return $schema->create_with_type('Allele', \%create_args);
}

=head2 create_simple_allele
Usage : my $allele = $allele_manager->create_simple_allele(...);
Function: Create an Allele object given some allele properties and a gene
Args : $primary_identifier - the primary key in the database
$allele_type
$name
$description
$expression
$gene - a Gene object
Returns : the new Allele
=cut

sub create_simple_allele
{
my $self = shift;

my $primary_identifier = shift;
my $allele_type = shift;
my $name = shift;
my $description = shift;
my $gene = shift;

my %create_args = (
primary_identifier => $primary_identifier,
type => $allele_type,
name => $name || undef,
description => $description || undef,
gene => $gene->gene_id(),
);

return $self->curs_schema()->create_with_type('Allele', \%create_args);
}

1;
47 changes: 43 additions & 4 deletions lib/Canto/Track/LoadUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ use feature qw(state);
use Package::Alias PubmedUtil => 'Canto::Track::PubmedUtil';

use Canto::Curs::GeneManager;
use Canto::Curs::AlleleManager;
use Canto::Curs::GenotypeManager;

use Canto::Track;

Expand Down Expand Up @@ -858,8 +860,14 @@ sub create_sessions_from_json
my ($curs, $cursdb) =
Canto::Track::create_curs($config, $self->schema(), $pub, $connect_options);

my $gene_manager = Canto::Curs::GeneManager->new(config => $config,
curs_schema => $cursdb);
push @results, [$curs, $cursdb];

my $allele_manager =
Canto::Curs::AlleleManager->new(config => $config, curs_schema => $cursdb);
my $genotype_manager =
Canto::Curs::GenotypeManager->new(config => $config, curs_schema => $cursdb);
my $gene_manager =
Canto::Curs::GeneManager->new(config => $config, curs_schema => $cursdb);

$curator_manager->set_curator($curs->curs_key(), $curator_email_address);

Expand All @@ -871,12 +879,43 @@ sub create_sessions_from_json
print "created session: ", $curs->curs_key(), " pub: ", $pub->uniquename(),
" for: $curator_email_address\n";

my %db_genes = ();

for my $gene_uniquename (@{$session_data->{genes}}) {
my $lookup_result = $gene_lookup->lookup([$gene_uniquename]);
$gene_manager->create_genes_from_lookup($lookup_result);
my %result = $gene_manager->create_genes_from_lookup($lookup_result);
while (my ($result_uniquename, $result_gene) = each %result) {
$db_genes{$result_uniquename} = $result_gene;
}
}
}

my $alleles = $session_data->{alleles};

if ($alleles) {
while (my ($allele_uniquename, $allele_details) = each %$alleles) {
my $allele_gene_uniquename = $allele_details->{gene};
if (!defined $allele_gene_uniquename) {
die qq|no "gene" field in details for $allele_uniquename in $pub_uniquename|;
}
my $gene = $db_genes{$allele_gene_uniquename};
if (!defined $gene) {
die qq|no gene the session for $allele_uniquename in $pub_uniquename|;
}

my $type = $allele_details->{allele_type} || 'other';
my $name = $allele_details->{allele_name} || undef;
my $description = $allele_details->{allele_description} || undef;
my @args = ($allele_uniquename, $type, $name, $description, $gene);

my @alleles_for_make_genotype =
$allele_manager->create_simple_allele(@args);

$genotype_manager->make_genotype(undef, undef, \@alleles_for_make_genotype,
$gene->organism()->taxonid(),
"genotype-$allele_uniquename");
}
}
}

return @results;
}
Expand Down
22 changes: 20 additions & 2 deletions t/60_load_util.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 4;
use Test::More tests => 10;
use Test::Exception;

use Canto::TestUtil;
Expand Down Expand Up @@ -31,6 +31,24 @@ my $gene_load = Canto::Track::GeneLoad->new(organism => $fly, schema => $schema)
$gene_load->create_gene('FBgn0004107', 'Dmel\Cdk2', [], 'Cyclin-dependent kinase 2');
$gene_load->create_gene('FBgn0016131', 'Dmel\Cdk4', [], 'Cyclin-dependent kinase 4');
my $test_json_file = $test_util->root_dir() . '/t/data/sessions_from_json_test.json';
my ($curs, $cursdb, $person) =
my @created_sessions =
$load_util->create_sessions_from_json($config, $test_json_file,
'test.user@3926fef56bb23eb871ee91dc2e3fdd7c46ef1385.org');

is (@created_sessions, 1);

my ($created_curs, $created_cursdb) = @{$created_sessions[0]};

my $FBal0119310_allele =
$created_cursdb->resultset('Allele')->find({ primary_identifier => "FBal0119310" });

ok (defined $FBal0119310_allele);

is($FBal0119310_allele->type(), 'other');
is($FBal0119310_allele->name(), 'Dmel\Cdk2_UAS.Tag:MYC');
is($FBal0119310_allele->description(), 'description of FBal0119310');

my $genotype_FBal0119310 =
$created_cursdb->resultset('Genotype')->find({ identifier => "genotype-FBal0119310" });

is(($genotype_FBal0119310->alleles()->all())[0]->name(), 'Dmel\Cdk2_UAS.Tag:MYC');
2 changes: 1 addition & 1 deletion t/data/sessions_from_json_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"gene": "FBgn0004107",
"allele_type": "other",
"allele_name": "Dmel\\Cdk2_UAS.Tag:MYC",
"allele_description": null
"allele_description": "description of FBal0119310"
},
"FBal0064432": {
"gene": "FBgn0016131",
Expand Down

0 comments on commit 6905682

Please sign in to comment.