changeset 22:1714165f5df0 draft

Uploaded
author charles-bernard
date Thu, 27 Oct 2016 04:42:59 -0400
parents 728294cecd96
children c7279df3f7ba
files ALFA/ALFA_wrapper.py ALFA/alfa_wrapper.sh ALFA/alfa_wrapper.xml ALFA/tool-data/alfa_genomes_indexes.loc.sample ALFA/tool-data/alfa_indexes.loc.sample ALFA/tool-data/alfa_indexes.loc.sample~ ALFA/tool_data_table_conf.xml.sample ALFA/tool_data_table_conf.xml.sample~
diffstat 8 files changed, 311 insertions(+), 337 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ALFA/ALFA_wrapper.py	Thu Oct 27 04:42:59 2016 -0400
@@ -0,0 +1,194 @@
+#!/usr/bin/python
+
+import argparse
+import logging
+import os
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+
+def exit_and_explain(msg):
+    logging.critical(msg)
+    sys.exit(msg)
+
+def cleanup_before_exit(tmp_dir):
+    if tmp_dir and os.path.exists(tmp_dir):
+        shutil.rmtree(tmp_dir)
+
+def get_arg():
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--project_name', dest='project_name', action='store', nargs=1, metavar='project_name', type=str)
+    #Input 1: Annotation File
+    parser.add_argument('--index', dest='indexes', action='store', nargs=2, metavar=('stranded_index_filename', 'unstranded_index_filename'), type=str)
+    parser.add_argument('--bi_index', dest='bi_indexes', action='store', nargs=1, metavar='built_in_indexes_dir_path', type=str )
+    parser.add_argument('--annotation', dest='annotation_file', action='store', nargs=1, metavar='annotation_gtf_file', type=str )
+    #Input 2: Mapped Reads
+    parser.add_argument('--reads_format', dest='reads_format', action='store', nargs=1, choices=['bam', 'bedgraph'], metavar='reads_format', type=str)
+    parser.add_argument('--reads', dest='reads', action='store', nargs='+', metavar=('bam_file1 label1',""), type=str)
+    parser.add_argument('--strandness', dest='strandness', action='store', nargs=1, default=['unstranded'], choices=['unstranded', 'forward', 'reverse'], metavar='strandness', type=str)
+    #Output files
+    parser.add_argument('--output_pdf', dest='output_pdf', action='store', nargs=1, metavar='output_pdf_filename', type=str)
+    parser.add_argument('--output_svg', dest='output_svg', action='store', nargs=2, metavar=('categories_svg_filename', 'biotypes_svg_filename'), type=str)
+    parser.add_argument('--output_png', dest='output_png', action='store', nargs=2, metavar=('categories_png_filename', 'biotypes_png_filename'), type=str)
+    parser.add_argument('--output_count', dest='output_count', action='store', nargs=1, metavar='output_count_filename', type=str)
+    parser.add_argument('--output_index', dest='output_indexes', action='store', nargs=2, metavar=('output_stranded_index_filename', 'output_unstranded_index_filename'), type=str)
+    #Output Options
+    parser.add_argument('--categories_depth', dest='categories_depth', action='store', nargs=1, default=[3], choices=range(1,5), metavar='categories_depth', type=int)
+    parser.add_argument('--plot_format', dest='plot_format', action='store', nargs=1, choices=['pdf', 'png', 'svg'], metavar='plot_format', type=str)
+    parser.add_argument('--threshold', dest='threshold', action='store', nargs=2, metavar=('yMin', 'yMax'), type=float)
+    #Internal variables
+    parser.add_argument('--log_report', dest='log_report', action='store', nargs=1, metavar='log_filename', type=str)
+    parser.add_argument('--galaxy_root', dest='GALAXY_ROOT_DIR', action='store', nargs=1, metavar='galaxy_root_path', type=str)
+    parser.add_argument('--tool_dir', dest='GALAXY_TOOL_DIR', action='store', nargs=1, metavar='galaxy_tool_dir_path', type=str)
+    args = parser.parse_args()
+    return args
+
+def make_tmp_dir(galaxy_root):
+    parent_dir = os.path.join(galaxy_root, 'database/tmp/')
+    if os.path.exists(parent_dir):
+        tmp_dir = tempfile.mkdtemp(prefix='tmp', suffix='', dir=parent_dir)
+    else:
+        tmp_dir = tempfile.mkdtemp(prefix='tmp', suffix='', dir='.')
+    return tmp_dir
+
+def mv_and_rename_user_indexes(stranded_index, unstranded_index):
+    index='index'
+    shutil.copy(stranded_index, index + '.stranded.index')
+    shutil.copy(unstranded_index, index + '.unstranded.index')
+    return index
+
+def get_input2_args(reads_list, format):
+    n = len(reads_list)
+    if n%2 != 0:
+        exit_and_explain('Problem with pairing reads filename and reads label')
+    input2_args='-i'
+    k = 0
+    reads_filenames = [''] * (n/2)
+    reads_labels = [''] * (n/2)
+    for i in range(0, n, 2):
+        reads_filenames[k] = reads_list[i].split('__fname__')[1]
+        reads_labels[k] = reads_list[i+1].split('__label__')[1]
+        if not reads_labels[k]:
+            reads_labels[k] = 'sample_%s' % str(k+1)
+        input2_args='%s %s %s' % (input2_args, reads_filenames[k], reads_labels[k])
+        k += 1
+    if format == 'bedgraph':
+        input2_args = input2_args + ' --bedgraph'
+    return input2_args, reads_filenames, reads_labels
+
+def redirect_errors(alfa_out, alfa_err):
+    # When the option --n is enabled, alfa prints '### End of the program' in stderr even if the process worked-
+    # The following lines to avoid the tool from crashing in this case
+    if alfa_err and not re.search('### End of program', alfa_err):
+        # When alfa prints '### End of program' in stdout, all the messages in stderr are considered
+        # as warnings and not as errors.
+        if re.search('### End of program', alfa_out):
+            logging.warning("The script ALFA.py encountered the following warning:\n\n%s" % alfa_err)
+            logging.info("\n******************************************************************\n")
+        # True errors make the script exits
+        else:
+            exit_and_explain("The script ALFA.py encountered the following error:\n\n%s" % alfa_err)
+
+def merge_count_files(reads_labels):
+    merged_count_file = open('count_file.txt', 'wb')
+    for i in range(0, len(reads_labels)):
+        current_count_file = open(reads_labels[i] + '.categories_counts', 'r')
+        reads_label = reads_labels[i]
+        merged_count_file.write('##LABEL: %s\n\n' % reads_label)
+        merged_count_file.write(current_count_file.read())
+        merged_count_file.write('__________________________________________________________________\n')
+        current_count_file.close()
+    merged_count_file.close()
+    return 'count_file.txt'
+
+def main():
+    args = get_arg()
+
+    if not (args.output_pdf or args.output_png or args.output_svg or args.output_indexes or args.output_count):
+        exit_and_explain('Error: no output to return\nProcess Aborted\n')
+
+    tmp_dir = make_tmp_dir(args.GALAXY_TOOL_DIR[0])
+    os.chdir(tmp_dir)
+
+    logging.basicConfig(level=logging.INFO, filename=args.log_report[0], filemode="a+", format='%(message)s')
+
+    alfa_path = os.path.join(args.GALAXY_TOOL_DIR[0], 'ALFA.py')
+
+    #INPUT1: Annotation File
+    if args.indexes:
+        # The indexes submitted by the user must exhibit the suffix '.(un)stranded.index' and will be called by alfa by their prefix
+        index = mv_and_rename_user_indexes(args.indexes[0], args.indexes[1])
+        input1_args = '-g %s' % index
+    elif args.bi_indexes:
+        input1_args = '-g %s' % args.bi_indexes[0]
+    elif args.annotation_file:
+        input1_args = '-a %s' % args.annotation_file[0]
+    else:
+        exit_and_explain('No annotation file submitted !')
+
+    #INPUT 2: Mapped Reads
+    if args.reads:
+        input2_args, reads_filenames, reads_labels = get_input2_args(args.reads, args.reads_format[0])
+        strandness = '-s %s' % args.strandness[0]
+    else:
+        exit_and_explain('No reads submitted !')
+
+    ##Output options
+    categories_depth = '-d %s' % args.categories_depth[0]
+    if not (args.output_pdf or args.output_png or args.output_svg):
+        output_args = '--n'
+    else:
+        if args.output_pdf:
+            output_args = '--pdf plot.pdf'
+        if args.output_png:
+            output_args = '--png plot'
+        if args.output_svg:
+            output_args = '--svg plot'
+        if args.threshold:
+            output_args = '%s -t %.3f %.3f' % (output_args, args.threshold[0], args.threshold[1])
+
+    ##Run alfa
+    cmd = 'python %s %s %s %s %s %s' % (alfa_path, input1_args, input2_args, strandness, categories_depth, output_args)
+    logging.info("__________________________________________________________________\n")
+    logging.info("Alfa execution")
+    logging.info("__________________________________________________________________\n")
+    logging.info("Command Line:\n%s\n" % cmd)
+    logging.info("------------------------------------------------------------------\n")
+    alfa_result = subprocess.Popen(args=cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    alfa_out, alfa_err =  alfa_result.communicate()
+
+    ##Handle stdout, warning, errors...
+    redirect_errors(alfa_out, alfa_err)
+
+    logging.info("Alfa prompt:\n%s" % alfa_out)
+
+    ##Redirect outputs
+    if args.output_pdf:
+        shutil.move('plot.pdf', args.output_pdf[0])
+    if args.output_png:
+        shutil.move('plot' + '.categories.png', args.output_png[0])
+        shutil.move('plot' + '.biotypes.png', args.output_png[1])
+    if args.output_svg:
+        shutil.move('plot' + '.categories.svg', args.output_svg[0])
+        shutil.move('plot' + '.biotypes.svg', args.output_svg[1])
+    if args.output_count:
+        count_filename = merge_count_files(reads_labels)
+        shutil.move(count_filename, args.output_count[0])
+    if args.output_indexes:
+        if args.annotation_file:
+            indexes_regex = re.compile('.*\.index')
+            indexes = filter(indexes_regex.search, os.listdir('.'))
+            indexes.sort()
+            shutil.move(indexes[0], args.output_indexes[0])
+            shutil.move(indexes[1], args.output_indexes[1])
+        if args.indexes:
+            shutil.move(index + '.stranded.index', args.output_indexes[0])
+            shutil.move(index + '.unstranded.index', args.output_indexes[1])
+        if args.bi_indexes:
+            shutil.move(args.bi_indexes[0] + '.stranded.index', args.output_index[0])
+            shutil.move(args.bi_indexes[1] + '.unstranded.index', args.output_index[1])
+
+    cleanup_before_exit(tmp_dir)
+main()
\ No newline at end of file
--- a/ALFA/alfa_wrapper.sh	Tue Oct 11 11:10:18 2016 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,235 +0,0 @@
-#!usr/bin/bash 
-
-#########################################################################################################
-# ARGUMENTS FROM alfa_wrapper.xml                                                                       #
-#########################################################################################################
-galaxyRoot=$1;
-toolDir=$2
-configFile=$3;
-logReport=$4;
-sed -i -e '/^$/d; s/\t//g;' $configFile;
-printf "__________________________________________________________________\n\n" > $logReport
-printf "                          ALFA CONFIG                             \n" >> $logReport
-printf "__________________________________________________________________\n" >> $logReport
-cat $configFile >> $logReport
-
-#########################################################################################################
-# INITIALIZATION OF THE VARIABLES from $configFile                                                      #
-#########################################################################################################
-#_INPUT1
-annotationSource=`grep -P '^annotationSource ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-if [ "$annotationSource" == "personal_gtf" ]; then
-	annotationFile=`grep -P '^annotationFile ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-elif [ "$annotationSource" == "built_in_index" ]; then
-	built_in_index_prefix=`grep -P '^built_in_index_prefix ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-else
-	strandedIndex=`grep -P '^strandedIndex ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-	unstrandedIndex=`grep -P '^unstrandedIndex ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-fi
-
-#_INPUT2
-readsType=`grep -P '^readsType ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-readsFileList=`grep -P '^readsFile\[[0-9]+\] ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-readsLabelList=`grep -P '^readsLabel\[[0-9]+\] ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-
-#_OUTPUT CHOICES
-plotChoice=`grep -P '^plotChoice ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-countFileChoice=`grep -P '^countFileChoice ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-indexChoice=`grep -P '^indexChoice ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-
-#_OUTPUT OPTIONS
-strandness=`grep -P '^strandness ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-categoriesDepth=`grep -P '^categoriesDepth ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-plotFormat=`grep -P '^plotFormat ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-plotThresholdChoice=`grep -P '^plotThresholdChoice ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-if [ "$plotThresholdChoice" == "True" ]; then
-	yMin=`grep -P '^yMin ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
- 	yMax=`grep -P '^yMax ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-fi
-
-#_OUTPUT FILES
-if [ "$plotChoice" == "True" ]; then 
-	if [ "$plotFormat" == "pdf" ]; then
-		outputPdf=`grep -P '^outputPdf ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-	elif [ "$plotFormat" == "svg" ]; then
-		outputCategoriesSvg=`grep -P '^outputCategoriesSvg ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-		outputBiotypesSvg=`grep -P '^outputBiotypesSvg ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-	else
-		outputCategoriesPng=`grep -P '^outputCategoriesPng ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-		outputBiotypesPng=`grep -P '^outputBiotypesPng ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-	fi
-fi
-if [ "$countFileChoice" == "True" ]; then 
-	outputCountFile=`grep -P '^outputCountFile ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-fi
-if [ "$indexChoice" == "True" ]; then 
-	outputStrandedIndex=`grep -P '^outputStrandedIndex ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-	outputUnstrandedIndex=`grep -P '^outputUnstrandedIndex ?=' $configFile | awk 'BEGIN{FS="= ?"} {print $2}'`;
-fi
-
-#########################################################################################################
-# CREATION OF A TMP DIRECTORY FOR THE OUTPUT FILES OF ALFA AND cd                                       #
-#########################################################################################################
-outputDirectory=`mktemp -d "$galaxyRoot"/database/tmp/tmpXXXXXX`;
-if [ -d $outputDirectory ]; then
-	chmod -R ugo+wrx $outputDirectory;
-	rm -R $outputDirectory;
-fi
-mkdir $outputDirectory;
-chmod -R ugo+wrx $outputDirectory;
-cd $outputDirectory;
-
-#########################################################################################################
-# TEST OF INPUT1                                                                                        #
-#########################################################################################################
-if [ "$annotationSource" == "index" ]; then
-	#need to copy the files.dat to .*index because ALFA requires the extension ".(un)stranded.index"
-	index="index"
-	cp $strandedIndex $index".stranded.index"
-	cp $unstrandedIndex $index".unstranded.index"
-fi
-
-#########################################################################################################
-# TEST OF INPUT2 AND DETERMINATION OF PYTHON READS INPUT ARGUMENT                                       #
-#########################################################################################################
-readsListLen=`echo "$readsFileList" | wc -l`;
-readsInput="";
-for (( i = 1; i <= readsListLen; i++ )) do
-	readsFile[$i]=`echo "$readsFileList" | awk -v i=$i 'NR==i'`;
-	readsLabel[$i]=`echo "$readsLabelList" | awk -v i=$i 'NR==i' | sed -e 's/ /_/g'`;
-	if [ "$readsType" == "bam" ]; then
-		bamSorted=`samtools view -H "${readsFile[$i]}" | grep -c 'SO:unsorted'`
-		if [ "$bamSorted" != "0" ] ; then
-			samtools sort ${readsFile[$i]} ${readsFile[$i]}
-		fi
-	else
-		#need to copy the file.dat to tmp.bedgraph because ALFA requires the extension ".bedgraph"
-		bedgraphFile="tmpBedgraph_"$i
-		cp ${readsFile[$i]} $bedgraphFile".bedgraph"
-		readsFile[$i]=$bedgraphFile
-	fi
-	if [ "${readsLabel[$i]}" == "" ]; then
-		readsLabel[$i]="sample_""$i";
-	fi
-	readsInput=$readsInput" "${readsFile[$i]}" "${readsLabel[$i]};
-done
-
-#########################################################################################################
-# DETERMINATION OF THE APPROPRIATE SCRIPTS ARGUMENTS                                                    #
-#########################################################################################################
-scriptPath="$toolDir/";
-if [ "$annotationSource" == "index" ]; then
-	scriptInput="-g $index -i ""$readsInput";
-elif [ "$annotationSource" == "built_in_index" ]; then
-	scriptInput="-g $built_in_index_prefix -i ""$readsInput";
-else
-	scriptInput="-a $annotationFile -i ""$readsInput";
-fi
-if [ "$readsType" = "bedgraph" ]; then
-	scriptInput=$scriptInput" --bedgraph";
-fi
-scriptStrandness="-s "$strandness
-scriptCategoriesDepth="-d "$categoriesDepth
-if [ "$plotChoice" == "True" ]; then
-	if [ "$plotFormat" == "pdf" ]; then
-		scriptPlotOutput="--pdf plotFile.pdf";
-	else
-		scriptPlotOutput="--"$plotFormat" plotFile";
-	fi
-	if [ "$plotThresholdChoice" == "True" ]; then
-		scriptPlotOutput=$scriptPlotOutput" -t ""$yMin"" ""$yMax"
-	fi
-else
-	scriptPlotOutput="--n";
-fi
-
-#########################################################################################################
-# DISPLAY ALFA PROCESS                                                                                  #
-#########################################################################################################
-printf "__________________________________________________________________\n\n" >> $logReport
-printf "                          ALFA PROCESS                            \n" >> $logReport
-printf "__________________________________________________________________\n" >> $logReport
-
-if [ "$plotChoice" == "False" ] && [ "$countFileChoice" == "False" ] && [ "$indexChoice" == "False" ]; then
-cat <<error 1>&2
-
-No output to return. 
-Process Aborted
-error
-exit 0
-fi
-
-printf "Command:\n" >> $logReport
-echo "python ""$scriptPath"ALFA.py $scriptInput $scriptStrandness $scriptCategoriesDepth $scriptPlotOutput >> $logReport;
-printf "\n******************************************************************\n" >> $logReport
-printf "Temporary Output Directory:\n" >> $logReport
-echo $outputDirectory >> $logReport
-printf "\n******************************************************************\n" >> $logReport
-printf "ALFA prompt:\n" >> $logReport
-python "$scriptPath"ALFA.py $scriptInput $scriptStrandness $scriptCategoriesDepth $scriptPlotOutput >> $logReport 2>errorFile;
-printf "\n******************************************************************\n" >> $logReport
-
-#########################################################################################################
-# REDIRECTION OF ERRORS - TMP SOURCE ALFA.PY MUST BE CORRECTED SOON                                     #
-#########################################################################################################
-if [[ -s errorFile ]]; then
-	#When the option --n is enabled, alfa prints '### End of the program' in stderr even if the process worked-
-	#The following lines to avoid the tool from crashing in this case
-	endProgram=`grep -c '### End of program' errorFile`
-	if [ "$endProgram" == "0" ]; then
-		#When alfa prints '### End of program' in stdout, all the messages in stderr are considered
-		#as warnings and not as errors. True errors make the script exits with code "2"
-		endProgram=`grep -c '### End of program' $logReport`
-		if [ "$endProgram" == "0" ]; then
- 			>&2 printf "The script ALFA.py encountered the following error:\n\n"
-			>&2 cat errorFile
-			printf "ALFA error:\n" >> $logReport
-			cat errorFile >> $logReport
-			printf "\n******************************************************************\n" >> $logReport
- 			exit 2
- 		else
- 			>&2 printf "The script ALFA.py encountered the following warning:\n\n"
- 			>&2 cat errorFile 
- 			printf "ALFA warning:\n" >> $logReport
- 			cat errorFile >> $logReport
-			printf "\n******************************************************************\n" >> $logReport
- 		fi
- 	fi
-fi
-
-#########################################################################################################
-# OUTPUT REDIRECTIONS                                                                                   #
-#########################################################################################################
-if [ "$plotChoice" == "True" ]; then
-	if [ "$plotFormat" == "pdf" ]; then
-		mv "plotFile.pdf" $outputPdf;
-	elif [ "$plotFormat" == "png" ]; then
-		mv "plotFile.categories.png" $outputCategoriesPng;
-		mv "plotFile.biotypes.png" $outputBiotypesPng;
-	else 
-		mv "plotFile.categories.svg" $outputCategoriesSvg;
-		mv "plotFile.biotypes.svg" $outputBiotypesSvg;
-	fi
-fi
-if [ "$countFileChoice" == "True" ]; then
-	> countFile;
-	for (( i = 1; i <= readsListLen; i++ )) do
-		printf "##LABEL: "${readsLabel[$i]}"\n\n" >> countFile;
-		cat ${readsLabel[$i]}".categories_counts" >> countFile;
-		printf "__________________________________________________________________\n" >> countFile;
-	done
-	mv countFile $outputCountFile;
-fi
-if [ "$indexChoice" == "True" ]; then
-	if [ "$annotationSource" == "index" ]; then
-		mv $strandedIndex $outputStrandedIndex
-		mv $unstrandedIndex $outputUnstrandedIndex
-	elif [ "$annotationSource" == "built_in_index" ]; then
-		cp $built_in_index_prefix".stranded.index" $outputStrandedIndex
-		cp $built_in_index_prefix".unstranded.index" $outputUnstrandedIndex
-	else
-		annotationFileName=`grep -P -o '[^/]*\.dat$' <<< $annotationFile`
-		mv $annotationFileName".stranded.index" $outputStrandedIndex
-		mv $annotationFileName".unstranded.index" $outputUnstrandedIndex
-	fi
-fi
\ No newline at end of file
--- a/ALFA/alfa_wrapper.xml	Tue Oct 11 11:10:18 2016 -0400
+++ b/ALFA/alfa_wrapper.xml	Thu Oct 27 04:42:59 2016 -0400
@@ -8,10 +8,61 @@
     	<requirement type="package" version="1.4">matplotlib</requirement>
   	</requirements>
 
-  	<command interpreter="bash">
-  		alfa_wrapper.sh $__root_dir__ $__tool_directory__ $ALFA_config $logReport
-  	</command>	
-	
+	<command interpreter="python">
+	<![CDATA[
+		ALFA_wrapper.py
+
+		--project_name "${projectName}"	
+
+		##__INPUT 1__##
+		#if str ( $annotation.annotationSource['annotationSourceSelection'] ) == "index"
+			--index $annotation.annotationSource['strandedIndex'] $annotation.annotationSource['unstrandedIndex']
+		#else if str ( $annotation.annotationSource['annotationSourceSelection'] ) == "built_in_index"
+			--bi_index $annotation.annotationSource.built_in_index_prefix.fields.prefix
+		#else
+			--annotation $annotation.annotationSource['annotationFile']
+		#end if
+
+		##__INPUT 2__##
+		--reads_format $reads.readsType['readsTypeSelection']
+			--reads
+		#for $i, $r in enumerate ( $reads.readsType['readsList'] ) 
+			__fname__$r.readsFile
+			__label__$r.readsLabel
+		#end for
+		--strandness $reads['strandness']
+
+		##__OUTPUT FILES__##
+		#if str ( $outputFiles['plot'] ) == "True"
+			#if str ( $outputOptions['plotFormat'] ) == "pdf"
+				--output_pdf $outputPdf
+			#else if str ( $outputOptions['plotFormat'] ) == "png"
+				--output_png $outputCategoriesPng $outputBiotypesPng
+			#else
+				--output_svg $outputCategoriesSvg $outputBiotypesSvg
+			#end if
+		#end if
+		#if str ( $outputFiles['countFile'] ) == "True"
+			--output_count $outputCountFile
+		#end if
+		#if str ( $outputFiles['index'] ) == "True"
+			--output_index $outputStrandedIndex $outputUnstrandedIndex
+		#end if
+
+		##__OUTPUT OPTIONS__##
+		--categories_depth $outputOptions['categoriesDepth']
+		#if str ( $outputFiles['plot'] ) == "True"
+			--plot_format $outputOptions['plotFormat']
+			#if str ( $outputOptions.plotThreshold['plotThresholdChoice'] ) == "True"
+				--threshold $outputOptions.plotThreshold.yMin $outputOptions.plotThreshold.yMax
+			#end if
+		#end if
+
+		--log_report $logReport
+		--galaxy_root $__root_dir__
+		--tool_dir $__tool_directory__
+	]]>
+	</command>
 	<inputs>
 		<param name="projectName" value="ALFA" type="text" size="20" label="Project Name">
 			<validator type="empty_field" message="Please, specify a name for your project."/>
@@ -29,7 +80,7 @@
 					</param>
 				</when>
 				<when value="index">
-					<param name="strandedIndex" type="data" format="index" label="Select your ALFA stranded index file (index format)"/>
+					<param name="strandedIndex" type="data" format="index" label="Select your ALFA Stranded index file (index format)"/>
 					<param name="unstrandedIndex" type="data" format="index" label="Select your ALFA Unstranded index file (index format)"/>
 				</when>
 				<when value="built_in_index">
@@ -74,7 +125,7 @@
 			<param name="index" type="boolean" truevalue="True" falsevalue="False" checked="False" label ="Indexes" help="Print the resulting stranded and unstranded indexes from the gtf input file (useful if you plan to run ALFA again with this annotated sequence)"/>
 		</section>
 
-		<section name="outputOptions" title="ADVANCED OPTIONS" expanded="False">
+		<section name="outputOptions" title="ADVANCED SETTINGS" expanded="False">
 			<param name="categoriesDepth" type="select" label="Categories to Display">
 				<option value="1">gene | intergenic</option>
 				<option value="2">exon | intron | intergenic</option>
@@ -92,6 +143,7 @@
 						<param name="yMin" type="float" value="-2.0" label="y min"/>
 						<param name="yMax" type="float" value="2.0" label="y max"/>
 					</when>
+					<when value="False"></when>
 			</conditional>
 		</section>
 	</inputs>
@@ -124,61 +176,6 @@
 		</data>
 	</outputs>
 
-	<configfiles>
-		<configfile name="ALFA_config">
-			projectName=$projectName
-
-			##__INPUT 1__##
-			annotationSource=$annotation.annotationSource['annotationSourceSelection']
-			#if str ( $annotation.annotationSource['annotationSourceSelection'] ) == "index"
-				annotationFile=None
-				strandedIndex=$annotation.annotationSource['strandedIndex']
-				unstrandedIndex=$annotation.annotationSource['unstrandedIndex']
-			#else if str ( $annotation.annotationSource['annotationSourceSelection'] ) == "built_in_index"
-				annotationFile=None
-				built_in_index_prefix=$annotation.annotationSource.built_in_index_prefix.fields.prefix
-			#else
-				annotationFile=$annotation.annotationSource['annotationFile']
-				strandedIndex=None
-				unstrandedIndex=None
-			#end if
-
-			##__INPUT 2__##
-			readsType=$reads.readsType['readsTypeSelection']
-			#for $i, $r in enumerate ( $reads.readsType['readsList'] ) 
-				readsFile[$i]=$r.readsFile
-				readsLabel[$i]=$r.readsLabel
-			#end for
-			strandness=$reads['strandness']
-
-			##__OUTPUT FILES__##
-			plotChoice=$outputFiles['plot']
-			countFileChoice=$outputFiles['countFile']
-			indexChoice=$outputFiles['index']
-
-			outputPdf=$outputPdf
-			outputCategoriesPng=$outputCategoriesPng
-			outputBiotypesPng=$outputBiotypesPng
-			outputCategoriesSvg=$outputCategoriesSvg
-			outputBiotypesSvg=$outputBiotypesSvg
-			outputCountFile=$outputCountFile
-			outputStrandedIndex=$outputStrandedIndex
-			outputUnstrandedIndex=$outputUnstrandedIndex
-
-			##__OUTPUT OPTIONS__##
-			categoriesDepth=$outputOptions['categoriesDepth']
-			plotFormat=$outputOptions['plotFormat']
-			plotThresholdChoice=$outputOptions.plotThreshold['plotThresholdChoice']
-			#if str ( $outputOptions.plotThreshold['plotThresholdChoice'] ) == "True"
-				yMin=$outputOptions.plotThreshold.yMin
-				yMax=$outputOptions.plotThreshold.yMax
-			#else
-				yMin=None
-				yMax=None
-			#end if
-		</configfile>
-	</configfiles>
-
 	<tests>
 		<test>
 			<param name="alfa_toy" />
@@ -221,13 +218,9 @@
 	</tests>
 
 	<help>
-**ALFA acronym**
-
-- Annotation.Landscape.For.Aligned reads
+<![CDATA[
+**What it does**
 
-----
-
-**What it does**
 
 	| ALFA provides a global overview of features distribution composing New Generation Sequencing dataset(s). 
 	|
@@ -235,6 +228,12 @@
 
 ----
 
+**ALFA acronym**
+
+- Annotation.Landscape.For.Aligned reads
+
+----
+
 **Official documentation of the tool**
 
 
@@ -250,56 +249,63 @@
 
 **Nota Bene**
 
-1. **Input 1: Annotation File**
+* **Input 1: Annotation File**
 
 
-	| ALFA requires as first input an annotation file (sequence, genome...) in gtf format in order to generate indexes that will be used in a 2nd step of the program.
-	| Indexes are files which list all the coordinates of all categories (stop codon, 5'-UTR, CDS, intergenic...) and biotypes (protein coding genes, miRNA, tRNA, ...) encountered in the annotated sequence.
+	| ALFA requires as first input an annotation file (sequence, genome...) in gtf format in order to generate alfa indexes needed in a second round of the program.
+	| Indexes are files which list all the coordinates of the categories (stop codon, 5'-UTR, CDS, intergenic...) and biotypes (protein coding genes, miRNA, tRNA, ...) encountered in the annotated sequence.
+	|
 	
-.. class:: warningmark
+	.. class:: warningmark
 
-Gtf File must be sorted.
+	| Gtf File must be sorted.
+	|
 
-.. class:: infomark
-
-Generation of indexes from an annotation file may be time consuming (i.e ~10min for the human genome). Thus, ALFA allows the user to submit directly indexes generated in previous runs.
+	.. class:: infomark
 
-2. **Input 2: Reads**
+	| Generation of indexes from an annotation file might be time consuming (i.e ~10min for the human genome). Thus, ALFA allows the user to submit directly indexes generated in previous runs.
+	|
 
-	| ALFA requires as second input a single or a set of mapped reads file(s) in either bam or bedgraph format. These files are required to intersect the coordinates of the mapped reads with the associated categories and biotypes on the annotated sequence.
-	| The strandness option determines which strand of the annotated sequence will be taken into account during this intersection.
+	.. class:: infomark
+
+	| ALFA also allows to use built-in indexes to save even more computational time. In order to generate these built-in indexes, install the data manager tool 'data_manager_build_alfa_indexes' available on the toolshed.
 
-.. class:: warningmark
+* **Input 2: Reads**
 
-Bam or Bedgraph file(s) must be sorted.
+	| ALFA requires as second input a single or a set of mapped reads file(s) in either bam or bedgraph format. The coordinates of the mapped reads will be intersected with the according categories and biotypes mentioned in the indexes.
+	| The strandness option determines which strand of the annotated sequence will be taken into account during this intersection.
+	|
 
-<!--
-.. class:: warningmark
+	.. class:: warningmark
 
-For oriented reads (either matching the forward strand or the reverse strand), 'forward' or 'reverse' strandness must be selected.
+	| Bam or Bedgraph file(s) must be sorted.
+	|
 
-.. class:: warningmark
+	.. class:: warningmark
 
-For paired-end or non-oriented reads, 'unstranded' strandness must be selected.
--->
+	| Chromosome names in reads and in annotation file (gtf or indexes) must be the same for the intersection to occur
+	|
 
-3. **Output files**
+* **Output files**
 
 	| The result of the intersection is a count file displaying the count of nucleotides in the reads for each genomic categories and biotypes. From this count file, plots of the raw and normalized distributions of the reads among these categories are generated.
 	| In the output files section, the user can choose what kind of files he desires as ALFA output. Categories Count File and Plots are proposed by default. 
-
-.. class:: infomark
+	|
 
-The user can also select the 'indexes' option as output. This option is interesting if you plan to run ALFA again with the same submitted annotation file. *See Nota Bene/Input 1: Annotation File for more information.*
+	.. class:: infomark
 
+	| The user can also select the 'indexes' option as output. This option is interesting if you plan to run ALFA again with the same submitted annotation file. *See Nota Bene/Input 1: Annotation File for more information.*
+	|
 
-- `How the plots look like`_
+	- `How the plots look like`_
 
-.. _How the plots look like: https://github.com/biocompibens/ALFA#plots
+	.. _How the plots look like: https://github.com/biocompibens/ALFA#plots
 
-- `How they are generated`_ 
+	|
 
-.. _How they are generated: https://github.com/biocompibens/ALFA#detailed-example
+	- `How they are generated`_ 
+
+	.. _How they are generated: https://github.com/biocompibens/ALFA#detailed-example
 
 ----
 
@@ -307,7 +313,7 @@
 
 	| Benoît Noël and Mathieu Bahin: *compbio team, Institut de Biologie de l'Ecole Normale Supérieure de Paris*
 
-
+]]>
      </help>
 
      <citations>
--- a/ALFA/tool-data/alfa_genomes_indexes.loc.sample	Tue Oct 11 11:10:18 2016 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-#<species>	<version>	<release>	<value>	<dbkey>	<name>	<prefix>
-#Arabidopsis_thaliana	TAIR10	30	Arabidopsis_t_TAIR10_30	Arabidopsis_t_TAIR10_30	Arabidopsis thaliana: TAIR10	<path_to_alfa_indexes>/Arabidopsis_thaliana.TAIR10.30
-#Drosophila_melanogaster	dm6	30	Drosophila_m_dm6_30	Drosophila_m_dm6_30	Drosophila melanogaster: dm6	<path_to_alfa_indexes>/Drosophila_melanogaster.BDGP6.30
-#Homo_sapiens	v38	82	Homo_s_v38_82	Homo_s_v38_82	Homo sapiens: v38	<path_to_alfa_indexes>/Homo_sapiens.GRCh38.82
-#Mus_musculus	v38	83	Mus_m_v38_83	Mus_m_v38_83	Mus musculus: v38 	<path_to_alfa_indexes>/Mus_musculus.GRCm38.83.chr
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ALFA/tool-data/alfa_indexes.loc.sample	Thu Oct 27 04:42:59 2016 -0400
@@ -0,0 +1,2 @@
+#<species>	<version>	<release>	<value>	<dbkey>	<name>	<prefix>
+#Dictyostelium_discoideum	dicty_2	7	Dictyostelium_discoideum_dicty_2_7	Dictyostelium_discoideum_dicty_2_7	Dictyostelium_discoideum: dicty_2 (release 7)	<path_to_dicty_indexes_dir>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ALFA/tool-data/alfa_indexes.loc.sample~	Thu Oct 27 04:42:59 2016 -0400
@@ -0,0 +1,5 @@
+#<species>	<version>	<release>	<value>	<dbkey>	<name>	<prefix>
+#Arabidopsis_thaliana	TAIR10	30	Arabidopsis_t_TAIR10_30	Arabidopsis_t_TAIR10_30	Arabidopsis thaliana: TAIR10	<path_to_alfa_indexes>/Arabidopsis_thaliana.TAIR10.30
+#Drosophila_melanogaster	dm6	30	Drosophila_m_dm6_30	Drosophila_m_dm6_30	Drosophila melanogaster: dm6	<path_to_alfa_indexes>/Drosophila_melanogaster.BDGP6.30
+#Homo_sapiens	v38	82	Homo_s_v38_82	Homo_s_v38_82	Homo sapiens: v38	<path_to_alfa_indexes>/Homo_sapiens.GRCh38.82
+#Mus_musculus	v38	83	Mus_m_v38_83	Mus_m_v38_83	Mus musculus: v38 	<path_to_alfa_indexes>/Mus_musculus.GRCm38.83.chr
--- a/ALFA/tool_data_table_conf.xml.sample	Tue Oct 11 11:10:18 2016 -0400
+++ b/ALFA/tool_data_table_conf.xml.sample	Thu Oct 27 04:42:59 2016 -0400
@@ -2,6 +2,6 @@
     <!-- Locations of all alfa indexes -->
     <table name="alfa_indexes" comment_char="#" allow_duplicate_entries="False">
         <columns>species, version, release, value, dbkey, name, prefix</columns>
-        <file path="tool-data/alfa_genomes_indexes.loc" />
+        <file path="tool-data/alfa_indexes.loc" />
     </table>
-</tables>
\ No newline at end of file
+</tables>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ALFA/tool_data_table_conf.xml.sample~	Thu Oct 27 04:42:59 2016 -0400
@@ -0,0 +1,7 @@
+<tables>
+    <!-- Locations of all alfa indexes -->
+    <table name="alfa_indexes" comment_char="#" allow_duplicate_entries="False">
+        <columns>species, version, release, value, dbkey, name, prefix</columns>
+        <file path="tool-data/alfa_genomes_indexes.loc" />
+    </table>
+</tables>
\ No newline at end of file