2 package SGN
::Controller
::AJAX
::BreedersToolbox
::Population
;
5 use Bio
::GeneticRelationships
::Population
;
6 use List
::MoreUtils qw
| any
|;
9 BEGIN { extends
'Catalyst::Controller::REST' }
12 default => 'application/json',
14 map => { 'application/json' => 'JSON', 'text/html' => 'JSON' },
19 isa
=> 'DBIx::Class::Schema',
23 sub create_population
:Path
('/ajax/population/new') Args
(0) {
27 my $population_name = $c->req->param('population_name');
28 my @members = $c->req->param('accessions[]');
29 my $schema = $c->dbic_schema("Bio::Chado::Schema");
31 my $population = Bio
::GeneticRelationships
::Population
->new( { name
=> $population_name});
32 $population->set_members(\
@members);
35 my $population_cvterm_id = $c->model("Cvterm")->get_cvterm_row($schema, "population", "stock_type");
36 my $member_of_cvterm_id = $c->model("Cvterm")->get_cvterm_row($schema, "member_of", "stock_relationship");
38 # create population stock entry
40 my $pop_rs = $schema->resultset("Stock::Stock")->create(
42 name
=> $population_name,
43 uniquename
=> $population_name,
44 type_id
=> $population_cvterm_id->cvterm_id(),
47 # generate population connections to the members
48 foreach my $m (@members) {
49 my $m_row = $schema->resultset("Stock::Stock")->find({ uniquename
=> $m });
50 my $connection = $schema->resultset("Stock::StockRelationship")->create(
52 subject_id
=> $m_row->stock_id,
53 object_id
=> $pop_rs->stock_id,
54 type_id
=> $member_of_cvterm_id->cvterm_id(),
57 $c->stash->{rest
} = { message
=> "Success! Population created" };