comparison run_segalign_diagonal_partition @ 0:5c72425b7f1b draft

planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 98a4dd44360447aa96d92143384d78e116d7581b
author richard-burhans
date Wed, 17 Apr 2024 18:06:54 +0000
parents
children 9e34b25a8670
comparison
equal deleted inserted replaced
-1:000000000000 0:5c72425b7f1b
1 #!/usr/bin/env bash
2
3 set -o errexit
4 set -o nounset
5 set -o pipefail
6 #set -o xtrace
7
8 ##
9 ## parse arguments
10 ##
11
12 SEGALIGN_ARGS=()
13
14 MAX_SEGMENT_SIZE=""
15 OUTPUT_FILENAME=""
16 LASTZ_COMMAND_FILE="lastz_commands.txt"
17 HELP=0
18
19 while [[ $# -gt 0 ]]; do
20 case $1 in
21 --help)
22 HELP=1
23 shift
24 ;;
25 --max_segments)
26 MAX_SEGMENT_SIZE="$2"
27 shift 2
28 ;;
29 --output)
30 OUTPUT_FILENAME=$(readlink -f "$2")
31 shift 2
32 ;;
33 --tool_directory)
34 TOOL_DIRECTORY="$2"
35 shift 2
36 ;;
37 *)
38 SEGALIGN_ARGS+=("$1")
39 shift
40 esac
41 done
42
43 set -- "${SEGALIGN_ARGS[@]}"
44
45 ##
46 ## check arguments
47 ##
48
49 if [[ $# == 0 || "$HELP" == "1" ]]; then
50 segalign --help
51 exit 0
52 fi
53
54 if [[ $# -lt 2 ]]; then
55 echo "run_segalign_diagonal_partition: missing target and query sequences" 1>&2
56 exit 1
57 fi
58
59 ref_path=$(readlink -f "$1")
60 test -e "$ref_path" || {
61 echo "run_segalign_diagonal_partition: target file \"$ref_path\" does not exist" 1>&2
62 exit 1
63 }
64 query_path=$(readlink -f "$2")
65 test -e "$query_path" || {
66 echo "run_segalign_diagonal_partition: query file \"$query_path\" does not exist" 1>&2
67 exit 1
68 }
69 shift 2
70
71 DATA_FOLDER="data"
72 mkdir -p "$DATA_FOLDER" || {
73 echo "run_segalign_diagonal_partition: cannont create data directory \"$DATA_FOLDER\"" 1>&2
74 exit 1
75 }
76
77 cd $DATA_FOLDER/..
78 echo ""
79 echo "Converting fasta files to 2bit format" 1>&2
80
81 ##
82 ## convert target and query to 2bit
83 ##
84 faToTwoBit "$ref_path" "$DATA_FOLDER/ref.2bit" || {
85 echo "run_segalign_diagonal_partition: cannot convert \"$ref_path\" to 2bit" 1>&2
86 exit 1
87 }
88 faToTwoBit "$query_path" "$DATA_FOLDER/query.2bit" || {
89 echo "run_segalign_diagonal_partition: cannont convert \"$ref_path\" to 2bit" 1>&2
90 exit 1
91 }
92
93
94
95 time {
96 while IFS= read -r line; do
97 "$TOOL_DIRECTORY/diagonal_partition.py" $MAX_SEGMENT_SIZE $line >> $LASTZ_COMMAND_FILE
98 # segalign sort writes out the partitioned segment files to the working
99 # directory and prints the modified lastz commands.
100 done < <(stdbuf -oL segalign $ref_path $query_path "${DATA_FOLDER}/" "$@" ) # segalign begins running in this line,
101 } 1>&2 # and every newline written to stdout, get assigned to $line which
102 # gets sent to diagonal_partition for diagonal partitioning
103
104 exit 0
105