Mercurial > repos > refinery-platform > qualimap2_bamqc
annotate qualimap_bamqc.py @ 6:a2438e0f1bbf draft default tip
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 40f39b0f1c81cae4606d15d1c0bd318b1e4c572d
author | refinery-platform |
---|---|
date | Mon, 30 Jul 2018 12:18:55 -0400 |
parents | a6d048668f7f |
children |
rev | line source |
---|---|
0
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
1 #!/usr/bin/env python |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
2 from __future__ import print_function |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
3 import argparse |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
4 import os |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
5 from subprocess import check_call, CalledProcessError |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
6 import shutil |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
7 import sys |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
8 |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
9 QUALIMAP_OUPUT_DIR = "qualimap_results" |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
10 |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
11 |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
12 def qualimap_bamqc(bam_filename, jv_mem_size): |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
13 qualimap_command = [ |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
14 "qualimap", "bamqc", |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
15 "-bam " + bam_filename, |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
16 "-outdir " + QUALIMAP_OUPUT_DIR, |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
17 "--java-mem-size=" + jv_mem_size |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
18 ] |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
19 |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
20 try: |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
21 check_call(qualimap_command) |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
22 except CalledProcessError: |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
23 print("Error running the qualimap bamqc", file=sys.stderr) |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
24 |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
25 |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
26 def main(): |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
27 parser = argparse.ArgumentParser( |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
28 description="Generate Bam Quality Statistics" |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
29 ) |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
30 parser.add_argument('--input_file') |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
31 parser.add_argument('--out_dir') |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
32 parser.add_argument('--out_results') |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
33 parser.add_argument('--out_zip') |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
34 parser.add_argument('--java_mem_size') |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
35 |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
36 args = parser.parse_args() |
6
a2438e0f1bbf
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 40f39b0f1c81cae4606d15d1c0bd318b1e4c572d
refinery-platform
parents:
0
diff
changeset
|
37 |
a2438e0f1bbf
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 40f39b0f1c81cae4606d15d1c0bd318b1e4c572d
refinery-platform
parents:
0
diff
changeset
|
38 # Run qualimap |
0
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
39 qualimap_bamqc(args.input_file, args.java_mem_size) |
6
a2438e0f1bbf
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 40f39b0f1c81cae4606d15d1c0bd318b1e4c572d
refinery-platform
parents:
0
diff
changeset
|
40 |
a2438e0f1bbf
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 40f39b0f1c81cae4606d15d1c0bd318b1e4c572d
refinery-platform
parents:
0
diff
changeset
|
41 # Create .zip archive containing the raw_data_qualimapReport files |
0
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
42 shutil.make_archive( |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
43 'raw_data_qualimapReport', |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
44 'zip', |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
45 os.path.join(QUALIMAP_OUPUT_DIR, 'raw_data_qualimapReport') |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
46 ) |
6
a2438e0f1bbf
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 40f39b0f1c81cae4606d15d1c0bd318b1e4c572d
refinery-platform
parents:
0
diff
changeset
|
47 |
a2438e0f1bbf
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 40f39b0f1c81cae4606d15d1c0bd318b1e4c572d
refinery-platform
parents:
0
diff
changeset
|
48 # Move newly created .zip to it's proper Galaxy output file |
0
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
49 shutil.move("raw_data_qualimapReport.zip", args.out_zip) |
6
a2438e0f1bbf
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 40f39b0f1c81cae4606d15d1c0bd318b1e4c572d
refinery-platform
parents:
0
diff
changeset
|
50 |
a2438e0f1bbf
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 40f39b0f1c81cae4606d15d1c0bd318b1e4c572d
refinery-platform
parents:
0
diff
changeset
|
51 # Move genome_results.txt to it's proper Galaxy output file |
0
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
52 shutil.move( |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
53 os.path.join(QUALIMAP_OUPUT_DIR, "genome_results.txt"), |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
54 args.out_results |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
55 ) |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
56 |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
57 if __name__ == "__main__": |
a6d048668f7f
planemo upload for repository https://github.com/refinery-platform/qualimap2 commit 88b5467f336ac3b6b5d3a6e824273a183e5184b6
refinery-platform
parents:
diff
changeset
|
58 main() |