1717############################################
1818
1919Description = 'Create IGV session file from a list of files and associated colours - ".bed", ".bw", ".bigwig", ".tdf", ".gtf" files currently supported.'
20- Epilog = """Example usage: python igv_files_to_session.py <XML_OUT> <LIST_FILE> <GENOME>"""
20+ Epilog = (
21+ """Example usage: python igv_files_to_session.py <XML_OUT> <LIST_FILE> <GENOME>"""
22+ )
2123
2224argParser = argparse .ArgumentParser (description = Description , epilog = Epilog )
2325
2426## REQUIRED PARAMETERS
2527argParser .add_argument ("XML_OUT" , help = "XML output file." )
2628argParser .add_argument (
27- "LIST_FILE" , help = "Tab-delimited file containing two columns i.e. file_name\t colour. Header isnt required."
29+ "LIST_FILE" ,
30+ help = "Tab-delimited file containing two columns i.e. file_name\t colour. Header isnt required." ,
2831)
2932argParser .add_argument (
30- "REPLACE_FILE" , help = "Tab-delimited file containing two columns i.e. file_name\t replacement_file_name. Header isnt required."
33+ "REPLACE_FILE" ,
34+ help = "Tab-delimited file containing two columns i.e. file_name\t replacement_file_name. Header isnt required." ,
3135)
3236argParser .add_argument (
33- "GENOME" , help = "Full path to genome fasta file or shorthand for genome available in IGV e.g. hg19."
37+ "GENOME" ,
38+ help = "Full path to genome fasta file or shorthand for genome available in IGV e.g. hg19." ,
3439)
3540
3641## OPTIONAL PARAMETERS
@@ -82,7 +87,6 @@ def igv_files_to_session(XMLOut, ListFile, ReplaceFile, Genome, PathPrefix=""):
8287 else :
8388 break
8489 fin .close ()
85-
8690 fileList = []
8791 fin = open (ListFile , "r" )
8892 while True :
@@ -91,22 +95,24 @@ def igv_files_to_session(XMLOut, ListFile, ReplaceFile, Genome, PathPrefix=""):
9195 ifile , colour = line .strip ().split ("\t " )
9296 if len (colour .strip ()) == 0 :
9397 colour = "0,0,178"
94- for ofile ,rfile in replaceFileDict .items ():
98+ for ofile , rfile in replaceFileDict .items ():
9599 if ofile in ifile :
96100 ifile = ifile .replace (ofile , rfile )
97101 fileList .append ((PathPrefix .strip () + ifile , colour ))
98102 else :
99103 break
100104 fin .close ()
101-
102- fout = open ('igv_files.txt' , "w" )
105+ fout = open ("igv_files.txt" , "w" )
103106 for ifile , colour in fileList :
104- fout .write (ifile + ' \n ' )
107+ fout .write (ifile + " \n " )
105108 fout .close ()
106109
107110 ## ADD RESOURCES SECTION
108111 XMLStr = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n '
109- XMLStr += '<Session genome="%s" hasGeneTrack="true" hasSequenceTrack="true" locus="All" version="8">\n ' % (Genome )
112+ XMLStr += (
113+ '<Session genome="%s" hasGeneTrack="true" hasSequenceTrack="true" locus="All" version="8">\n '
114+ % (Genome )
115+ )
110116 XMLStr += "\t <Resources>\n "
111117 for ifile , colour in fileList :
112118 XMLStr += '\t \t <Resource path="%s"/>\n ' % (ifile )
@@ -143,7 +149,9 @@ def igv_files_to_session(XMLOut, ListFile, ReplaceFile, Genome, PathPrefix=""):
143149 '\t \t <Track altColor="0,0,178" autoScale="false" clazz="org.broad.igv.track.FeatureTrack" color="%s" '
144150 % (colour )
145151 )
146- XMLStr += 'displayMode="COLLAPSED" featureVisibilityWindow="-1" fontSize="10" '
152+ XMLStr += (
153+ 'displayMode="COLLAPSED" featureVisibilityWindow="-1" fontSize="10" '
154+ )
147155 XMLStr += (
148156 'id="%s" name="%s" renderer="BASIC_FEATURE" sortable="false" visible="true" windowFunction="count"/>\n '
149157 % (ifile , os .path .basename (ifile ))
@@ -160,7 +168,6 @@ def igv_files_to_session(XMLOut, ListFile, ReplaceFile, Genome, PathPrefix=""):
160168 'id="%s" name="%s" renderer="BASIC_FEATURE" sortable="false" visible="true" windowFunction="count"/>\n '
161169 % (ifile , os .path .basename (ifile ))
162170 )
163-
164171 XMLStr += "\t </Panel>\n "
165172 # XMLStr += '\t<HiddenAttributes>\n\t\t<Attribute name="DATA FILE"/>\n\t\t<Attribute name="DATA TYPE"/>\n\t\t<Attribute name="NAME"/>\n\t</HiddenAttributes>\n'
166173 XMLStr += "</Session>"
@@ -175,7 +182,13 @@ def igv_files_to_session(XMLOut, ListFile, ReplaceFile, Genome, PathPrefix=""):
175182############################################
176183############################################
177184
178- igv_files_to_session (XMLOut = args .XML_OUT , ListFile = args .LIST_FILE , ReplaceFile = args .REPLACE_FILE , Genome = args .GENOME , PathPrefix = args .PATH_PREFIX )
185+ igv_files_to_session (
186+ XMLOut = args .XML_OUT ,
187+ ListFile = args .LIST_FILE ,
188+ ReplaceFile = args .REPLACE_FILE ,
189+ Genome = args .GENOME ,
190+ PathPrefix = args .PATH_PREFIX ,
191+ )
179192
180193############################################
181194############################################
0 commit comments