Skip to content

Commit

Permalink
adding more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tgaspe committed Aug 30, 2024
1 parent 7cee28e commit 91205bb
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/bcftools/bcftools_concat/config.vsh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ argument_groups:
alternatives: -i
type: file
multiple: true
description: Input VCF/BCF file.
required: true
description: Input VCF/BCF files to concatenate.

- name: --file_list
alternatives: -f
type: file
description: Read the list of VCF/BCF files from a file, one file name per line.

- name: Outputs
arguments:
Expand Down Expand Up @@ -60,14 +64,9 @@ argument_groups:
- name: --remove_duplicates
alternatives: -d
type: string
choices: ['snps', 'indels', 'both', 'all', 'exact']
choices: ['snps', 'indels', 'both', 'all', 'exact', 'none']
description: |
Output duplicate records present in multiple files only once: <snps|indels|both|all|exact>.
- name: --file_list
alternatives: -f
type: file
description: Read the list of files from a file.
- name: --ligate
alternatives: -l
Expand Down
8 changes: 7 additions & 1 deletion src/bcftools/bcftools_concat/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ for par in ${unset_if_false[@]}; do
[[ "$test_val" == "false" ]] && unset $par
done

# Check to see whether the par_input or the par_file_list is set
if [[ -z "${par_input}" && -z "${par_file_list}" ]]; then
echo "Error: One of the parameters '--input' or '--file_list' must be used."
exit 1
fi

# Create input array
IFS=";" read -ra input <<< $par_input

Expand All @@ -31,7 +37,6 @@ bcftools concat \
${par_allow_overlaps:+-a} \
${par_compact_PS:+-c} \
${par_remove_duplicates:+-d "$par_remove_duplicates"} \
${par_file_list:+-f "$par_file_list"} \
${par_ligate:+-l} \
${par_ligate_force:+--ligate-force} \
${par_ligate_warn:+--ligate-warn} \
Expand All @@ -46,4 +51,5 @@ bcftools concat \
${meta_cpus:+--threads "$meta_cpus"} \
${par_verbose:+-v "$par_verbose"} \
-o $par_output \
${par_file_list:+-f "$par_file_list"} \
${input[@]} \
70 changes: 69 additions & 1 deletion src/bcftools/bcftools_concat/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ cat <<EOF > "$TMPDIR/example.vcf"
##contig=<ID=1,length=249250621,assembly=b37>
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT SAMPLE1
1 752567 llama G C,A . . . . 1/2
1 752722 . G A,AAA . . . . ./.
1 752752 . G A,AAA . . . . ./.
EOF

bgzip -c $TMPDIR/example.vcf > $TMPDIR/example.vcf.gz
Expand All @@ -53,6 +53,14 @@ cat <<EOF > "$TMPDIR/example_2.vcf"
1 752739 . G A,AAA . . . . ./.
EOF

bgzip -c $TMPDIR/example_2.vcf > $TMPDIR/example_2.vcf.gz
tabix -p vcf $TMPDIR/example_2.vcf.gz

cat <<EOF > "$TMPDIR/file_list.txt"
$TMPDIR/example.vcf.gz
$TMPDIR/example_2.vcf.gz
EOF

# Test 1: Default test
mkdir "$TMPDIR/test1" && pushd "$TMPDIR/test1" > /dev/null

Expand All @@ -72,6 +80,66 @@ echo "- test1 succeeded -"

popd > /dev/null

# Test 2: Allow overlaps, compact PS and remove duplicates
mkdir "$TMPDIR/test2" && pushd "$TMPDIR/test2" > /dev/null

echo "> Run bcftools_concat test with allow overlaps, and remove duplicates"
"$meta_executable" \
--input "../example.vcf.gz" \
--input "../example_2.vcf.gz" \
--output "concatenated.vcf" \
--allow_overlaps \
--remove_duplicates 'none' \
# &> /dev/null

# checks
assert_file_exists "concatenated.vcf"
assert_file_not_empty "concatenated.vcf"
assert_file_contains "concatenated.vcf" "concat -a -d none -o concatenated.vcf ../example.vcf.gz ../example_2.vcf.gz"
echo "- test2 succeeded -"

popd > /dev/null


# Test 3: Ligate, ligate force and ligate warn
mkdir "$TMPDIR/test3" && pushd "$TMPDIR/test3" > /dev/null

echo "> Run bcftools_concat test with ligate, ligate force and ligate warn"
"$meta_executable" \
--input "../example.vcf.gz" \
--input "../example_2.vcf.gz" \
--output "concatenated.vcf" \
--ligate \
--compact_PS \
# &> /dev/null


# checks
assert_file_exists "concatenated.vcf"
assert_file_not_empty "concatenated.vcf"
assert_file_contains "concatenated.vcf" "concat -c -l -o concatenated.vcf ../example.vcf.gz ../example_2.vcf.gz"
echo "- test3 succeeded -"

popd > /dev/null

# Test 4: file list with ligate force and ligate warn
mkdir "$TMPDIR/test4" && pushd "$TMPDIR/test4" > /dev/null

echo "> Run bcftools_concat test with file list, ligate force and ligate warn"
"$meta_executable" \
--file_list "../file_list.txt" \
--output "concatenated.vcf" \
--ligate_force \
# &> /dev/null

# checks
assert_file_exists "concatenated.vcf"
assert_file_not_empty "concatenated.vcf"
assert_file_contains "concatenated.vcf" "concat --ligate-force -o concatenated.vcf -f ../file_list.txt"
echo "- test4 succeeded -"

popd > /dev/null

echo "---- All tests succeeded! ----"
exit 0

Expand Down

0 comments on commit 91205bb

Please sign in to comment.