Merge pull request #5230 from solgenomics/topic/open_pollinated
[sgn.git] / lib / SGN / Controller / AJAX / Transgenic.pm
blob2c6c63563f87fc0dcd61e14699a129407253eaf6
1 =head1 NAME
3 SGN::Controller::AJAX::Transgenic - a REST controller class for Vector Constructs.
5 =head1 DESCRIPTION
7 Synchronizes transgenic accessions into the database from the ETHZ CASS database.
9 =head1 AUTHOR
11 Nicolas Morales <nm529@cornell.edu>
13 =cut
15 package SGN::Controller::AJAX::Transgenic;
17 use Moose;
18 use JSON -support_by_pp;
19 use List::MoreUtils qw /any /;
20 use Data::Dumper;
21 use JSON;
22 use SGN::Model::Cvterm;
25 BEGIN { extends 'Catalyst::Controller::REST' }
27 __PACKAGE__->config(
28 default => 'application/json',
29 stash_key => 'rest',
30 map => { 'application/json' => 'JSON' },
34 sub sync_cass_transgenics : Path('/ajax/cass_transgenics/sync') Args(0) ActionClass('REST') { }
36 sub sync_cass_transgenics_POST {
37 my $self = shift;
38 my $c = shift;
39 my $status = '';
40 my $schema = $c->dbic_schema("Bio::Chado::Schema");
42 my $transgenic_names = decode_json($c->req->param("data"));
43 my %transgenic_hash = %$transgenic_names;
44 my $transgenics = $transgenic_hash{transgenic};
45 my @transgenics_array = @$transgenics;
47 my $stock_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'accession', 'stock_type')->cvterm_id();
48 my $stock_prop_type_id = SGN::Model::Cvterm->get_cvterm_row($schema, 'transgenic', 'stock_property')->cvterm_id();
50 my $create_db = $schema->resultset("General::Db")->find_or_create({
51 name => 'ETHZ_CASS',
52 description => 'Internal ETHZ CASS DB',
53 urlprefix => '',
54 url => 'https://cass.pb.ethz.ch'
55 });
57 foreach (@transgenics_array) {
58 #print STDERR $_->{construct};
59 #print STDERR $_->{construct_id};
60 #print STDERR $_->{level};
62 my $create_stock = $schema->resultset("Stock::Stock")->find_or_create({
63 uniquename => $_->{transgenic},
64 name => $_->{transgenic},
65 type_id => $stock_type_id,
66 });
68 my $create_dbxref = $schema->resultset("General::Dbxref")->find_or_create({
69 db_id => $create_db->db_id(),
70 accession => $_->{transgenic_id},
71 version => 'transgenic',
72 description => 'ETHZ_CASS transgenic id'
73 });
75 my $create_stock_dbxref = $schema->resultset("Stock::StockDbxref")->find_or_create({
76 stock_id => $create_stock->stock_id(),
77 dbxref_id => $create_dbxref->dbxref_id()
78 });
80 my $create_stock_prop = $schema->resultset("Stock::Stockprop")->find_or_create({
81 stock_id => $create_stock->stock_id(),
82 type_id => $stock_prop_type_id,
83 value => 1
84 });
87 #print STDERR Dumper $transgenics;
88 #print STDERR $status;
90 $c->stash->{rest} = {response=>$status};