-
Notifications
You must be signed in to change notification settings - Fork 1
/
sleuth.py
executable file
·109 lines (71 loc) · 3.35 KB
/
sleuth.py
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
#!/usr/bin/env python3
#############################################################################
# Copyright 2020 Simon Andrews
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
############################################################################
import argparse
import os
import subprocess
import sys
VERSION = 1.2
def process_file(options):
if not options.quiet:
print(f"Calling SNPs on {options.bamfile}")
outfile = run_snp_calling(options)
if not options.quiet:
print(f"Drawing graph")
draw_graph(outfile,options)
def run_snp_calling(options):
# Find the current location so we can set the classpath
current = os.path.dirname(os.path.realpath(__file__))
classpath = [current, current+"/htsjdk.jar", current+"/commons_compress.jar"]
joined_classpath = ":".join(classpath)
if sys.platform.startswith("win"):
joined_classpath = ";".join(classpath)
outfile = options.bamfile
if outfile.endswith(".bam"):
outfile = outfile[:-4]
outfile = outfile+"_sleuth.txt"
quiet_value = "false"
if options.quiet:
quiet_value = "true"
command_options = [options.java,"-cp",joined_classpath,f'-Dquiet={quiet_value}',"uk/ac/babraham/CellLineSleuth/CellLineSleuthApplication",options.snpfile, options.bamfile,outfile]
#print(f"Command options are {command_options}")
subprocess.run(command_options, check=True)
return outfile
def draw_graph(infile, options):
current = os.path.dirname(os.path.realpath(__file__))
format = "png"
if options.svg:
format = "svg"
subprocess.run([options.rscript,current+"/R/create_sleuth_graph.R",infile,format], check=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def read_options():
parser = argparse.ArgumentParser(description="Identify human cell lines")
parser.add_argument('--quiet', dest="quiet", action='store_true', default=False, help="Supress all but essential messages")
parser.add_argument('--version', action='version', version=f"Cell Line Sleuth v{VERSION}")
parser.add_argument('--java', type=str, help="Location of the java binary", default="java")
parser.add_argument('--rscript', type=str, help="Location of the Rscript binary", default="Rscript")
parser.add_argument('--svg', dest="svg", action='store_true', default=False, help="Write graph in SVG format")
parser.add_argument('snpfile', type=str, help="The SNP file generated by cosmic_diagnosic_snps.py")
parser.add_argument('bamfile', type=str, help="The BAM file aligned to GRCh38 to analyse")
options = parser.parse_args()
#TODO: Test java and R
return options
def main():
options = read_options()
process_file(options)
if __name__ == "__main__":
main()