********************************************************************************	
		INSTALLER UNE INSTANCE GALAXY / Linux
********************************************************************************
1-  De préférence en local sur son ordinateur. Choisir un répertoire de travail.

2- Sinon:
ssh -XY violette
violette@genotoul1 ~ $ cd /work/violette/

Depuis Google : Galaxy Project / Get Galaxy / install locally

violette@genotoul1 /work/coquelicot $ git clone https://github.com/galaxyproject/galaxy/
Initialized empty Git repository in /work/coquelicot/galaxy/.git/
remote: Counting objects: 196402, done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 196402 (delta 2), reused 0 (delta 0), pack-reused 196391
Receiving objects: 100% (196402/196402), 68.88 MiB | 4.51 MiB/s, done.
Resolving deltas: 100% (155679/155679), done.

Explorer le contenu du répertoire galaxy/ :

violette@genotoul1 /work/violette $ ls
galaxy
violette@genotoul1 /work/violette $ ls galaxy/
CITATION            display_applications      openid              static
client              doc                       README.rst          templates
CODE_OF_CONDUCT.md  external_service_types    requirements.txt    test
config              extract_dataset_parts.sh  rolling_restart.sh  test-data
contrib             lib                       run_reports.sh      tool-data
CONTRIBUTING.md     LICENSE.txt               run.sh              tool_list.py
CONTRIBUTORS.md     locale                    run_tests.sh        tools
create_db.sh        Makefile                  run_tool_shed.sh    tox.ini
cron                manage_db.sh              scripts
database            manage_tools.sh           setup.cfg


Ne surtout pas lancer en frontal le run en frontal !!! (ne pas lancer le sh run.sh)
Votre formateur prend le relais sur une machine de tests.


Pour celles/ceux qui le souhaitent, faire les mêmes manips en local sur votre ordinateur (comme je ne connais pas les configurations de vos PC .. le support sera limité).
Installation en local sur PC : installs, tests et run en local sur PC

* Chemin d'accès au code Galaxy:
[Sarah@localhost LOCAL_TESTS]$ pwd
/home/Sarah/Documents/GALAXY/MASTER_2_BIOINFO/COURS/LOCAL_TESTS

* Installation du code Galaxy:
[Sarah@localhost LOCAL_TESTS]$ git clone https://github.com/galaxyproject/galaxy/
Clonage dans 'galaxy'...
remote: Counting objects: 245878, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 245878 (delta 0), reused 0 (delta 0), pack-reused 245876
Réception d'objets: 100% (245878/245878), 160.18 MiB | 1.43 MiB/s, fait.
Résolution des deltas: 100% (195225/195225), fait.
Vérification de la connectivité... fait.

Remarque importante :
Premier lancement de galaxy :  sh run.sh
Pour les restarts suivants (afin de ne pas recréer une base de données), pas de sh run.sh mais ./rolling_restart.sh

********************************************************************************
		Explorer les répertoire et les fichiers
********************************************************************************

Merci d'identifier les principaux répertoire et fichiers utiles :


PRINCIPAUX REPERTOIRES :
[galaxy-preprod@vm-galaxy-preprod galaxy-preprod]$ ls
clean.sh            galaxy         logs    my_config        my_files                  my_tmp        my_tools           my_workspace  python-src  TOTO
example_wrapper.pl  GalaxyPath.pm  my_bin  my_dependencies  my_job_working_directory  my_tool-data  my_visualizations  pbs           shed_tools  venv.tgz


LES FICHIERS DE CONFIGURATION :
[galaxy-preprod@vm-galaxy-preprod galaxy-preprod]$ ls my_config
auth_conf.xml                           galaxy.ini                           local_env.sh                    sanitize_whitelist.txt                tool_conf.xml.main
auth_conf.xml.sample                    galaxy.ini.sample                    migrated_tools_conf.xml         shed_data_manager_conf.xml            tool_conf.xml.sample
data_manager_conf.xml.sample            integrated_tool_panel.xml            migrated_tools_conf.xml.sample  shed_data_manager_conf.xml.sample     tool_data_table_conf.xml
datatypes_conf.xml                      job_conf.xml                         my_tool_conf.xml                shed_tool_conf.xml                    tool_data_table_conf.xml.sample
datatypes_conf.xml.sample               job_conf.xml.sample_advanced         object_store_conf.xml.sample    shed_tool_conf.xml.sample             tool_shed.ini.sample
dependency_resolvers_conf.xml.sample    job_conf.xml.sample_basic            openid_conf.xml.sample          shed_tool_data_table_conf.xml         tool_sheds_conf.xml
disposable_email_blacklist.conf.sample  job_metrics_conf.xml.sample          plugins                         shed_tool_data_table_conf.xml.sample  tool_sheds_conf.xml.sample
external_service_types_conf.xml.sample  job_resource_params_conf.xml.sample  reports.ini.sample              tool_conf.xml                         workflow_schedulers_conf.xml.sample

LES FICHIERS DE LOC:
[galaxy-preprod@vm-galaxy-preprod galaxy-preprod]$ ls my_tool-data
16S_db.loc                            builds.txt                    funDo.loc                      mirdeep2_indexes.loc         regions.loc                      snpeffv_genomedb.loc
add_scores.loc                        bwa_index.loc                 funDo.loc.sample               mosaik_index.loc             regions.loc.sample               snpeffv_genomedb.loc.sample
add_scores.loc.sample                 bwa_index.loc.sample          gatk2_annotations.txt          mosaik_index.loc.sample      rsem_indices.loc                 snpeffv_regulationdb.loc
alignseq.loc                          bwa_mem_indexes.loc           gatk2_picard_indexes.loc       mothur_aligndb.loc           rsem_indices.loc.sample          snpeffv_regulationdb.loc.sample
alignseq.loc.sample                   bwa_mem_index.loc             gatk2_picard_index.loc         mothur_lookup.loc            sam_fa_indexes.loc               snpsift_dbnsfp.loc
all_fasta.loc                         bwa_mirdeep2_index.loc        gatk3_sorted_picard_index.loc  mothur_map.loc               sam_fa_indices.loc               snpsift_dbnsfp.loc.sample
all_fasta.loc.sample                  codingSnps.loc                gatk_annotations.txt           mothur_taxonomy.loc          sequence_index_base.loc          snpsift_dbnsfps.loc
annotation_profiler_options.xml       codingSnps.loc.sample         gatk_picard_indexes.loc        ngs_sim_fasta.loc            sequence_index_base.loc.sample   snpsift_dbnsfps.loc.sample

LES TOOLS:
[galaxy-preprod@vm-galaxy-preprod galaxy-preprod]$ ls my_tools
bcftools_view         egnpp          gatk_3             R_ACP_CATIBIOSDBIOL  sm_bam2bai4igv     sm_fasta_manip            sm_mapping_from_bam   sm_RNAseq                sm_TEST             sr_cat_fastas
bed_intersect         fasta_tools    gatk3_toolshed_US  rgenetics            sm_bam2bamsorted   sm_FASTQ_qual             sm_merge_cols         sm_RPY2TOOLS_tests       sm_upload           sr_fosmides
bwa_0_7_10            fastq          in_vcf_sort        samtools             sm_blastall        sm_flash                  sm_mirdeep2           sm_samtools_faidx        sm_upload_work      sr_mapping
contra_2.0.8          fastx_toolkit  my_test.xml        sartools_1_1_0       sm_bowtie_build    sm_FOSMIDES               sm_miRNA_annotations  sm_save_on_user_workTMP  sm_work             stacks
coverage_statistics   fml_gff3togtf  new_operations     sequenza             sm_cluster         sm_GFF2GTF                sm_miRNA_qual         sm_sed                   sm_zip              trim_galore
deseq_and_sam2counts  Frogs          -p                 shrnaseq             sm_compress        sm_GFF2GTF.pl             sm_niks               sm_sgs                   snpeff_3.4          vcf_tools
discosnp_plus_plus    FROGS          picard             sickle_migale        sm_compute_GC      sm_GFF2GTF.xml            sm_phylofish          sm_SNP_calling           snpeff_4.1_nlapalu
dlas_qstat            FROGS_nolink   picrust_galaxy     sm_annotation_SNP    sm_compute_length  sm_gtf_to_gff             sm_qquota             sm_split                 snpeff_compile
edger                 gatk2          presartools        sm_archive           sm_dos2unix        sm_indexation_genome_ref  sm_RepeatMasker       sm_STAR                  sr_apollo


Merci d'expliquer rapidement au tableau (qui se lance), les fichiers suivants:
galaxy.ini
job_conf.xml
datatypes_conf.xml
tool_conf.xml
bwa_index.loc
et le répertoire tools/

* Visualisation des fichiers:
[Sarah@localhost LOCAL_TESTS]$ ls
galaxy
[Sarah@localhost LOCAL_TESTS]$ ls galaxy/
CITATION            contrib          cron                  external_service_types    locale           openid              run_reports.sh    scripts    test          tools
client              CONTRIBUTING.md  database              extract_dataset_parts.sh  Makefile         README.rst          run.sh            setup.cfg  test-data     tox.ini
CODE_OF_CONDUCT.md  CONTRIBUTORS.md  display_applications  lib                       manage_db.sh     requirements.txt    run_tests.sh      static     tool-data
config              create_db.sh     doc                   LICENSE.txt               manage_tools.sh  rolling_restart.sh  run_tool_shed.sh  templates  tool_list.py

* Création du galaxy.ini
[Sarah@localhost LOCAL_TESTS]$ cp galaxy/config/galaxy.ini.sample galaxy/config/galaxy.ini

* Paramétrage de son galaxy.ini:
[Sarah@localhost LOCAL_TESTS]$ geany galaxy/config/galaxy.ini &

Décommenter le port et l'host:
# The port on which to listen.
#port = 8080

# The address on which to listen.  By default, only listen to localhost (Galaxy
# will not be accessible over the network).  Use '0.0.0.0' to listen on all
# available network interfaces.
#host = 127.0.0.1

Depuis votre interface web Galaxy, créer vous un compte avec REGISTER.
Compléter galaxy.ini pour être admin de votre machine en renseignant le mail de votre compte Galaxy nouvellement créé.

* Lancer Galaxy:
[Sarah@localhost galaxy]$ ls
[Sarah@localhost galaxy]$ sh run.sh
Initializing config/migrated_tools_conf.xml from migrated_tools_conf.xml.sample
Initializing config/shed_tool_conf.xml from shed_tool_conf.xml.sample
Initializing config/shed_tool_data_table_conf.xml from shed_tool_data_table_conf.xml.sample
Initializing config/shed_data_manager_conf.xml from shed_data_manager_conf.xml.sample
Initializing tool-data/shared/ucsc/builds.txt from builds.txt.sample
Initializing tool-data/shared/ucsc/manual_builds.txt from manual_builds.txt.sample
Initializing tool-data/shared/ucsc/ucsc_build_sites.txt from ucsc_build_sites.txt.sample
Initializing tool-data/shared/igv/igv_build_sites.txt from igv_build_sites.txt.sample
Initializing tool-data/shared/rviewer/rviewer_build_sites.txt from rviewer_build_sites.txt.sample
Initializing static/welcome.html from welcome.html.sample
Fetching https://pypi.python.org/packages/source/v/virtualenv/virtualenv-13.1.2.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 1679k  100 1679k    0     0   641k      0  0:00:02  0:00:02 --:--:--  641k
Verifying /tmp/galaxy-virtualenv-MPVzTy/virtualenv-13.1.2.tar.gz checksum is aabc8ef18cddbd8a2a9c7f92bc43e2fea54b1147330d65db920ef3ce9812e3dc
New python executable in .venv/bin/python
Installing setuptools, pip, wheel...done.
Activating virtualenv at .venv
Collecting pip>=8.1
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 374kB/s 

.....


Starting server in PID 4330.
serving on http://127.0.0.1:8080

* Cliquer sur l'http fournit pour visualiser votre instance locale de Galaxy.

* Attention, pour les autres restarts, afin de ne pas recréer une base de données, veuillez ne pas utiliser sh run.sh mais ./rolling_restart.sh &


********************************************************************************
    Ajout du tool  "%GC content" dans votre instance locale / ou compte fleur
********************************************************************************

Récupérer le code du wrapper%GC content
Source des infos:
https://wiki.galaxyproject.org/Admin/Tools/AddToolTutorial


1. Write and test your tool outside Galaxy:

Suppose one has written a simple Perl script (called toolExample.pl) for computing the GC content of a sequence in the FASTA format, which looks like this:

    #!/usr/bin/perl -w
    
    # usage : perl toolExample.pl <FASTA file> <output file>
    
    open (IN, "<$ARGV[0]");
    open (OUT, ">$ARGV[1]");
    while (<IN>) {
        chop;
        if (m/^>/) {
           s/^>//;
           if ($. > 1) {
               print OUT sprintf("%.3f", $gc/$length) . "\n";
           }
           $gc = 0;
           $length = 0;
       } else {
           ++$gc while m/[gc]/ig;
           $length += length $_;
       }
   }
   print OUT sprintf("%.3f", $gc/$length) . "\n";
   close( IN );
   close( OUT );

To integrate this tool into Galaxy we will follow these steps:

2. Put tool into Galaxy's tools directory:

To begin the tool integration process we need to add our Perl script to the tools/ directory, where all tool-related files are stored. In this example we will create a new subdirectory called myTools within tools/. So cd to your Galaxy installation and type these commands:

   1 cd tools
   2 mkdir myTools
   3 cd myTools

Now one needs to copy the script (in this case toolExample.pl) into the tools/myTools/ directory.

3. Create Tool Definition File:

At this point toolExample.pl resides within the tools/myTools/ directory, but Galaxy still does not know how to run this tool. To let Galaxy know the execution details of our new tool, we need to write a tool configuration file, which, in this case, will be called toolExample.xml. For this particular example open a text editor of your choice and create the toolExample.xml file within the tools/myTools directory. This file looks like this:

    <tool id="fa_gc_content_1" name="Compute GC content" version="0.1.0">
      <description>for each sequence in a file</description>
      <command interpreter="perl">toolExample.pl $input $output</command>
      <inputs>
        <param format="fasta" name="input" type="data" label="Source file"/>
      </inputs>
      <outputs>
        <data format="tabular" name="output" />
      </outputs>
   
     <tests>
       <test>
         <param name="input" value="fa_gc_content_input.fa"/>
         <output name="out_file1" file="fa_gc_content_output.txt"/>
       </test>
     </tests>
   
     <help>
   This tool computes GC content from a FASTA file.
     </help>
   
   </tool>

Note how this file specifies command line parameters, links them to input and output, and provides help information using the restructured text format. Once you are done, the tools/myTools directory will contain two files toolExample.pl and toolExample.xml. For basic and general tool definition file please see Example Tool Definiton File. Once you feel comfortable with the basics you can browse through the full tool definition syntax.

4. Make Galaxy aware of the new tool:

REMARQUE : cp tool_conf.xml.sample tool_conf.xml !!

Now the tool and its configuration file are ready. The final step makes Galaxy aware of the new tools. Galaxy knows about installed tools (and also what to display on the left pane) from the tool_conf.xml tool-registry file. Thus, letting Galaxy know about our new tool is as easy as adding these lines to the tool_conf.xml file located in the config directory of the Galaxy distribution:

     <section name="MyTools" id="mTools">
        <tool file="myTools/toolExample.xml" />
     </section>

5. Start it up:

At this point, start Galaxy by typing sh rolling_restart.sh from within Galaxy's root directory and point your browser to http://localhost:8080.



********************************************************************************
                Tester  tool%GC content
********************************************************************************

1 - Tester %GC content via l'interface web Galaxy avec un fasta contenant une
séquence puis avec un fasta contenant plusieurs séquences.
Des données de tests sont disponibles depuis : http://genoweb.toulouse.inra.fr/~sigenae/Galaxy_Formation/test-data/

2 - Tester le wrapper en ligne de commande depuis votre terminal dans
/tools/MyTools/ : perl %GC.pl args
POur savoir comment est lançée cette ligne de commande perl, n'hésitez pas à vous reporter au tag <command> de votre xml.

3- Ajouter des print STDOUT dans %GC.pl; lancer l'outil dans Galaxy; observer
le contenu du stdout depuis l'icône i de votre dataset. Dans cet stdout, vous pouvez ajouter la version de vos outils bioinformatiques ou les étapes de traitement, à destination des biologistes.

4- Regarder le contenu de votre fichier galaxy/database/ 



********************************************************************************
                       Le fameux pont R
********************************************************************************
    Rbin path
    $r_bin = '/usr/local/bioinfo/src/R/current/bin/R';
    #Log dir
    $log_dir = $working_dir;

#déaration de l'objet $R et ouverture du pont :
$R = Statistics::R->new(
"r_bin" => $r_bin,
"log_dir" => $log_dir,
) or die "Problem with R : $!\n";

    Ouverture du pont
    $R->startR;

#envoi du repertoire de travail
$R->send(
qq`
setwd("$working_dir")
`);

#Read R script
$cmd="";
open IN,"< $script_dir/Graphics_desc.R"
or die "Unable to read R script : $!\n";
while ($line=<IN>) {
$cmd.=$line;
}
close(IN);

#Declare R function
$R->send($cmd);


