2 package SGN
::Controller
::SimSearch
;
5 use File
::Temp
"tempdir";
8 BEGIN { extends
'Catalyst::Controller'; }
10 sub simsearch
: Path
('/tools/simsearch') {
14 $c->stash->{template
} = '/tools/simsearch/index.mas';
17 sub upload_file
: Path
('/tools/simsearch/upload_file') {
21 my $tempdir = $c->tempfiles_subdir("simsearch");
22 my $tempfile = $c->config->{basepath
}."/".$c->tempfile( TEMPLATE
=> 'simsearch/simsearch-XXXXXX', UNLINK
=> 0 );
25 my $upload = $c->request->upload('upload_vcf_file');
27 my $filename = $upload->filename();
29 print STDERR
"UPLOAD FILENAME: $filename\n";
30 my $format = "dosage";
32 if ($filename =~ m/\.vcf$/) {
36 my $tempname = $upload->tempname();
37 print STDERR
"TEMPNAME: $tempname\n";
39 $c->stash->{filename
} = $tempfile;
40 $c->stash->{template
} = '/tools/simsearch/upload_file.mas';
42 my $simsearch_datadir = $c->config->{simsearch_datadir
};
44 print STDERR
"SIMSEARCH DATADIR = $simsearch_datadir\n";
46 $upload->copy_to($tempfile);
48 my @files = glob "$simsearch_datadir/*";
50 print STDERR
"FILES: ".join(",",@files)."\n";
54 my $pulldown = "<select id=\"reference_file\" >\n";
55 foreach my $f (@files) {
56 $pulldown .= "<option>".basename
($f)."</option>";
58 $pulldown .="</select>";
60 # -i required input file -r reference file (with -i only, input is also used as reference)
61 # need to add a pull down with current genotypes for each protocol
63 print STDERR
"COPIED TO $tempfile\n";
64 $c->stash->{reference_files_menu
} = $pulldown;
65 $c->stash->{filename
} = basename
($tempfile);
66 $c->stash->{user_readable_filename
} = basename
($filename);
67 $c->stash->{format
} = $format;
70 sub process_file
:Path
('/tools/simsearch/process_file') :Args
(0) {
74 my $filename = $c->config->{basepath
}."/".$c->config->{tempfiles_subdir
}."/simsearch/".$c->req->param("filename");
76 my $fileurl = "/simsearch/".$c->req->param("filename");
78 print STDERR
"READING FROM $filename\n";
79 my $reference_file = $c->req->param("reference_file");
81 my $reference_file_path = $c->config->{simsearch_datadir
}."/".$reference_file;
82 # do not specify -r option when there is no reference file
85 if ($reference_file) {
86 $ref_option = " -r $reference_file_path ";
89 my $cmd = "../gtsimsrch/src/simsearch -i $filename $ref_option -o $filename.out";
91 print STDERR
"running command $cmd...\n";
95 system("perl ../gtsimsrch/src/agmr_cluster.pl < $filename.out > $filename.out.clusters");
98 open(my $F , "<", $filename.".out.clusters") || die "Can't open file $filename.out";
102 my $html = "<table cellspacing=\"20\" cellpadding=\"20\" border=\"1\">";
107 $html .= '<tr><td>'.$group.'</td><td>'. join('<br />', @line[4..@line-1])."</td></tr>\n";
114 # plot the agmr score distribution histogram using the 6th column in $filename.out
118 $c->stash->{results
} = $html;
119 $c->stash->{data
} = \
@data;
120 $c->stash->{histogram
} = $fileurl.".out_distances_histogram.png";
123 $c->stash->{template
} = '/tools/simsearch/results.mas';