diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bcbed57 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/.includepath +/.project diff --git a/README.md b/README.md index 0563141..eba096f 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,11 @@ R packages: abind, boot, cluster, ggplot2, gplots, Hmisc, MASS, MAST, RDRToolbox, reshape, rgl, RSvgDevice, stringr, survival, vioplot Apache or any other supported web server. # Install -
The software is tested on Fedora 20 and CentOS 7.0 using apache2, but should install on any other linux distribution.
+The software is tested on Fedora 20 and CentOS 7.0 using apache2, and Ubuntu 16.04. It should install on any other linux distribution, too. Windows is not supported!
Obtain and install my Stefans_Lib_Essentials Perl library.
Download this source and install it using the Perl make procedure:
In addition you will need to install R and my Rscexv package as well as the python ZIFA library.
To install the server files to your web path you should use the SCexV install.pl script scripts/install.pl. This script will take care of access rights, copy all required files and changes all links inside the server files to support install into a subpath. In other words it is absolutely not recommended to copy the source files to your web path by hand. ## install.pl usage @@ -35,3 +36,67 @@ The output from this script should help to pinpoint the missing parts. If this t # Example installationYou can access our installation at stemsysbio.bmc.lu.se/SCexV/. For more help on the usage please check out our instructional videos on our YouTube channel.
+ +# Installation on Ubuntu 16.04 fresh install + +sudo apt-get install libcatalyst-view-tt-perl libcatalyst-plugin-session-store-fastmmap-perl libcatalyst-plugin-session-store-cache-perl libcatalyst-plugin-redirect-perl libcatalyst-plugin-configloader-perl libcatalyst-perl libcatalyst-modules-perl libcatalyst-modules-extra-perl libcatalyst-action-rest-perl dos2unix libhtml-template-perl libnet-ssh2-perl libdatetime-format-mysql-perl libgd-svg-perl libdate-simple-perl pdl + +mkdir SRC +cd SRC + +git clone https://github.com/stela2502/Stefans_Lib_Esentials.git +cd Stefans_Lib_Esentials/Stefans_Libs_Essentials/ +make +sudo make install + +git clone https://github.com/stela2502/SCExV.git +cd SCExV/ +git checkout testing +cd SCExV/ +make +sudo make install + +## R +sudo apt-get install r-base r-base-html r-base-core libcurl4-openssl-dev libssl-dev libssh2-1-dev libx11-dev libglu1-mesa-dev libfreetype6-dev + + +## within R +install.packages(c('httr','git2r', 'devtools','Rcpp') ) + +source("http://bioconductor.org/biocLite.R") +biocLite("RDRToolbox") +biocLite("Biobase", 'BiocGenerics') + +library(devtools) +install_github('stela2502/RFclust.SGE') +install_github('RGLab/MAST') +install_github('stela2502/Rscexv') + +## python ZIFA +sudo apt-get install python-numpy python-matplotlib python-scipy scikits.learn + +cd SRC +git clone https://github.com/epierson9/ZIFA +cd ZIFA +sudo python setup.py install + + +## apache2 + +sudo apt-get install libapache2-mod-perl2 libcatalyst-engine-apache-perl apache2 libplack-perl + +## the web interface + +cpanm Plack + +cd SRC/SCexV/SCexV/ +sudo perl -I lib script/install.pl -install_path /var/www/html/SCexV/ -server_user www-data + +This will print a sample apache2 config file that you can adjust if necessary and put into the sites_eanables directory of your apache config. +! make sure that the mod_perl2 mod is loaded ! + +service restart apache2 + +You now can access the server under http://localhost/SCexV/ + + diff --git a/SCExV/.gitignore b/SCExV/.gitignore index a66ea59..734ef57 100644 --- a/SCExV/.gitignore +++ b/SCExV/.gitignore @@ -3,11 +3,27 @@ /t/data/Output/ /t/data/Outpath/ BugRreport_rgl* +/MANIFEST +/MYMETA.json +/MYMETA.yml +/Makefile +/.RData /BugReport_rgl.tar.gz +/Grouping.ABCG2.CBFA2T3 +/Grouping.AHR.CBFA2T3 +/Grouping.GeneB.GeneC2 +/Grouping.GeneB.GeneF +/Grouping.GeneC1.GeneC2 /HTpcrA-0.70.tar.gz /HTpcrA-0.80.tar.gz /HTpcrA-0.81.tar.gz /HTpcrA-0.90.tar.gz -/MANIFEST.bak +/INSTALL_Ubuntu_16.04.txt /Makefile.old -/Makefile +/MANIFEST.bak +/pm_to_blib +/rainbow_2.Rout +/rainbow_3.Rout +/rainbow_4.Rout +/rainbow_6.Rout +/RScript.Rout diff --git a/SCExV/BugReport_rgl/.gitignore b/SCExV/BugReport_rgl/.gitignore index 1de5dac..7fe3485 100644 --- a/SCExV/BugReport_rgl/.gitignore +++ b/SCExV/BugReport_rgl/.gitignore @@ -1,11 +1,4 @@ /.RData -/OrigDensityWebGL.html -/OrigDensityWebGL_mod.html -/OrigDensityWebGL_mod.html.log -/OrigPointsWebGL.html -/OrigPointsWebGL_mod.html -/OrigPointsWebGL_mod.html.log -/add_md5.pl /analysis.RData /create_3d_source_files.R /create_3d_source_files.Rout @@ -13,7 +6,13 @@ /difference_md5.txt /differences_md5_sums.txt /index.html -/rgl.js -/points.html /md5_Density.txt /md5_Points.txt +/OrigDensityWebGL.html +/OrigDensityWebGL_mod.html +/OrigDensityWebGL_mod.html.log +/OrigPointsWebGL.html +/OrigPointsWebGL_mod.html +/OrigPointsWebGL_mod.html.log +/points.html +/rgl.js diff --git a/SCExV/BugReport_rgl/add_md5.pl b/SCExV/BugReport_rgl/add_md5.pl new file mode 100755 index 0000000..458566e --- /dev/null +++ b/SCExV/BugReport_rgl/add_md5.pl @@ -0,0 +1,109 @@ +#! /usr/bin/perl -w + +# Copyright (C) 2016-01-12 Stefan Lang + +# This program is free software; you can redistribute it +# and/or modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; +# either version 3 of the License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, see'. join("",
Re-Grouping - delete grouing data file '$_'.
\n"); - @files = grep !/$_/, @files; - } - $self->index_form( $c, $path ); - - } - $c->stash->{'template'} = 'CustomGroupingsDoc.tt2'; -} sub samplenames : Local : Form { my ( $self, $c, @args ) = @_; @@ -102,13 +50,29 @@ sub samplenames : Local : Form { if ( $c->form->submitted && $c->form->validate ) { ## exclude some samples!! my $analysis_conf = $self->config_file( $c, 'rscript.Configs.txt' ); - $analysis_conf->{'UG'} = - $self->R_userGroups( $c, $self->__process_returned_form($c) ); - $self->config_file( $c, 'rscript.Configs.txt', $analysis_conf ); - unless ( ref( $c->stash->{'ERROR'} ) eq "ARRAY" ) { - $c->res->redirect( $c->uri_for("/analyse/re_run/") ); + my $dataset = $self->__process_returned_form($c); + + my $Rscript = + $c->model('RScript')->create_script( $c, 'userGroups', $dataset ); + $c->model('RScript') + ->runScript( $c, $path, "Grouping_" . $dataset->{'GroupingName'}, + $Rscript, 'wait' ); + + if ( -f $path . "Grouping_R_Error.txt" ) { + open( IN, "<$path" . "Grouping_R_Error.txt" ); + $c->stash->{'ERROR'} = [Here you can analyse your uploaded data using the options on the left side.
"; $self->update_form($c); if ( $c->form->submitted && $c->form->validate ) { - + warn "Button return value = ". $c->form->submitted."\n"; my $dataset = $self->__process_returned_form($c); $dataset->{'randomForest'} ||= 10; $self->config_file( $c, 'rscript.Configs.txt', $dataset ) @@ -428,7 +449,7 @@ sub index : Path : Form { ); } elsif ( $c->form->submitted() eq "0E0" ) - { ## remove samples based on the 2D MDS figure! + { ## this is when the RemoveSamples is pressed in 2D MDS view if ( $dataset->{'x1'} =~ m/\d+/ ) { $self->config_file( $c, 'rscript.Configs.txt', $dataset ); my $gg = $c->model('GeneGroups'); @@ -458,31 +479,20 @@ sub index : Path : Form { ); ## now I need to create a new R script!!! - my $script = - 'mark.mds <- read.table( file="' + my $script = $c->model('RScript')->create_script()."\n" + . $c->model('RScript')->_add_fileRead( $path ) + . 'mark.mds <- read.table( file="' . $path . '2D_data.xls' . '" )' . "\n"; - $script .= - "source ('libs/Tool_Plot.R')\n" - . "source ('libs/Tool_Pipe.R')\n" - . "load( 'norm_data.RData')\n"; $script .= $gg->export_R_exclude_samples('mark.mds') - . "data.filtered <- remove.samples( data.filtered, match(excludeSamples, rownames(data.filtered\$PCR) ) )\n" - . "data.filtered <- sd.filter(data.filtered)\n" + . "data <- remove.samples( data, match(excludeSamples, rownames(data\@data) ) )\n" + . "data <- sd.filter(data)\n" . "## write the new data\n" - . "save( data.filtered, file='norm_data.RData' )\n"; - unlink( $c->session_path() . "R.error" ) - if ( -f $c->session_path() . "R.error" ); - open( OUT, ">" . $self->path($c) . "ExcludeSamples.R" ) - or Carp::confess($!); - print OUT $script; - close(OUT); - chdir($path); - system( -'/bin/bash -c "DISPLAY=:7 R CMD BATCH --no-save --no-restore --no-readline -- ExcludeSamples.R"' - ); + . "save( data, file='analysis.RData' )\n"; + + $c->model('RScript')->runScript( $c, $path, "ExcludeSamples.R", $script ); $c->res->redirect( $c->uri_for("/analyse/re_run/") ); $c->detach(); @@ -500,6 +510,7 @@ sub index : Path : Form { } if ( -d $path . 'webGL' ) { my $path = $c->session_path(); + $self->update_form( $c ); if ( -f $path . "R.error" ) { open( IN, "<$path" . "R.error" ); $c->stash->{'message'} .= join( "","
diff --git a/SCExV/lib/HTpcrA/Model/PValues.pm b/SCExV/lib/HTpcrA/Model/PValues.pm
deleted file mode 100644
index 34df4e0..0000000
--- a/SCExV/lib/HTpcrA/Model/PValues.pm
+++ /dev/null
@@ -1,55 +0,0 @@
-package HTpcrA::Model::PValues;
-use Moose;
-use namespace::autoclean;
-
-extends 'Catalyst::Model';
-
-=head1 NAME
-
-HTpcrA::Model::PValues - Catalyst Model
-
-=head1 DESCRIPTION
-
-Catalyst Model.
-
-=head1 AUTHOR
-
-Stefan Lang
-
-=head1 LICENSE
-
-This library is free software. You can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-sub create_script {
- my ( $self, $c, $dataset ) = @_;
- my $path = $c->session->{'path'};
- unless ( -f $path . "/norm_data.RData" ) {
- $c->res->redirect( $c->uri_for("/files/upload/") );
- $c->detach();
- }
- $dataset->{'boot'} ||= 1000,
- $dataset->{'lin_lang_file'} ||= 'lin_lang_stats.xls';
- $dataset->{'sca_ofile'} ||= "Significant_genes.csv";
-# unless ( -f $path . "createPvalues.R" ) {
- my $script =
- "source('libs/Tool_PValues.R')\nload('analysis.RData')\n"
- . "stat_obj <- create_p_values( data, boot = $dataset->{'boot'}, "
- . "lin_lang_file= '$dataset->{'lin_lang_file'}', sca_ofile ='$dataset->{'sca_ofile'}' )\n"
- . "save( data, file='analysis.RData' )\n";
- open( OUT, ">" . $path . "createPvalues.R" ) or die "$!\n";
- print OUT $script;
- close(OUT);
-# }
- chdir($path);
- system(
-'/bin/bash -c "DISPLAY=:7 R CMD BATCH --no-save --no-restore --no-readline -- createPvalues.R >> R.run.log"'
- );
- return $dataset;
-}
-
-__PACKAGE__->meta->make_immutable;
-
-1;
diff --git a/SCExV/lib/HTpcrA/Model/RScript.pm b/SCExV/lib/HTpcrA/Model/RScript.pm
new file mode 100644
index 0000000..b846b6c
--- /dev/null
+++ b/SCExV/lib/HTpcrA/Model/RScript.pm
@@ -0,0 +1,504 @@
+package HTpcrA::Model::RScript;
+use Moose;
+use namespace::autoclean;
+use File::Copy "mv";
+
+extends 'Catalyst::Model';
+
+=head1 NAME
+
+HTpcrA::Model::RScript - Catalyst Model
+
+=head1 DESCRIPTION
+
+Catalyst Model.
+
+
+=encoding utf8
+
+=head1 AUTHOR
+
+Stefan Lang
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+=head2 create_script
+
+This function allows slimmer storage + call of Rscripts.
+
+options: ($path, $file, $script, $wait )
+
+=cut
+
+sub runScript {
+ my ( $self, $c, $path, $file, $script, $wait ) = @_;
+ unlink( $c->session_path() . "R.error" )
+ if ( -f $c->session_path() . "R.error" );
+ open( OUT, ">" . $path . $file ) or Carp::confess($!);
+ print OUT $script;
+ close(OUT);
+ $wait ||= '';
+ if ( $wait eq 'NoRun' ) {
+ return 1;
+ }
+ if ($wait) {
+ $wait = '';
+ }
+ else {
+ $wait = '&';
+ }
+ chdir($path);
+ system(
+'/bin/bash -c "DISPLAY=:7 R CMD BATCH --no-save --no-restore --no-readline -- '
+ . $file
+ . " $wait\"" );
+ return 1;
+}
+
+sub create_script {
+ my ( $self, $c, $function, $dataset ) = @_;
+ my $str = join( "\n",
+ "options(rgl.useNULL=TRUE)", "library(Rscexv)", "useGrouping<-NULL", );
+ if ( defined $function ) {
+ unless ( $self->can($function) ) {
+ Carp::confess(
+"Internal server error: R creation function '$function' not defined!\n"
+ );
+ }
+ $str .= "\n" . &{ \&{$function} }( $self, $c, $dataset );
+ }
+ return $str;
+}
+
+
+sub _add_fileRead {
+ my ( $self, $path ) = @_;
+ if ( -f $path . "analysis.RData" ) {
+ return "load('analysis.RData')\ndata.filtered <- data\n";
+ }
+ if ( -f $path . "norm_data.RData" ) {
+ return "load('norm_data.RData')\n";
+ }
+ return '## probably a problem : no file existst in path "' . $path . '"'
+ . "\n";
+}
+
+=head2 pValues
+
+Calulate all p values for the data
+
+=cut
+
+sub pValues {
+ my ( $self, $c, $dataset ) = @_;
+ my $path = $c->session->{'path'};
+
+ $dataset->{'boot'} ||= 1000,
+ $dataset->{'lin_lang_file'} ||= 'lin_lang_stats.xls';
+ $dataset->{'sca_ofile'} ||= "Significant_genes.csv";
+ my $script =
+ "load('analysis.RData')\n"
+ . "stat_obj <- create_p_values( data, boot = $dataset->{'boot'}, "
+ . "lin_lang_file= '$dataset->{'lin_lang_file'}', sca_ofile ='$dataset->{'sca_ofile'}' )\n"
+ . "saveObj( data, file='analysis.RData' )\n";
+ return $script;
+}
+
+
+=head2 geneGroup2D
+
+This creates th R script from the grouping_2d controller.
+This is dependant on the GeneGroups class that is provided in the dataset->{'gg'} object.
+
+=cut
+
+sub geneGroup2D {
+ my ( $self, $c, $dataset ) = @_;
+
+ my $script = $self-> _add_fileRead ( $c->session_path() );
+ $script .= $dataset->{'gg'}->export_R( 'data.filtered', $dataset->{'groupname'} );
+ $script .= "saveObj(data.filtered)\n";
+
+ return $script;
+}
+
+
+=head2 geneGroup1D_backend
+
+This R script creates all figures for the web frontend 1D gene grouping
+
+=cut
+
+sub geneGroup1D_backend {
+ my ( $self, $c, $dataset ) = @_;
+ my $script = $self->_add_fileRead( $dataset->{'path'} . "../" );
+
+ ## load the previousely defined cut regions
+ opendir( DIR, $dataset->{'path'} );
+ $script .=
+ "cuts <- list()\n"
+ . "files <- c( '"
+ . join( "', '",
+ map { $dataset->{'subpath'} . "/$_" } grep /.cut$/,
+ readdir(DIR) )
+ . "' )\n";
+ closedir(DIR);
+ $script .=
+ "library(stringr)\n"
+ . "for ( i in 1:length(files)){\n"
+ . " cuts[[i]] <-readLines( files[i] )\n" . "}\n"
+ . "names(cuts) <- str_replace_all( files, '.cut', '' )\n"
+ . "names(cuts) <- str_replace_all( names(cuts), '$dataset->{'subpath'}/', '' )\n";
+
+ ## plot all the expression as histogram
+ $script .=
+"plot.histograms ( data.filtered, cuts, subpath='$dataset->{'subpath'}' )\n";
+
+ $script .=
+ "## export all gene names for the web frontend\n"
+ . "n <- rownames(data.filtered\@data )\n"
+ . "if ( data.filtered\@wFACS ) {\n"
+ . " n <- c( n , colnames(data.filtered\@facs) )\n}\n"
+ . "write( n, file.path( data.filtered\@outpath, '$dataset->{'subpath'}', 'Genes.txt'), ncolumns=1 ) \n";
+ return $script;
+}
+
+=head2 geneGroup1D
+
+This creates a grouping script for a 1D gene group used in the analysis section!
+
+=cut
+
+sub geneGroup1D {
+ my ( $self, $c, $dataset ) = @_;
+
+ my @values = sort { $a <=> $b } split( /\s+/, $dataset->{'cutoff'} );
+ ## store these values for later??
+ open( OUT, ">" . $dataset->{'path'} . "$dataset->{GOI}.cut" );
+ print OUT join( "\n", @values );
+ close(OUT);
+ my $script =
+ $self->_add_fileRead( $dataset->{'path'} . "../" )
+ . "data <- group_1D (data.filtered, '$dataset->{'GOI'}', c("
+ . join( ", ", @values )
+ . " ) )\n"
+ . "saveObj( data )\n";
+ return $script;
+}
+
+=head2 remove_samples
+
+This function is called from the DropGenes contoller
+
+=cut
+
+sub remove_samples {
+ my ( $self, $c, $dataset ) = @_;
+ my $path = $c->session_path();
+ my $script = $self->_add_fileRead( $path );
+
+#Carp::confess ("These are the keys - do we have a 'Samples' one?: ". join(", ", keys %$dataset));
+ if ( defined @{ $dataset->{'Samples'} }[0] ) {
+ $script .=
+ "remS <- c ('"
+ . join( "', '", @{ $dataset->{'Samples'} } )
+ . "')\ndata.filtered = remove.samples(data.filtered, match( remS,rownames(data.filtered\@data)) )\n"
+ if ( @{ $dataset->{'Samples'} }[0] =~ m/[\w\d_]+/ );
+ }
+ if ( defined $dataset->{'RegExp'} ) {
+ $script .=
+"data.filtered = remove.samples(data.filtered, grep( \"$dataset->{'RegExp'}\" ,rownames(data.filtered\@data)) )\n"
+ if ( $dataset->{'RegExp'} =~ m/[\w\d_]+/ );
+ }
+
+ $script .=
+ "data.filtered <- sd.filter(data.filtered)\n"
+ . "data <- z.score.PCR.mad(data.filtered)\n"
+ . "save( data, file='analysis.RData' )\n";
+
+ return $script;
+}
+
+=head2 regroup
+
+Creates the script to re-order a grouping. Called by the Regroup controller.
+
+=cut
+
+sub regroup {
+ my ( $self, $c, $dataset ) = @_;
+
+ my $path = $c->session_path();
+ my $Rscript = $self->_add_fileRead($path);
+
+ my $data_table =
+ data_table->new( { 'filename' => $path . 'Sample_Colors.xls' } );
+ my ( $old_ids, $OK );
+ ## R dataset: group2sample = list ( '1' = c( 'Sample1', 'Sample2' ) )
+ $Rscript .= "userGroups <-regroup ( data.filtered, list (";
+ $OK = 0;
+ for ( my $i = 1 ; $i <= scalar( keys %$dataset ) ; $i++ )
+ { ## scale from 1 to n
+ next unless ( defined $dataset->{ 'g' . $i } );
+ $old_ids = { map { $_ => 1 } $dataset->{ 'g' . $i } =~ m/Group(\d+)/g };
+ next if ( keys %$old_ids == 0 );
+ $OK++;
+ $Rscript .= " \n\t'$i' = c('" . join(
+ "', '",
+ @{
+ $data_table->select_where(
+ 'grouping',
+ sub {
+ my $v = shift;
+ return 1 if ( $old_ids->{$v} );
+ return 0;
+ }
+ )->GetAsArray('SampleName')
+ }
+ ) . "'),";
+ }
+ if ( $OK < 2 ) {
+ $c->stash->{'ERROR'} = [
+'Sorry - you have not created enough groups! Min 2 groups are required!'
+ ];
+ }
+ chop($Rscript);
+ $Rscript .= " )\n, name='$dataset->{GroupingName}')\n"
+ . "saveObj(userGroups)\n";
+
+
+ return $Rscript;
+
+}
+
+=head2 userGroups
+
+Create a grouping based on user input pattern match. Called from the Regroups controller.
+=cut
+
+
+sub userGroups {
+ my ( $self, $c, $dataset ) = @_;
+ my $path = $c->session_path();
+
+ unlink( $path . "Grouping_R_Error.txt" )
+ if ( -f $path . "Grouping_R_Error.txt" );
+
+ my @groupsnames = split( /\s+/, $dataset->{'Group Names'} );
+ my $data_table =
+ data_table->new( { 'filename' => $path . 'Sample_Colors.xls' } );
+
+ my $Rscript = $self->_add_fileRead($path);
+
+ $Rscript .= "data.filtered <-group_on_strings ( data.filtered, c( '"
+ . join( "', '", @groupsnames )
+ . "' ) )\n" . "saveObj( data.filtered)\n";
+ return $Rscript;
+}
+
+=head2 fixPath
+
+This short R script fixes the path in an uploaded zip file R object!
+
+=cut
+sub fixPath {
+ my ( $self, $c, $dataset ) = @_;
+ my $path = $c->session_path();
+ my $script = $self->_add_fileRead($path);
+ $script .= "data\@outpath <- pwd()\n"
+ . "save( data, file='analysis.RData' )\n";
+ return $script;
+}
+
+=head2 remove_genes
+
+This function is called from the DropGenes contoller
+
+=cut
+
+sub remove_genes {
+ my ( $self, $c, $dataset ) = @_;
+ my $path = $c->session_path();
+ my $script = $self->_add_fileRead($path);
+
+ if ( defined @{ $dataset->{'Genes'} }[0] ) {
+ $script .=
+ "remS <- c ('"
+ . join( "', '", @{ $dataset->{'Genes'} } ) . "')\n"
+ . "kill <- match( remS,colnames(data.filtered\@data))\n"
+ . "data.filtered = remove.genes(data.filtered, kill[which(is.na(kill) == F )] )\n"
+ . "kill <- match( remS,colnames(data.filtered\@facs))\n"
+ . "data.filtered = remove.FACS.genes(data.filtered, kill[which(is.na(kill) == F )] )\n"
+ if ( @{ $dataset->{'Genes'} }[0] =~ m/[\w\d_]+/ );
+ }
+
+ $script .=
+ "data.filtered <- sd.filter(data.filtered)\n"
+ . "data <- z.score.PCR.mad(data.filtered)\n"
+ . "save( data, file='analysis.RData' )\n";
+ return $script;
+}
+
+=head2 densityPlot
+
+This script calculates the density 3D plot for the analysis page.
+
+=cut
+
+sub densityPlot {
+ my ( $self, $c, $dataset ) = @_;
+ my $path = $c->session_path();
+# my $script = $self->file_load($c, $dataset);
+ my $script = $self->_add_fileRead($path);
+ $script .= "library(ks)\n";
+ $script .= "plotDensity(data.filtered)\n";
+ return $script;
+}
+
+=head2 coexpression
+
+Creates the body of the coexpression script, that can be run without waiting for it.
+
+=cut
+
+sub coexpression {
+ my ( $self, $c, $dataset ) = @_;
+ my $path = $c->session_path();
+ return
+ $self->_add_fileRead($path)
+ . "t <- coexpressGenes(data)\n"
+ . "write.table(t,'Coexpression_4_Cytoscape.txt',row.names=F, sep=' ')\n";
+}
+
+=head2 RandomForest
+
+Creates the initial RFcluster script - no bells no whistles.
+
+=cut
+
+sub RandomForest {
+ my ( $self, $c, $dataset ) = @_;
+ my $path = $c->session_path();
+ return
+ $self->_add_fileRead($path)
+ . "data <- rfCluster(data,rep=1, SGE=F, email, k= $dataset->{'cluster_amount'},"
+ . " slice=4, subset=nrow(data\@data}-20, pics=F ,nforest=500, ntree=500, name='RFclust', recover=F)\n"
+ . "write.table(t,'Coexpression_4_Cytoscape.txt',row.names=F, sep=' ')\n"
+ ."save( data, file='analysis.RData' )\n";
+}
+
+=head2 analyze
+
+Creates the body of the analysis script.
+
+=cut
+
+sub analyze {
+ my ( $self, $c, $dataset ) = @_;
+ my $path = $c->session_path();
+ my $script =
+ $self->_add_fileRead($path);
+
+ if ( -f $path . "Gene_grouping.randomForest.txt" ) {
+ Carp::confess(
+ "RF Grouping is broken in the developmental version! FIXME!!!");
+ $script .=
+ "source ('libs/Tool_RandomForest.R')\n"
+ . "load('RandomForestdistRFobject_genes.RData')\n"
+ . "createGeneGroups_randomForest (data.filtered, $dataset->{'randomForest'})\n"
+ . "source ('Gene_grouping.randomForest.txt')\n";
+ }
+ if ( $dataset->{'UG'} eq "Group by plateID" ) {
+ $script .= "groups.n <- max( as.numeric(data.filtered\@samples[,'ArrayID']))\n"
+ . "useGrouping <- 'ArrayID'\n";
+ }
+ elsif( $dataset->{'UG'} eq "none" ) {
+ $script .= "groups.n <- $dataset->{'cluster_amount'}\n";
+ }
+ elsif ( $dataset->{'UG'} =~ m/\w/ ) { ## an expression based grouping!
+ $script .= "useGrouping <- '$dataset->{'UG'}'\n"
+ . "groups.n <- max( as.numeric(data.filtered\@samples[,useGrouping]))\n ";
+ }
+ else {
+ $script .= "groups.n <-$dataset->{'cluster_amount'}\n";
+ }
+ if ( $dataset->{'move_neg'} ) {
+ $script .= "move.neg <- TRUE\n";
+ }
+ else {
+ $script .= "move.neg <- FALSE\n";
+ }
+ if ( $dataset->{'plot_neg'} ) {
+ $script .= "plot.neg <- TRUE\n";
+ }
+ else {
+ $script .= "plot.neg <- FALSE\n";
+ }
+ if ( $dataset->{'use_beans'} ) {
+ $script .= "beanplots = TRUE\n";
+ }
+ else {
+ $script .= "beanplots = FALSE\n";
+ }
+ $script .=
+ "plotsvg = $dataset->{'plotsvg'}\n"
+ . "zscoredVioplot = $dataset->{'zscoredVioplot'}\n"
+ . "onwhat='$dataset->{'cluster_by'}'\n"
+ . "data <- analyse.data ( data.filtered, groups.n=groups.n, "
+ . "onwhat='$dataset->{'cluster_by'}', clusterby='$dataset->{'cluster_on'}', "
+ . "mds.type='$dataset->{'mds_alg'}', cmethod='$dataset->{'cluster_alg'}', LLEK='$dataset->{'K'}', "
+ . "ctype= '$dataset->{'cluster_type'}', zscoredVioplot = zscoredVioplot"
+ . ", move.neg = move.neg, plot.neg=plot.neg, beanplots=beanplots, plotsvg =plotsvg, useGrouping=useGrouping)\n"
+ . "\n"
+ . " save( data, file='analysis.RData' )\n"
+ . "write.table( cbind(data\@samples[,c(1,2)], 'grouping' = data\@usedObj[['clusters']], colors=data\@usedObj[['colors']]),
+ file='Sample_Colors.xls' , row.names=F, sep='\\t',quote=F )\n";
+
+ unlink("$path/Summary_Stat_Outfile.xls")
+ if ( -f "$path/Summary_Stat_Outfile.xls" );
+ return $script;
+}
+
+=header2
+file_load will create the script used for the file upload.
+=cut
+
+sub file_load {
+ my ( $self, $c, $dataset ) = @_;
+ my $seesion_hash = $c->session();
+ my $path = $c->session_path();
+ if ( -f $path."/analysis.RData" ){
+ mv( $path."/analysis.RData" ,$path."/analysis.old.RData" );
+ }
+ my $script = "negContrGenes <- NULL\n";
+ $script .=
+ "negContrGenes <- c ( '"
+ . join( "', '", @{ $dataset->{'negControllGenes'} } ) . "')\n"
+ if ( defined @{ $dataset->{'negControllGenes'} }[0] and ! @{ $dataset->{'negControllGenes'} }[0] eq "linux" );
+ $dataset->{'controlM'} ||=[];
+ $script .= "data.filtered <- createDataObj ( PCR= c( "
+ . join( ", ",
+ map { "'$_->{'filename'}'" } @{ $seesion_hash->{'PCRTable'} } )
+ . " ), "
+ . "FACS= c( "
+ . join( ", ",
+ map { "'$_->{'filename'}'" } @{ $seesion_hash->{'facsTable'} } )
+ . " ), "
+ . "ref.genes= c( '"
+ . join( "', '", @{ $dataset->{'controlM'} } ) . "' ),"
+ . " use_pass_fail = '$dataset->{'use_pass_fail'}', "
+ . "max.value=40, max.ct= $dataset->{'maxCT'} , max.control=$dataset->{'maxGenes'}, "
+ . "norm.function='$dataset->{'normalize2'}', negContrGenes=negContrGenes )\n"
+ . "save( data.filtered, file=file.path(data.filtered\@outpath,'norm_data.RData') )\n";
+ $script =~ s/c\( '.?.?\/?' \)/NULL/g;
+ return $script;
+}
+
+__PACKAGE__->meta->make_immutable;
+
+1;
diff --git a/SCExV/lib/HTpcrA/Model/java_splicer.pm b/SCExV/lib/HTpcrA/Model/java_splicer.pm
index 6be1369..9867702 100644
--- a/SCExV/lib/HTpcrA/Model/java_splicer.pm
+++ b/SCExV/lib/HTpcrA/Model/java_splicer.pm
@@ -68,6 +68,30 @@ sub java_splice_old {
return { functions => \@functions, md5sums=> \@md5sums, rest =>join("\n",@$all) } ; ## the last entry is the plot script
}
+sub classSplitter {
+ my ( $self, $str ) = @_;
+ my (@return, $use, $position);
+ $position = -1;
+ if ( -f $str ) {
+ open ( IN, "<$str" ) or die $!;
+ $str = join("\n",