0
|
1 # ----------------------------------------------------------------------#
|
|
2 # Copyright (c) 2011, Richard Lupat & Jason Li.
|
|
3 #
|
|
4 # > Source License <
|
|
5 # This file is part of CONTRA.
|
|
6 #
|
|
7 # CONTRA is free software: you can redistribute it and/or modify
|
|
8 # it under the terms of the GNU General Public License as published by
|
|
9 # the Free Software Foundation, either version 3 of the License, or
|
|
10 # (at your option) any later version.
|
|
11 #
|
|
12 # CONTRA is distributed in the hope that it will be useful,
|
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 # GNU General Public License for more details.
|
|
16 #
|
|
17 # You should have received a copy of the GNU General Public License
|
|
18 # along with CONTRA. If not, see <http://www.gnu.org/licenses/>.
|
|
19 #
|
|
20 #
|
|
21 #-----------------------------------------------------------------------#
|
|
22 # Last Updated : 03 Sep 2011 15:00PM
|
|
23
|
|
24
|
|
25 import os
|
|
26
|
|
27 def splitByChromosome(destFolder):
|
|
28
|
|
29 try:
|
|
30 os.mkdir(destFolder + "chr/")
|
|
31 except:
|
|
32 print "folder exist"
|
|
33
|
|
34 inputfile = destFolder + "sample.BEDGRAPH"
|
|
35 outputfile = destFolder + "chr/chr1.txt"
|
|
36 file = open(inputfile,"r")
|
|
37 output = open(outputfile,"w")
|
|
38 check = "1"
|
|
39
|
|
40 for row in file:
|
|
41 if row[0] == '#':
|
|
42 continue
|
|
43
|
|
44 cols = row.split()
|
|
45 chr = cols[0].strip("chr")
|
|
46 if (chr != check):
|
|
47 output.close()
|
|
48 check = chr
|
|
49 output = open(destFolder+ "chr/chr"+check+".txt","w")
|
|
50 output.write(row)
|
|
51
|
|
52 output.close()
|
|
53
|
|
54 #JLMod
|
|
55 def splitByChromosome3(infile):
|
|
56 destFolder = os.path.dirname(infile)+"/"
|
|
57
|
|
58 try:
|
|
59 os.mkdir(destFolder + "chr/")
|
|
60 except:
|
|
61 print "folder exist"
|
|
62
|
|
63 #inputfile = destFolder + "sample.BEDGRAPH"
|
|
64 inputfile=infile
|
|
65 outputfile = destFolder + "chr/chr1.txt"
|
|
66 file = open(inputfile,"r")
|
|
67 output = open(outputfile,"w")
|
|
68 check = "1"
|
|
69
|
|
70 for row in file:
|
|
71 cols = row.split()
|
|
72 chr = cols[0].strip("chr")
|
|
73 if (chr != check):
|
|
74 output.close()
|
|
75 check = chr
|
|
76 output = open(destFolder+ "chr/chr"+check+".txt","w")
|
|
77 output.write(row)
|
|
78
|
|
79 output.close()
|
|
80
|
|
81 def splitByChromosome2(folder):
|
|
82
|
|
83 try:
|
|
84 os.mkdir(folder + "target/")
|
|
85 except:
|
|
86 print "folder exist"
|
|
87
|
|
88 inputfile = folder + "geneRefCoverage.txt"
|
|
89 outputfile = folder + "target/chr1.txt"
|
|
90 file = open(inputfile,"r")
|
|
91 output = open(outputfile,"w")
|
|
92 check = "1"
|
|
93
|
|
94 for row in file:
|
|
95 cols = row.split()
|
|
96 chr = cols[0].strip("chr")
|
|
97 if (chr != check):
|
|
98 output.close()
|
|
99 check = chr
|
|
100 output = open(folder+ "target/chr"+check+".txt","w")
|
|
101 output.write(row)
|
|
102
|
|
103 output.close()
|
|
104
|
|
105
|