Skip to content

Commit 40db9a5

Browse files
committed
Update igv_files_to_session.py script
1 parent 80fd01c commit 40db9a5

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

bin/igv_files_to_session.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
argParser.add_argument(
2727
"LIST_FILE", help="Tab-delimited file containing two columns i.e. file_name\tcolour. Header isnt required."
2828
)
29+
argParser.add_argument(
30+
"REPLACE_FILE", help="Tab-delimited file containing two columns i.e. file_name\treplacement_file_name. Header isnt required."
31+
)
2932
argParser.add_argument(
3033
"GENOME", help="Full path to genome fasta file or shorthand for genome available in IGV e.g. hg19."
3134
)
@@ -65,10 +68,21 @@ def makedir(path):
6568
############################################
6669

6770

68-
def igv_files_to_session(XMLOut, ListFile, Genome, PathPrefix=""):
71+
def igv_files_to_session(XMLOut, ListFile, ReplaceFile, Genome, PathPrefix=""):
6972

7073
makedir(os.path.dirname(XMLOut))
7174

75+
replaceFileDict = {}
76+
fin = open(ReplaceFile, "r")
77+
while True:
78+
line = fin.readline()
79+
if line:
80+
ofile, rfile = line.strip().split("\t")
81+
replaceFileDict[ofile] = rfile
82+
else:
83+
break
84+
fin.close()
85+
7286
fileList = []
7387
fin = open(ListFile, "r")
7488
while True:
@@ -77,10 +91,18 @@ def igv_files_to_session(XMLOut, ListFile, Genome, PathPrefix=""):
7791
ifile, colour = line.strip().split("\t")
7892
if len(colour.strip()) == 0:
7993
colour = "0,0,178"
94+
for ofile,rfile in replaceFileDict.items():
95+
if ofile in ifile:
96+
ifile = ifile.replace(ofile, rfile)
8097
fileList.append((PathPrefix.strip() + ifile, colour))
8198
else:
8299
break
83-
fout.close()
100+
fin.close()
101+
102+
fout = open('igv_files.txt', "w")
103+
for ifile, colour in fileList:
104+
fout.write(ifile + '\n')
105+
fout.close()
84106

85107
## ADD RESOURCES SECTION
86108
XMLStr = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n'
@@ -153,7 +175,7 @@ def igv_files_to_session(XMLOut, ListFile, Genome, PathPrefix=""):
153175
############################################
154176
############################################
155177

156-
igv_files_to_session(XMLOut=args.XML_OUT, ListFile=args.LIST_FILE, Genome=args.GENOME, PathPrefix=args.PATH_PREFIX)
178+
igv_files_to_session(XMLOut=args.XML_OUT, ListFile=args.LIST_FILE, ReplaceFile=args.REPLACE_FILE, Genome=args.GENOME, PathPrefix=args.PATH_PREFIX)
157179

158180
############################################
159181
############################################

0 commit comments

Comments
 (0)