This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
perform_exhaustive_testing
executable file
·220 lines (184 loc) · 13.9 KB
/
perform_exhaustive_testing
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#! /usr/bin/env python3
#####################################################################################################################################################################
#
# A standalone script created for the purpose of testing abridge
# Script does not take any inputs and all the required information is hard coded intentionally to prevent it from being accidentally executed in the future
# Script will also perform download and alignment of all sequences
# Can be executed without any changes on Ceres
#
# Tests carried out by this script:
# - 2 types of STAR alignments - one with
#
#####################################################################################################################################################################
import os
import sys
import multiprocessing
import time
CPU = 1
def runDockerCommand( name, version, image_location, container_name, volumes, command , cpus = 1, memory = '1g' ):
"""
Runs the command in a docker container
"""
# Runs the main command
docker_cmd = f" docker run "
# docker_cmd += f" -ti "
docker_cmd += f" --rm "
docker_cmd += f" --cpus={cpus}"
docker_cmd += f" --memory='{memory}'"
# docker_cmd += f" --name {container_name}"
for mapping in volumes:
docker_cmd += f" -v {mapping}"
docker_cmd += f" {image_location}:{version} "
docker_cmd += f" bash -c '{command}'"
#logging.info( f"Running command - {docker_cmd}" )
os.system( docker_cmd )
def runSingularityCommand(name, version, image_location, container_name, volumes, command , cpus = 1, memory = '1g' ):
"""
Runs the command in a Singularity container
"""
# Runs the main command
if "sratools" not in image_location:
singularity_cmd = f" singularity exec "
for mapping in volumes:
singularity_cmd += f" -B {mapping}"
singularity_cmd += f" {image_location} "
singularity_cmd += f" bash -c '{command}'"
else:
singularity_cmd = f" singularity exec "
for mapping in volumes:
singularity_cmd += f" -B {mapping}"
singularity_cmd += f" {image_location} "
singularity_cmd += f" {command}"
print( f"Running command - {singularity_cmd}" )
sys.stdout.flush()
os.system( singularity_cmd )
def executeCommand(framework_of_choice, software, version, volumes_list, singularity_sif_location, cmd1):
"""
Executes the command within the requested framework
"""
if framework_of_choice == "docker":
runDockerCommand(
name = software,
version = version,
image_location = f"ghcr.io/sagnikbanerjee15/dockerized_tools_and_pipelines/{software}",
container_name = f"{software}",
volumes = volumes_list,
command = cmd1,
cpus = CPU,
memory = '1g'
)
elif framework_of_choice == "singularity":
runSingularityCommand(
name = software,
version = version,
image_location = singularity_sif_location,
container_name = f"{software}",
volumes = volumes_list,
command = cmd1,
cpus = CPU,
memory = '1g'
)
def runCommand( eachinput ):
Run, cmd1, cmd2 = eachinput
if "<" not in cmd1:
os.system( cmd1 )
os.system( cmd2 )
else:
subprocess.check_call( ['bash', '-c', cmd1] )
subprocess.check_call( ['bash', '-c', cmd2] )
def main():
OUTPUT_DIRECTORY_MAIN = "/project/maizegdb/sagnik/ABRIDGE/testing"
OUTPUT_DIRECTORY_TEMP = "/90daydata/maizegdb/sagnik/ABRIDGE/testing"
sra_id = "SRR13711353"
pool = multiprocessing.Pool( processes = int( CPU ) )
########################################################################################################################
# Compress
########################################################################################################################
allinputs = []
for ended in ["SE","PE"]:
for alignment_type in ["all_tags_sorted", "no_tags_unsorted"]:
alignment_filename = f"{OUTPUT_DIRECTORY_MAIN}/alignments/{sra_id}_{ended}_{alignment_type}_1.sam"
for ignore_alignment_scores in [0, 1]:
for ignore_all_quality_scores in [0, 1]:
for ignore_quality_scores_for_matched_bases in [0, 1]:
for ignore_soft_clippings in [0, 1]:
for ignore_mismatches in [0, 1]:
for ignore_unmapped_reads in [0, 1]:
for skip_shortening_read_names in [0, 1]:
output_directory_main = f"{OUTPUT_DIRECTORY_MAIN}/abridge_compressed/{sra_id}_{ended}_{alignment_type}_i_align_sc_{ignore_alignment_scores}_i_all_qual_sc_{ignore_all_quality_scores}_i_qual_sc_matched_bases_{ignore_quality_scores_for_matched_bases}_i_soft_clippings_{ignore_soft_clippings}_i_mismatches_{ignore_mismatches}_i_unmapped_reads_{ignore_unmapped_reads}_skip_shrtnng_rn_{skip_shortening_read_names}"
output_directory_temp = f"{OUTPUT_DIRECTORY_TEMP}/abridge_compressed/{sra_id}_{ended}_{alignment_type}_i_align_sc_{ignore_alignment_scores}_i_all_qual_sc_{ignore_all_quality_scores}_i_qual_sc_matched_bases_{ignore_quality_scores_for_matched_bases}_i_soft_clippings_{ignore_soft_clippings}_i_mismatches_{ignore_mismatches}_i_unmapped_reads_{ignore_unmapped_reads}_skip_shrtnng_rn_{skip_shortening_read_names}"
cmd1 = f" /project/maizegdb/sagnik/ABRIDGE/Abridge/abridge "
cmd1 += f" --compress "
if ignore_alignment_scores == 1:
cmd1 += f" --ignore_alignment_scores "
if ignore_all_quality_scores == 1:
cmd1 += f" --ignore_all_quality_scores "
if ignore_quality_scores_for_matched_bases == 1:
cmd1 += f" --ignore_quality_scores_for_matched_bases "
if ignore_soft_clippings == 1:
cmd1 += " --ignore_soft_clippings "
if ignore_mismatches == 1:
cmd1 += " --ignore_mismatches "
if ignore_unmapped_reads == 1:
cmd1 += " --ignore_unmapped_reads "
if skip_shortening_read_names == 1:
cmd1 += f" --skip_shortening_read_names "
cmd1 += f" --inputalignedfilename {alignment_filename} "
cmd1 += f" --genome /project/maizegdb/sagnik/ABRIDGE/testing/reference/Arabidopsis_thaliana.TAIR10.dna.toplevel.fa "
cmd1 += f" --keep_intermediate_error_files "
cmd1 += f" --preserve_all_intermediate_files "
cmd1 += f" --output_directory {output_directory_main}"
cmd1 += f" --software_directory /project/maizegdb/sagnik/ABRIDGE/testing/singularity_images"
cmd1 += f" 1> {output_directory_main}.output "
cmd1 += f" 2> {output_directory_main}.error"
if os.path.exists(f"{output_directory_main}/{sra_id}_{ended}_{alignment_type}.abridge") == False and os.path.exists(f"{output_directory_temp}/{sra_id}_{ended}_{alignment_type}.abridge") == False:
os.system(f"rm -rf {output_directory_temp}")
cmd2 = f"mv {output_directory_main} {OUTPUT_DIRECTORY_TEMP}/abridge_compressed"
allinputs.append( ["dummy", cmd1, cmd2] )
pool.map( runCommand, allinputs )
return
########################################################################################################################
# Decompress
########################################################################################################################
allinputs = []
os.chdir(f"{OUTPUT_DIRECTORY_MAIN}/abridge_decompressed")
for ended in ["SE","PE"]:
for alignment_type in ["all_tags_sorted", "no_tags_unsorted"]:
alignment_filename = f"{OUTPUT_DIRECTORY_MAIN}/alignments/{sra_id}_{ended}_{alignment_type}.sam"
for ignore_alignment_scores in [0, 1]:
for ignore_all_quality_scores in [0, 1]:
for ignore_quality_scores_for_matched_bases in [0, 1]:
for ignore_soft_clippings in [0, 1]:
for ignore_mismatches in [0, 1]:
for ignore_unmapped_reads in [0, 1]:
for skip_shortening_read_names in [0, 1]:
for quality in [0, 1]:
for ignore_sequence in [0, 1]:
output_directory_main = f"{OUTPUT_DIRECTORY_MAIN}/abridge_decompressed/{sra_id}_{ended}_{alignment_type}_i_align_sc_{ignore_alignment_scores}_i_all_qual_sc_{ignore_all_quality_scores}_i_qual_sc_matched_bases_{ignore_quality_scores_for_matched_bases}_i_soft_clippings_{ignore_soft_clippings}_i_mismatches_{ignore_mismatches}_i_unmapped_reads_{ignore_unmapped_reads}_skip_shrtnng_rn_{skip_shortening_read_names}_quality_{quality}_i_seq_{ignore_sequence}"
output_directory_temp = f"{OUTPUT_DIRECTORY_TEMP}/abridge_decompressed/{sra_id}_{ended}_{alignment_type}_i_align_sc_{ignore_alignment_scores}_i_all_qual_sc_{ignore_all_quality_scores}_i_qual_sc_matched_bases_{ignore_quality_scores_for_matched_bases}_i_soft_clippings_{ignore_soft_clippings}_i_mismatches_{ignore_mismatches}_i_unmapped_reads_{ignore_unmapped_reads}_skip_shrtnng_rn_{skip_shortening_read_names}_quality_{quality}_i_seq_{ignore_sequence}"
compressed_filename = f"{OUTPUT_DIRECTORY_TEMP}/abridge_compressed/{sra_id}_{ended}_{alignment_type}_i_align_sc_{ignore_alignment_scores}_i_all_qual_sc_{ignore_all_quality_scores}_i_qual_sc_matched_bases_{ignore_quality_scores_for_matched_bases}_i_soft_clippings_{ignore_soft_clippings}_i_mismatches_{ignore_mismatches}_i_unmapped_reads_{ignore_unmapped_reads}_skip_shrtnng_rn_{skip_shortening_read_names}/{sra_id}_{ended}_{alignment_type}.abridge"
cmd1 = f" /project/maizegdb/sagnik/ABRIDGE/Abridge/abridge "
cmd1 += f" --decompress "
cmd1 += f" --inputabrfilename {compressed_filename} "
cmd1 += f" --genome /project/maizegdb/sagnik/ABRIDGE/testing/reference/Arabidopsis_thaliana.TAIR10.dna.toplevel.fa "
cmd1 += f" --keep_intermediate_error_files "
cmd1 += f" --preserve_all_intermediate_files "
cmd1 += f" --output_directory {output_directory_main}"
if quality == 1:
cmd1 += f" --quality C "
if ignore_sequence == 1:
cmd1 += f" --ignore_sequence "
cmd1 += f" --software_directory /project/maizegdb/sagnik/ABRIDGE/testing/singularity_images"
cmd1 += f" 1> {output_directory_main}.output "
cmd1 += f" 2> {output_directory_main}.error"
#print(f"{output_directory_temp}/{sra_id}_{ended}_{alignment_type[:-3]}_decompressed.sam")
if os.path.exists(f"{output_directory_main}/{sra_id}_{ended}_{alignment_type[:-4]}_decompressed.sam") == False and os.path.exists(f"{output_directory_temp}/{sra_id}_{ended}_{alignment_type[:-4]}_decompressed.sam") == False:
#present_working_directory = os.getcwd()
#os.chdir(output_directory_temp)
os.system(f"rm -rf {output_directory_temp}")
cmd2 = f"mv {output_directory_main} {OUTPUT_DIRECTORY_TEMP}/abridge_decompressed"
allinputs.append( ["dummy", cmd1, cmd2] )
pool.map( runCommand, allinputs )
#print(len(allinputs))
if __name__ == "__main__":
main()