-
Notifications
You must be signed in to change notification settings - Fork 4
/
collateAllRepGeneCover.py
executable file
·80 lines (68 loc) · 2.19 KB
/
collateAllRepGeneCover.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
#!/bin/env python
'''
collateAllRepGeneCover.py
Copyright (c) 2015, David Edwards, Bernie Pope, Kat Holt
All rights reserved. (see README.txt for more details)
Takes a coverage and average depth output divided by replicon__gene, and named
after each isolate, and converts them to a coverage matrix and average depth matrix,
divided by replicon__gene and strain.
example:
python collateAllGeneCover.py <inputDir> <outputDir> refName sequences_string
Created: 27/5/2013
Modified: 21/07/2014
author: David Edwards
'''
import sys, glob
from pipe_utils import splitPath
inPath = sys.argv[1]
outPath = sys.argv[2]
refName = sys.argv[3]
sequences_string = sys.argv[4]
sequences = sequences_string.split(',')
coverFiles = []
for sequence in sequences:
if sequence != '':
coverFiles.append((inPath+sequence+'/'+sequence+'_CoverDepthMatrix.txt'))
output = "replicon__gene"
outCover = outPath + refName + "_CoverMatrix.csv"
outDepth = outPath + refName + "_DepthMatrix.csv"
geneList = []
coverList = []
depthList = []
first_file = True
for file in coverFiles:
(prefix, name, ext) = splitPath(file)
output = output + "," + name[:-17]
coverFile = open(file)
count = 0
for line in coverFile:
if line.find('\n') != -1:
line = line[:-1]
cover = line.split(',')
if first_file == True:
geneList.append(cover[0])
coverList.append([])
depthList.append([])
coverList[count].append(cover[1])
depthList[count].append(cover[2])
count += 1
coverFile.close()
first_file = False
output = output + "\n"
outCoverMatrix = open(outCover, "w")
outDepthMatrix = open(outDepth, "w")
outCoverMatrix.write(output)
outDepthMatrix.write(output)
for gene in range(len(geneList)):
outputCover = geneList[gene]
outputDepth = geneList[gene]
for j in range(len(coverList[gene])):
outputCover = outputCover + "," + coverList[gene][j]
for j in range(len(depthList[gene])):
outputDepth = outputDepth + "," + depthList[gene][j]
outputCover += "\n"
outputDepth += "\n"
outCoverMatrix.write(outputCover)
outDepthMatrix.write(outputDepth)
outCoverMatrix.close()
outDepthMatrix.close()