forked from raphael-group/hierarchical-hotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hhn.sh
172 lines (141 loc) · 5.33 KB
/
hhn.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/usr/bin/env bash
# Initialize variables
scores=""
edges=""
index=""
output_file=""
# data=$PWD/data
intermediate="/HHN/intermediate"
results="/HHN/results"
num_permutations=100
# Parse command-line options
while getopts ":s:e:i:o:" opt; do
case $opt in
s) scores="$OPTARG" ;;
e) edges="$OPTARG" ;;
i) index="$OPTARG" ;;
o) output_file="$OPTARG" ;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;;
:) echo "Option -$OPTARG requires an argument." >&2; exit 1 ;;
esac
done
# Check if required options are provided
if [ -z "$scores" ] || [ -z "$edges" ] || [ -z "$index" ] || [ -z "$output_file" ]; then
echo "Usage: $0 -s <scores> -e <edges> -i <index> -o <output_file>"
exit 1
fi
# Hierarchical HotNet is parallelizable, but this script runs each Hierarchical
# HotNet sequentially. Please see the example_commands_parallel.sh script for a
# parallelized example.
# Compile Fortran module.
cd /HHN/src
f2py -c fortran_module.f95 -m fortran_module > /dev/null
cd ..
################################################################################
#
# Prepare data.
#
################################################################################
# Create data, intermediate data and results, and results directories.
# mkdir --p "$data"
mkdir -p "$intermediate"
mkdir -p "$results"
# Create directories for network
mkdir -p "$intermediate/network"
# Create directories for network and scores
mkdir -p "$intermediate/network_score"
################################################################################
#
# Construct similarity matrices.
#
################################################################################
python src/construct_similarity_matrix.py \
-i "$edges" \
-o "$intermediate/network/similarity_matrix.h5" \
-bof "$intermediate/network/beta.txt"
################################################################################
#
# Permute data.
#
################################################################################
# This example does not use permuted networks, but these commands show how to
# generate them.
echo "Permuting networks..."
cp "$index" "$intermediate/network/index_gene_0.tsv"
cp "$edges" "$intermediate/network/edge_list_0.tsv"
# Preserve connectivity of the observed graph.
for i in `seq 1 4`; do
python src/permute_network.py \
-i "$intermediate/network/edge_list_0.tsv" \
-s "$i" \
-c \
-o "$intermediate/network/edge_list_${i}.tsv"
done
# Do not preserve connectivity of the observed graph.
for i in `seq 5 8`; do
python src/permute_network.py \
-i "$intermediate/network/edge_list_0.tsv" \
-s "$i" \
-o "$intermediate/network/edge_list_${i}.tsv"
done
echo "Permuting scores..."
cp "$scores" "$intermediate/network_score/scores_0.tsv"
python src/find_permutation_bins.py \
-gsf "$intermediate/network_score/scores_0.tsv" \
-igf "$index" \
-elf "$edges" \
-ms 1000 \
-o "$intermediate/network_score/score_bins.tsv"
for i in `seq $num_permutations`; do
python src/permute_scores.py \
-i "$intermediate/network_score/scores_0.tsv" \
-bf "$intermediate/network_score/score_bins.tsv" \
-s "$i" \
-o "$intermediate/network_score/scores_${i}.tsv"
done
################################################################################
#
# Construct hierarchies.
#
################################################################################
echo "Constructing hierarchies..."
for i in $(seq 0 $num_permutations); do
python src/construct_hierarchy.py \
-smf "$intermediate/network/similarity_matrix.h5" \
-igf "$index" \
-gsf "$intermediate/network_score/scores_${i}.tsv" \
-helf "$intermediate/network_score/hierarchy_edge_list_${i}.tsv" \
-higf "$intermediate/network_score/hierarchy_index_gene_${i}.tsv"
done
################################################################################
#
# Process hierarchies.
#
################################################################################
echo "Processing hierarchies..."
# This example uses -lsb/--lower_size_bound 1 because it is a small toy example
# with 25 vertices. Use larger value (default is 10) for larger graphs.
python src/process_hierarchies.py \
-oelf "$intermediate/network_score/hierarchy_edge_list_0.tsv" \
-oigf "$intermediate/network_score/hierarchy_index_gene_0.tsv" \
-pelf $(for i in $(seq $num_permutations); do echo "$intermediate/network_score/hierarchy_edge_list_${i}.tsv "; done) \
-pigf $(for i in $(seq $num_permutations); do echo "$intermediate/network_score/hierarchy_index_gene_${i}.tsv "; done) \
-lsb 1 \
-cf "$results/clusters_network_scores.tsv" \
-pl "network" "score" \
-pf "$results/sizes_network_score.pdf"
################################################################################
#
# Perform consensus.
#
################################################################################
echo "Performing consensus..."
python src/perform_consensus.py \
-cf "$results/clusters_network_scores.tsv" "$results/clusters_network_scores.tsv" \
-igf $index $index \
-elf $edges $edges \
-n "network" "network" \
-s "score" "score" \
-t 2 \
-cnf $results/consensus_nodes.tsv \
-cef $output_file