Skip to content

Commit

Permalink
Fix for PEP479 compliance
Browse files Browse the repository at this point in the history
Correctly handles StopIteration raised in handling of bam files for PEP479 compliance and python 3.7 compatibility
  • Loading branch information
genomematt committed Jul 5, 2019
1 parent 010e290 commit 78083fa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@
**/.DS_store

#ignore egg info files
XenoMapper.egg-info
XenoMapper.egg-info
\.eggs/

\.pytest_cache/v/cache/

\.vscode/

dist/
30 changes: 16 additions & 14 deletions xenomapper/xenomapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,24 @@ def getBamReadPairs(bamfile1,bamfile2, skip_repeated_reads=False): #pragma: no c
"""
bam1 = bam_lines(bamfile1)
bam2 = bam_lines(bamfile2)
line1= next(bam1).strip('\n').split() #split on white space. Results in 11 fields of mandatory SAM + variable number of additional tags.
line2= next(bam2).strip('\n').split()
while line1 and line2 and line1 !=[''] and line2 !=['']:
assert line1[0] == line2[0]
yield line1,line2
previous_read1 = line1[0]
previous_read2 = line2[0]
if skip_repeated_reads:
while line1 and line2 and line1 !=[''] and line2 !=[''] and line1[0] == previous_read1:
try:
line1= next(bam1).strip('\n').split() #split on white space. Results in 11 fields of mandatory SAM + variable number of additional tags.
line2= next(bam2).strip('\n').split()
while line1 and line2 and line1 !=[''] and line2 !=['']:
assert line1[0] == line2[0]
yield line1,line2
previous_read1 = line1[0]
previous_read2 = line2[0]
if skip_repeated_reads:
while line1 and line2 and line1 !=[''] and line2 !=[''] and line1[0] == previous_read1:
line1= next(bam1).strip('\n').split()
while line1 and line2 and line1 !=[''] and line2 !=[''] and line2[0] == previous_read2:
line2= next(bam2).strip('\n').split()
else:
line1= next(bam1).strip('\n').split()
while line1 and line2 and line1 !=[''] and line2 !=[''] and line2[0] == previous_read2:
line2= next(bam2).strip('\n').split()
else:
line1= next(bam1).strip('\n').split()
line2= next(bam2).strip('\n').split()
pass
except StopIteration:
return

def getReadPairs(sam1,sam2, skip_repeated_reads=False):
"""Process two sam files to yield the equivalent line from each file
Expand Down

0 comments on commit 78083fa

Please sign in to comment.