<tool id="dNdSpiNpiS" name="dNdSpiNpiS" version="3.0">
	<description>- Population genetics -</description>

	<requirements>
		<requirement type="binary">dNdSpiNpiS</requirement>
	</requirements>
	
	<command>
		dNdSpiNpiS -alignment_file=$pfas_file
		
		#if $cond_population.pop_select != "all_individuals":
		 -population_file=$cond_population.pop_file
		#end if
		
		#if $cond_focal_species.source_select == "user_defined":
		 -ingroup=$cond_focal_species.custom_name
		#else:
		 -ingroup=$cond_focal_species.dropdown_list
		#end if
		
		#if $cond_out_species.out_select != "no_outgroup"
			#if $cond_out_species.out_select == "user_defined":
			 -outgroup=$cond_out_species.out_custom_name
			#else:
			 -outgroup=$cond_out_species.out_dropdown_list
			#end if
		#end if
		
		#if $cond_boot_opts.boot_opts_selector != "standard":
		 -bs_replicates=$cond_boot_opts.bs_replicates
		 -bs_sort=$cond_boot_opts.bs_sort
		 -bs_confidence=$cond_boot_opts.bs_confidence
		#end if
		
		 -gc_bin=$gc_bin -gapN_site=$gapN_site -gapN_seq=$gapN_seq -min_nb_codon=$min_codon -kappa=$kappa
		 -remove_frameshift=$frameshift -compute_distances=$distance -tolerance_zone=$tolerance_zone -allow_internal_bc=$internal_bad_codons
		 -print_header=$header -contig_usage=$contig_usage -out=dNdSpiNpiS_output -exec_mode=galaxy 1> $dNdSpiNpiS_log 2> $dNdSpiNpiS_error
	</command>

	<inputs>
		<param name="pfas_file" type="data" label="Input alignment file" format="fasta" help="Requested file type: fasta/pseudofasta (txt files won't be available in the dropdown list above)" />
		
		<conditional name="cond_population">
			<param name="pop_select" type="select" label="Use all individuals as a population or select a custom population file">
				<option value="all_individuals" selected="true">Use all focal individuals</option>
				<option value="custom_population_file">Use a custom population file</option>
			</param>
			<when value="all_individuals" />
			<when value="custom_population_file">
				<param name="pop_file" type="data" label="Input Population file" format="csv" help="Requested file type: csv" />
			</when>
		</conditional>

		<conditional name="cond_focal_species">
			<param name="source_select" type="select" label="Enter a custom focal/ingroup species name or choose one from PopPhyl Species List ">
				<option value="user_defined">Enter a custom species name</option>
				<option value="popphyl_list" selected="true">Choose a species name in PopPhyl Species List</option>
			</param>
			<when value="user_defined">
				<param name="custom_name" type="text" label="Name of the focal/ingroup species for this analysis" optional="true" help="In general, species name use the following format: Gender_species (Example: Ostrea_edulis)" />
			</when>
			<when value="popphyl_list">
				<param name="dropdown_list" type="select" label="Name of the focal/ingroup species for this analysis" optional="true" help="Type the first letters of the desired species name to narrow the list">
					<options from_data_table="popphyl_species" />
				</param>
			</when>
		</conditional>
		
		<conditional name="cond_out_species">
			<param name="out_select" type="select" label="Do you want to use a second species as outgroup ?">
				<option value="no_outgroup">No (Analyze focal species only)</option>
				<option value="user_defined">Yes - Custom species name</option>
				<option value="popphyl_list" selected="true">Yes - Choose a species name in PopPhyl Species List</option>
			</param>
			<when value="no_outgroup"></when>
			<when value="user_defined">
				<param name="out_custom_name" type="text" label="Name of the outgroup species for this analysis" optional="true" help="In general, species name use the following format: Gender_species (Example: Ostrea_chilensis)" />
			</when>
			<when value="popphyl_list">
				<param name="out_dropdown_list" type="select" label="Name of the outgroup species for this analysis" optional="true" help="Type the first letters of the desired species name to narrow the list">
					<options from_data_table="popphyl_species" />
				</param>
			</when>
		</conditional>
		
		<param name="gc_bin" type="integer" label="Number of class/bin for GC allele frequency" value="8" help="Field type: positive integer" />
		
		<param name="gapN_site" type="integer" label="Minimum number of focal/ingroup sequences without an undetermined character (or a gap) required to keep a given site" value="10" help="Field type: integer - Exemple: 10 if you have 10 focal individuals with 2 alleles each" />
		<param name="gapN_seq" type="float" label="Maximum tolerated proportion of undetermined characters (or gap) to keep a given sequence" value="0.5" help="Field type: float" />
		
		<param name="min_codon" type="integer" label="Minimum number of complete codons required to perform calculations" value="10" help="Field type: positive integer" />
		<param name="kappa" type="integer" label="Kappa to use in SequenceStatistics methods" value="1" help="Field type: positive integer" />
		
		<param name="frameshift" type="select" label="Frameshift management" help="">
			<option value="1">Remove frameshift-containing contigs</option>
			<option value="0" selected="true">Keep frameshift-containing contigs</option>
		</param>
		
		<param name="distance" type="select" label="Compute distance between focal/ingroup individuals" help="">
			<option value="1" selected="true">Yes</option>
			<option value="0">No</option>
		</param>
		
		<param name="tolerance_zone" type="integer" label="Number of terminal positions in which Stop/Frameshift codons will be tolerated" value="20" help="Field type: positive integer" />
		
		<param name="internal_bad_codons" type="select" label="Internal Stop/Frameshift codons" help="">
			<option value="1">tolerated</option>
			<option value="0" selected="true">forbidden</option>
		</param>

		<param name="header" type="select" label="Write columns names at the beginning of the main output file ?" help="">
			<option value="1" selected="true">Yes</option>
			<option value="0">No</option>
		</param>
		
		<param name="contig_usage" type="select" label="Contig usage restriction for the Biological Summary" help="">
			<option value="all"  selected="true">Use all contigs</option>
			<option value="even">Use even contigs only</option>
			<option value="odd">Use odd contigs only</option>
		</param>
		
		<conditional name="cond_boot_opts">
			<param name="boot_opts_selector" type="select" label="Bootstrap parameters for the Biological Summary">
				<option value="standard" selected="True">Use standard parameters</option>
				<option value="custom">Use custom parameters</option>
			</param>
			<when value="custom">
				<param name="bs_replicates" type="integer" label="Number of bootstrap resampling to execute" value="10000" help="Field type: positive integer" />
				<param name="bs_sort" type="integer" label="Sort precision for the confidence interval" value="1000000" help="Field type: positive integer" />
				<param name="bs_confidence" type="float" label="Percentage of confidence" value="0.95" help="Field type: float" />
			</when>
			<when value="standard" />
		</conditional>
	</inputs>
	
	<outputs>
		<data name="dNdSpiNpiS_log" label="dNdSpiNpiS - Log file" format="txt" />
		<data name="dNdSpiNpiS_error" label="dNdSpiNpiS - Error file" format="txt" />
		<data name="dNdSpiNpiS_output" from_work_dir="dNdSpiNpiS_output" label="dNdSpiNpiS - Population genetics" format="tabular" />
		<data name="dNdSpiNpiS_summary" from_work_dir="dNdSpiNpiS_summary" label="dNdSpiNpiS - Biological summary (${contig_usage.value})" format="txt" />
		<data name="dNdSpiNpiS_distances" from_work_dir="dNdSpiNpiS_distances" label="dNdSpiNpiS - Distances" format="tabular">
			<filter>distance == "1"</filter>
		</data>
	</outputs>
	
	<help>
This program can be used to analyze all contigs of an alignment file in Fasta/PseudoFasta format.

----

List of analysis for the ingroup species:

	- Polymorphism analysis (piN, piS)
	- GC3
	- Individual Heterozygosity
	- Fit
	- Weir and Cockerham (Evolution 1984) Fit
	- Non Oriented GC Analysis
	- Distance between individuals

----

Additionnal analysis when two species are defined:

	- Collect various indicators of Selection (nN, nS, fixN, fixS, etc.)
	- McDonald-Kreitman analysis
	</help>
</tool>
