@@ -28,15 +28,15 @@ def calculateDeletion(PASS):
2828 if float (PASS [key ]) == 0 :
2929 SCORES .append ((key , 'No Data Detected' ))
3030 elif np .isnan (float (PASS [key ])):
31- SCORES .append ((key , 'Region does not meet mappability threshold' ))
31+ SCORES .append ((key , 'Region does not meet mappability threshold' ))
3232 else :
33- SCORES .append ((key , np .log (float (PASS [key ]) / MEDIAN ) / np .log (2 )))
33+ SCORES .append ((key , np .log (float (PASS [key ]) / MEDIAN ) / np .log (2 )))
3434 return SCORES
3535
3636def iterateBAM (bam , bed , READLENGTH , MAP , MAPTHRESH ):
3737 # open BAM file
3838 samfile = pysam .AlignmentFile (bam , "rb" )
39- # open BED file
39+ # open BED file
4040 file = open (bed , "r" )
4141
4242 # Counter of total tags mapping across all intervals
@@ -65,16 +65,16 @@ def iterateBAM(bam, bed, READLENGTH, MAP, MAPTHRESH):
6565 intervalCount [index ] = intervalCount [index ] + 1
6666 totalSize = totalSize + intervalSize
6767
68- # Calculate avg tags per bp across the entire region
68+ # Calculate avg tags per bp across the entire region
6969 intervalAvg = list (map (lambda x : float (x ) / float (intervalSize ), intervalCount ))
70-
71- # Normalize avg reads per interval by mappability
70+
71+ # Normalize avg reads per interval by mappability
7272 for index in range (0 , len (MAP [intervalID ])):
73- if float (MAP [intervalID ][index ]) >= MAPTHRESH :
74- mapAvg [index ] = float (intervalAvg [index ] * intervalCount [index ]) / float (MAP [intervalID ][index ])
75- else :
76- mapAvg [index ] = float ('NaN' )
77-
73+ if float (MAP [intervalID ][index ]) >= MAPTHRESH :
74+ mapAvg [index ] = float (intervalAvg [index ] * intervalCount [index ]) / float (MAP [intervalID ][index ])
75+ else :
76+ mapAvg [index ] = float ('NaN' )
77+
7878 PASS [intervalID ] = (mapAvg , intervalCount )
7979
8080 except (IndexError , ValueError ):
@@ -90,7 +90,7 @@ def iterateBAM(bam, bed, READLENGTH, MAP, MAPTHRESH):
9090 if all (float (x ) < MAPTHRESH for x in MAP [key ]):
9191 normalizedScore = float ('NaN' )
9292 elif sum (PASS [key ][1 ]) != 0 :
93- normalizedScore = np .nansum (PASS [key ][0 ]) / sum (PASS [key ][1 ])
93+ normalizedScore = np .nansum (PASS [key ][0 ]) / sum (PASS [key ][1 ])
9494 else :
9595 normalizedScore = 0
9696 SCORE [key ] = normalizedScore
@@ -99,11 +99,11 @@ def iterateBAM(bam, bed, READLENGTH, MAP, MAPTHRESH):
9999 if float (totalSize ) <= 0 :
100100 print ("ERROR!!!\t Total size of all intervals surveyed is less than 1" )
101101 sys .exit (- 1 )
102-
102+
103103 # Close files
104104 file .close ()
105105 samfile .close ()
106-
106+
107107 return SCORE ,FAIL
108108
109109def closestLength (READLENGTH , read ):
@@ -120,7 +120,7 @@ def loadMap(MAP):
120120 file = open (MAP , "r" )
121121 header = 0 ;
122122 MAP = {}
123- # Iterate BED coord file, getting tag counts across interval
123+ # Iterate BED coord file, getting tag counts across interval
124124 for line in file :
125125 mapline = line .rstrip ().split ("\t " )
126126 if header == 0 :
@@ -140,8 +140,8 @@ def validateBAM(bam):
140140 print ("BAM index not detected.\n Attempting to index now...\n " )
141141 pysam .index (str (bam ))
142142 if not os .path .isfile (bam + ".bai" ):
143- raise RuntimeError ("BAM indexing failed, please check if BAM file is sorted" )
144- return False
143+ raise RuntimeError ("BAM indexing failed, please check if BAM file is sorted" )
144+ return False
145145 print ("BAM index successfully generated.\n " )
146146 return True
147147
@@ -150,9 +150,9 @@ def validateBAM(bam):
150150 if len (sys .argv ) < 2 or not sys .argv [1 ].startswith ("-" ): sys .exit (usage )
151151 BAM = BED = MAP = OUT = ""
152152
153- # Variable to set the mappability threshold so that we do not consider regions with mappability
154- # below this number 0-1, Default to 0.25 meaning at least 25% of the region must be uniquely mappable
155- # by at least one actively used readlength
153+ # Variable to set the mappability threshold so that we do not consider regions with mappability
154+ # below this number 0-1, Default to 0.25 meaning at least 25% of the region must be uniquely mappable
155+ # by at least one actively used readlength
156156 MAPTHRESH = 0.25
157157
158158 OUTPUTTHRESH = - 3
@@ -173,11 +173,11 @@ def validateBAM(bam):
173173 print ("No BAM file detected!!!" )
174174 sys .exit (usage )
175175 elif BED == "" :
176- print ("No BED Coordinate file detected!!!" )
177- sys .exit (usage )
176+ print ("No BED Coordinate file detected!!!" )
177+ sys .exit (usage )
178178 elif MAP == "" :
179- print ("No Mappability file detected!!!" )
180- sys .exit (usage )
179+ print ("No Mappability file detected!!!" )
180+ sys .exit (usage )
181181 if OUT == "" :
182182 OUT = os .path .splitext (os .path .basename (BAM ))[0 ] + "_" + os .path .splitext (os .path .basename (BED ))[0 ] + ".tab"
183183
@@ -189,11 +189,11 @@ def validateBAM(bam):
189189 print ("Output file: " ,OUT )
190190 print ("Log2 output threshold: " ,OUTPUTTHRESH )
191191
192- # Validate BAM file
192+ # Validate BAM file
193193 if (not validateBAM (BAM )):
194- print ("ERROR!!!\t No BAM index detected.\n " )
195- sys .exit (- 1 )
196-
194+ print ("ERROR!!!\t No BAM index detected.\n " )
195+ sys .exit (- 1 )
196+
197197 # Load mappability file
198198 READLENGTH , REGIONMAP = loadMap (MAP )
199199 print ("Mappability file loaded" )
@@ -203,7 +203,7 @@ def validateBAM(bam):
203203 print ("Genomic coordinate coverage calculated" )
204204
205205 # Calculate log2 tag enrichment over median of mappability-normalized tag avg per region
206- SCORE = calculateDeletion (PASS )
206+ SCORE = calculateDeletion (PASS )
207207 print ("Depletion calculated" )
208208
209209 # Output final data
@@ -215,7 +215,7 @@ def validateBAM(bam):
215215 for id ,score in reversed (FINAL ):
216216 try :
217217 if float (score ) < OUTPUTTHRESH :
218- output .write (id + "\t " + str (score ) + "\n " )
218+ output .write (id + "\t " + str (score ) + "\n " )
219219 else :
220220 break
221221 except (ValueError ):
0 commit comments