-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcopyjunctions_simple.py
executable file
·91 lines (77 loc) · 3.51 KB
/
copyjunctions_simple.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
### hierarchical_clustering.py
#Copyright 2005-2012 J. David Gladstone Institutes, San Francisco California
#Author Nathan Salomonis - [email protected]
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is furnished
#to do so, subject to the following conditions:
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
#INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
#PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
#OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
#SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#################
### Imports an tab-delimited expression matrix and produces and hierarchically clustered heatmap
#################
# bugs, import matplotlib.colors as mc, -row_method
# new features fastcluster
import export
import string
import time
import sys, os
import shutil
import unique
import getopt
################# General data import methods #################
def filepath(filename):
fn = unique.filepath(filename)
return fn
def cleanUpLine(line):
data = string.replace(line,'\n','')
data = string.replace(data,'\c','')
data = string.replace(data,'\r','')
data = string.replace(data,'"','')
return data
def getFolders(sub_dir):
dir_list = unique.read_directory(sub_dir); dir_list2 = []
###Only get folder names
for entry in dir_list:
if '.' not in entry: dir_list2.append(entry)
return dir_list2
def getFiles(sub_dir):
dir_list = unique.read_directory(sub_dir); dir_list2 = []
###Only get folder names
for entry in dir_list:
if '.' in entry: dir_list2.append(entry)
return dir_list2
def copyJunctionFiles(directory):
root_dir = getFolders(directory)
#print root_dir
for top_level in root_dir: ### e.g.,
try:
files = getFiles(directory+'/'+top_level)
for file in files:
if 'junctions.bed' in file and 'junctionBEDfiles' not in top_level:
source_file = directory+'/'+top_level+'/'+file
source_file = filepath(source_file)
destination_file = directory+'/'+'junctionBEDfiles/'+top_level+'__junctions.bed'
destination_file = filepath(destination_file)
export.copyFile(source_file,destination_file)
print 'copying to:',destination_file
except Exception:
print 'failed to copy', source_file
if __name__ == '__main__':
if len(sys.argv[1:])<=1: ### Indicates that there are insufficient number of command-line arguments
print "Warning! Please designate a BAM file as input in the command-line"
print "Example: python BAMtoJunctionBED.py --i /Users/me/sample1.bam --g /Users/me/human.gtf"
sys.exit()
else:
options, remainder = getopt.getopt(sys.argv[1:],'', ['i=','g=','r='])
for opt, arg in options:
if opt == '--i': directory=arg
try: os.mkdir(directory+'/junctionBEDfiles')
except Exception: pass
copyJunctionFiles(directory)