3 SGN::Controller::AJAX::VectorConstruct - a REST controller class for Vector Constructs.
7 Synchronizes vector constructs into the database from the ETHZ CASS database.
11 Nicolas Morales <nm529@cornell.edu>
15 package SGN
::Controller
::AJAX
::VectorConstruct
;
18 use JSON
-support_by_pp
;
19 use List
::MoreUtils qw
/any /;
22 use SGN
::Model
::Cvterm
;
25 BEGIN { extends
'Catalyst::Controller::REST' }
28 default => 'application/json',
30 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
33 sub sync_cass_constructs
: Path
('/ajax/cass_vector_construct/sync') Args
(0) ActionClass
('REST') { }
35 sub sync_cass_constructs_POST
{
39 my $schema = $c->dbic_schema("Bio::Chado::Schema");
41 my $construct_names = decode_json
($c->req->param("data"));
42 my %construct_hash = %$construct_names;
43 my $constructs = $construct_hash{construct
};
44 my @construct_array = @
$constructs;
46 my $stock_type_id = SGN
::Model
::Cvterm
->get_cvterm_row($schema, 'vector_construct', 'stock_type')->cvterm_id();
48 my $create_db = $schema->resultset("General::Db")->find_or_create({
50 description
=> 'Internal ETHZ CASS DB',
52 url
=> 'https://cass.pb.ethz.ch'
55 foreach (@construct_array) {
56 #print STDERR $_->{construct};
57 #print STDERR $_->{construct_id};
58 #print STDERR $_->{level};
60 my $create_stock = $schema->resultset("Stock::Stock")->find_or_create({
61 uniquename
=> $_->{construct
},
62 name
=> $_->{construct
},
63 type_id
=> $stock_type_id,
66 my $create_dbxref = $schema->resultset("General::Dbxref")->find_or_create({
67 db_id
=> $create_db->db_id(),
68 accession
=> $_->{construct_id
},
69 version
=> 'vector_construct',
70 description
=> 'ETHZ_CASS vector_construct id'
73 my $create_stock_dbxref = $schema->resultset("Stock::StockDbxref")->find_or_create({
74 stock_id
=> $create_stock->stock_id(),
75 dbxref_id
=> $create_dbxref->dbxref_id()
79 #print STDERR Dumper $constructs;
80 #print STDERR $status;
82 $c->stash->{rest
} = {response
=>$status};