-
Notifications
You must be signed in to change notification settings - Fork 1
/
SeparateByChrom.py
77 lines (66 loc) · 2.07 KB
/
SeparateByChrom.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
#!/usr/bin/env python
# Copyright (c) 2007 NHLBI, NIH
# Authors: Dustin E Schones and Keji Zhao
#
# This software is distributable under the terms of the GNU General
# Public License (GPL) v2, the text of which can be found at
# http://www.gnu.org/copyleft/gpl.html. Installing, importing or
# otherwise using this module constitutes acceptance of the terms of
# this License.
#
# Disclaimer
#
# This software 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.
#
# Comments and/or additions are welcome (send e-mail to:
import re, os, sys, shutil
from math import *
from string import *
from optparse import OptionParser
import operator
import Utility
grep = "grep";
cat = "cat";
#grep = "/bin/grep";
#cat = "/bin/cat";
plus = re.compile("\+");
minus = re.compile("\-");
def separateByChrom(chroms, file, extension):
for chrom in chroms:
match = chrom + "[[:space:]]";
tmpFile = chrom + extension;
try:
if os.system('%s %s %s > %s' %
(grep, match, file, tmpFile)): raise
except: sys.stderr.write( str(chrom) + " reads do not exist in " + str(file) + "\n");
def combineAllGraphFiles(chroms, extension, final_out):
"""
Combine the seperately processed chromosomes, return the output file name
"""
outfile = open(final_out,'w');
outfile.close();
for chrom in chroms:
file = chrom + extension;
if Utility.fileExists(file):
try:
if os.system('%s %s >> %s' %
(cat, file, final_out)): raise
except:
sys.stderr.write( "")
# sys.stderr.write("cat failed\n")
else:
print file, " file does not exist."
return final_out
def cleanup(chroms, extension):
for chrom in chroms:
file = chrom + extension;
try:
if os.remove('%s' %
(file)): raise
except:
sys.stderr.write("")
# sys.stderr.write("clean up failed\n");