#/usr/bin/env bash

# humann2
humann2 \
    --input 'test-data/input_sequences.fasta' \
    -o 'humann2_output' \
    --annotation-gene-index 8 \
    --taxonomic-profile 'test-data/taxonomic_profile.tabular' \
    --metaphlan-options="-t rel_ab" \
    --nucleotide-database 'test-data/' \
    --protein-database 'test-data/' \
    --evalue '1' \
    --search-mode 'uniref50' \
    --prescreen-threshold '0.01' \
    --identity-threshold '50' \
    --translated-subject-coverage-threshold '50' \
    --translated-query-coverage-threshold '50' \
    --translated-alignment 'diamond' \
    --xipe 'off' \
    --minpath 'on' \
    --pick-frames 'on' \
    --gap-fill 'off' \
    --output-format 'tsv' \
    --output-max-decimals '10' \
    --output-basename 'humann2' \
    --pathways 'metacyc'

humann2 \
    --input 'test-data/input_sequences.fasta' \
    -o 'humann2_output' \
    --annotation-gene-index 8 \
    --metaphlan-options="-t rel_ab" \
    --nucleotide-database 'test-data/' \
    --protein-database 'test-data/' \
    --evalue '1' \
    --search-mode 'uniref90' \
    --prescreen-threshold '0.01' \
    --identity-threshold '50' \
    --translated-subject-coverage-threshold '50' \
    --translated-query-coverage-threshold '50' \
    --translated-alignment 'rapsearch' \
    --xipe 'off' \
    --minpath 'on' \
    --pick-frames 'on' \
    --gap-fill 'off' \
    --output-format 'tsv' \
    --output-max-decimals '10' \
    --output-basename 'humann2' \
    --pathways 'unipathway'

# humann2_associate
humann2_associate \
    --input 'test-data/hmp_pathabund.txt' \
    --focal-metadatum 'STSite' \
    --last-metadatum 'STSite' \
    --focal-type 'categorical' \
    --fdr '0.2' \
    --output 'test-data/associate_output.txt'

# humann2_barplot
humann2_barplot \
    --input 'test-data/hmp_pathabund.txt' \
    --focal-feature ANAGLYCOLYSIS-PWY \
    --sort none \
    --last-metadatum STSite \
    --focal-metadatum STSite \
    --scaling none \
    --width 5 \
    --dimensions 8 4 \
    --output test-data/barplot1.png

humann2_barplot \
    --input 'test-data/hmp_pathabund.txt' \
    --focal-feature ANAGLYCOLYSIS-PWY \
    --sort sum \
    --last-metadatum STSite \
    --focal-metadatum STSite \
    --scaling pseudolog \
    --width 5 \
    --dimensions 8 4 \
    --output test-data/barplot2.pdf

humann2_barplot \
    --input 'test-data/hmp_pathabund.txt' \
    --focal-feature ANAGLYCOLYSIS-PWY \
    --sort metadata \
    --last-metadatum STSite \
    --focal-metadatum STSite \
    --exclude-unclassified \
    --scaling none \
    --as-genera \
    --grid \
    --remove-zeroes \
    --width 5 \
    --dimensions 8 4 \
    --output test-data/barplot3.svg

humann2_barplot \
    --input 'test-data/hmp_pathabund.txt' \
    --focal-feature ANAGLYCOLYSIS-PWY \
    --top-strata 12 \
    --sort sum \
    --last-metadatum STSite \
    --focal-metadatum STSite \
    --exclude-unclassified \
    --scaling normalize \
    --width 5 \
    --dimensions 8 4 \
    --output test-data/barplot4.eps

# humann2_regroup_table
humann2_regroup_table \
    --input 'test-data/demo_genefamilies.tsv' \
    -o 'test-data/regrouped_gene_families_to_infogo1000.tsv' \
    --function 'sum' \
    --groups 'uniref90_infogo1000' \
    --ungrouped 'Y' \
    --protected 'Y'

humann2_regroup_table \
    --input 'test-data/demo_genefamilies.tsv' \
    -o 'test-data/regrouped_gene_families_to_ko.tsv' \
    --function 'mean' \
    --groups 'uniref90_ko' \
    --ungrouped 'Y' \
    --protected 'Y'

humann2_regroup_table \
    --input 'test-data/demo_genefamilies.tsv' \
    -o 'test-data/regrouped_gene_families_to_rxn.tsv' \
    --function 'sum' \
    --groups 'uniref90_rxn' \
    --ungrouped 'Y' \
    --protected 'Y'

# humann2_renorm_table
humann2_renorm_table \
    --input 'test-data/demo_pathabundance.tsv' \
    -o 'test-data/cpm_community_renormalized_pathway_abundance.tsv' \
    --units 'cpm' \
    --mode 'community' \
    --special 'n'

humann2_renorm_table \
    --input 'test-data/demo_pathabundance.tsv' \
    -o 'test-data/relab_levelwise_renormalized_pathway_abundance.tsv' \
    --units 'relab' \
    --mode 'levelwise' \
    --special 'y'

# humann2_join_tables
mkdir join_table_tmp_dir
cp 'test-data/demo_pathabundance.tsv' join_table_tmp_dir
cp 'test-data/demo_pathcoverage.tsv' join_table_tmp_dir
humann2_join_tables \
    -i 'join_table_tmp_dir' \
    -o 'test-data/joined_pathway_coverage_abundance.tsv'

# humann2_merge_abundance_tables
humann2_merge_abundance_tables \
    --input-genes 'test-data/demo_genefamilies.tsv' \
    --input-pathways 'test-data/demo_pathabundance.tsv' \
    -o 'test-data/merged_gene_families_pathways_abundances.tsv' 

# humann2_reduce_table
humann2_reduce_table \
    --input 'test-data/demo_genefamilies.tsv' \
    -o 'test-data/max_reduced_gene_family_abundance.tsv' \
    --function 'max' \
    --sort-by 'name'

# humann2_rename_table
humann2_rename_table \
    --input 'test-data/regrouped_gene_families_to_infogo1000.tsv' \
    --names 'infogo1000' \
    -o 'test-data/renamed_info1000.tsv'
    
humann2_rename_table \
    --input 'test-data/regrouped_gene_families_to_infogo1000.tsv' \
    --custom 'test-data/rename_mapping' \
    -o 'test-data/renamed_mapping_info1000.tsv'

# humann2_rna_dna_norm
humann2_rna_dna_norm \
    --input_dna 'test-data/rna_dna_norm-dna.txt' \
    --input_rna 'test-data/rna_dna_norm-rna.txt' \
    --output_basename 'results1' \
    --method 'laplace'

humann2_rna_dna_norm \
    --input_dna 'test-data/rna_dna_norm-dna.txt' \
    --input_rna 'test-data/rna_dna_norm-rna.txt' \
    --output_basename 'results2' \
    --method 'witten_bell' \
    --log_transform \
    --log_base '2'

# humann2_split_stratified_table
humann2_split_stratified_table \
    --input 'test-data/demo_genefamilies.tsv' \
    --output 'split_stratified_table'

# humann2_split_table
mkdir split_table_tmp_dir
humann2_split_table \
    --input 'test-data/joined_pathway_coverage_abundance.tsv' \
    -o 'split_table_tmp_dir'
cp 'split_table_tmp_dir/demo_Abundance.tsv' 'test-data/'
cp 'split_table_tmp_dir/demo_Coverage.tsv' 'test-data/'

# humann2_strain_profiler
humann2_strain_profiler \
    --input 'test-data/strain_profiler-input.txt' \
    --critical_mean '1' \
    --critical_count '2' \
    --pinterval '1e-10' '1' \
    --critical_samples '2'

# humann2_unpack_pathways
humann2_unpack_pathways \
    --input-genes 'test-data/demo_genefamilies.tsv' \
    --input-pathways 'test-data/demo_pathabundance.tsv' \
    --output unpack1

humann2_unpack_pathways \
    --input-genes 'test-data/demo_genefamilies.tsv' \
    --input-pathways 'test-data/demo_pathabundance.tsv' \
    --remove-taxonomy \
    --output unpack2
