-
Notifications
You must be signed in to change notification settings - Fork 0
/
arcasHLA.py
83 lines (55 loc) · 2.06 KB
/
arcasHLA.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
import os
from Config import Config
from datetime import datetime
class arcasHLA:
def __init__(self, BAM, config, log, prefix, outDir):
self.BAM = BAM
self.config = config
self.log = log
self.prefix = prefix
self.outDir = outDir
def return_BAM(self):
return str(self.BAM)
def return_prefix(self):
return str(self.prefix)
def return_outDir(self):
return str(self.outDir)
def return_log(self):
return str(self.log)
#If directory to run arcas does not exists, create it!
def exists_directory(self, directory):
try:
os.mkdir(directory)
except:
print ('Directory already exists ' + directory)
def arcasHLA_log(self, cmd):
#Check if log directory exists
logfile = self.return_log()
try :
os.mkdir(logfile)
except :
print ("LOG exists")
#Make arcaslog file
try:
with open(logfile + "/arcasHLA.log", "w") as outfile:
ts = datetime.now()
outfile.write(str(ts) + '>> Running ' + cmd )
except IOError:
print ('Cannot open file ' + outfile)
#Return values from config file
def return_config(self):
config = Config(self.config)
#Find where is arcasHLA location
arcas = config.find_in_config('arcasHLA', 'arcasHLA')
return str(arcas)
#First step of arcasHLA
def test_arcas(self):
cmd = self.return_config() + ' ' + self.return_BAM() + ' -o ' + self.return_prefix() + ' --paired -t 8'
print (cmd)
arcasHLA_dir = self.return_outDir() + '/' + self.return_prefix()
self.exists_directory(arcasHLA_dir)
return (cmd)
#Second step of arcasHLA
def typing_arcas(self):
cmd = self.return_config + ' genotype ' + self.return_fastq1() + ' ' + self.return_fastq2() + ' -g A,B,C,DPB1,DQB1,DQA1,DRB1 -o ' + self.return_prefix() + ' -t 8 -v'
print (cmd)