#!/bin/bash source tests/test_helper.sh TEST_ARB=$TEST_ARGS maketmpdir T cp $TEST_ARB $T/ref.arb SINA="./src/sina --prealigned --preserve-order" begin_test "Copy ARB to FASTA (TEST_ARB->test.fasta)" capture_stdouterr "$SINA -i $T/ref.arb -o $T/test.fasta --select-step 1000" assert_exit_success assert_output_contains "align 12 sequences" end_test begin_test "Copy ARB to FASTA.gz (TEST_ARB->test.fasta.gz)" capture_stdouterr "$SINA -i $T/ref.arb -o $T/test.fasta.gz --select-step 1000" assert_exit_success assert_output_contains "align 12 sequences" capture_stderr "gunzip -c $T/test.fasta.gz | cmp - $T/test.fasta" assert_exit_success end_test begin_test "Copy ARB to FASTA (TEST_ARB->STDOUT)" capture_stdouterr "$SINA -i $T/ref.arb -o - --select-step 1000 > $T/test2.fasta" assert_exit_success assert_output_contains "align 12 sequences" capture_stderr "cmp $T/test.fasta $T/test2.fasta" assert_exit_success end_test begin_test "Copy ARB to ARB (TEST_ARB->test.arb)" capture_stdouterr "$SINA -i $T/ref.arb -o $T/test.arb --select-step 1000" assert_exit_success assert_output_contains "align 12 sequences" end_test begin_test "Copy FASTA to ARB (test.fasta->test2.arb)" capture_stdouterr "$SINA -i $T/test.fasta -o $T/test2.arb" assert_exit_success assert_output_contains "align 12 sequences" capture_stdouterr "cmp $T/test.arb $T/test2.arb" assert_exit_success end_test begin_test "Copy FASTA.gz to ARB (test.fasta->test2.arb)" capture_stdouterr "$SINA -i $T/test.fasta.gz -o $T/test2.arb" assert_exit_success assert_output_contains "align 12 sequences" capture_stdouterr "cmp $T/test.arb $T/test2.arb" assert_exit_success end_test begin_test "Copy ARB into ARB (TEST_ARB->test2.arb)" capture_stdouterr "$SINA -i $T/ref.arb -o $T/test2.arb --select-step 1001" assert_exit_success assert_output_contains "align 12 sequences" capture_stdouterr "cmp $T/test.arb $T/test2.arb" assert_exit_failure end_test begin_test "Copy ARB to NULL (outtype=NONE)" capture_stdouterr "$SINA -i $T/test2.arb --outtype NONE" assert_exit_success assert_output_contains "align 23 sequences" end_test begin_test "Copy FASTA to NULL (test.fasta->/dev/null)" capture_stdouterr "$SINA -i $T/test.fasta -o /dev/null" assert_exit_success assert_output_contains "align 12 sequences" end_test begin_test "Meta Data in FASTA header" capture_stdouterr "$SINA -i $T/test.arb -o $T/test.fasta --meta-fmt header -f acc" assert_exit_success assert_output_contains "align 12 sequences" grep "^>" $T/test.fasta | sed 's/.*\[acc=\([^]]*\)\].*/\1/' | sort -u > $T/acc.txt capture_stdout "wc -l $T/acc.txt" assert_output_contains "12" end_test begin_test "Meta Data in sidecar CSV" capture_stdouterr "$SINA -i $T/test.arb -o $T/test.fasta --meta-fmt csv -f acc" assert_exit_success assert_output_contains "align 12 sequences" cut -d, -f2 $T/test.csv | tr -d $'\\r' | tail -n+2 | sort > $T/acc2.txt assert_exit_success "cmp $T/acc.txt $T/acc2.txt" end_test begin_test "Meta Data in FASTA comments" capture_stdouterr "$SINA -i $T/test.arb -o $T/test.fasta --meta-fmt comment -f acc" assert_exit_success assert_output_contains "align 12 sequences" sed -n 's/^; acc=//p' $T/test.fasta | sort > $T/acc2.txt assert_exit_success "cmp $T/acc.txt $T/acc2.txt" end_test begin_test "CSV writer" capture_stdouterr "$SINA -i $T/test.arb -o $T/test.fasta -o $T/test.csv -f acc" assert_exit_success assert_output_contains "align 12 sequences" cut -d, -f2 $T/test.csv | tail -n+2 | sort > $T/acc2.txt assert_exit_success "cmp $T/acc.txt $T/acc2.txt" end_test begin_test "CSV writer - stdout" capture_stdouterr "$SINA -i $T/test.arb -o $T/test.fasta --outtype CSV -o - -f acc > $T/test.csv" assert_exit_success assert_output_contains "align 12 sequences" cut -d, -f2 $T/test.csv | tail -n+2 | sort > $T/acc2.txt assert_exit_success "cmp $T/acc.txt $T/acc2.txt" end_test begin_test "CSV writer - gzip" capture_stdouterr "$SINA -i $T/test.arb -o $T/test.csv.gz -f acc" assert_exit_success assert_output_contains "align 12 sequences" gzip -dc $T/test.csv.gz | cut -d, -f2 | tail -n+2 | sort > $T/acc2.txt assert_exit_success "cmp $T/acc.txt $T/acc2.txt" end_test begin_test "CSV writer - CRLF" capture_stdouterr "$SINA -i $T/test.arb -o $T/test.csv -f acc --csv-crlf" assert_exit_success assert_output_contains "align 12 sequences" cut -d, -f2 $T/test.csv | tail -n+2 | sort > $T/acc2.txt assert_exit_failure "cmp $T/acc.txt $T/acc2.txt" assert_exit_success "tr -d $'\\r' < $T/acc2.txt | cmp $T/acc.txt -" assert_exit_success "grep -c $'\\r' $T/test.csv" assert_output_contains 13 end_test