Skip to content

Commit

Permalink
Take advantage of newer pysam version
Browse files Browse the repository at this point in the history
  • Loading branch information
EC2 Default User committed Feb 7, 2019
1 parent ca822e1 commit 8dde12b
Showing 1 changed file with 8 additions and 38 deletions.
46 changes: 8 additions & 38 deletions lib/mutfilter/realignment_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,41 +46,6 @@ def math_log_fisher_pvalue(self,fisher_pvalue):
return val


############################################################
def makeTwoReference(self, chr,start,end,ref,alt, output):

hOUT = open(output, 'w')

seq = ""
label = ','.join([chr, str(start), str(end), ref, alt])
range = chr + ":" + str(int(start) - self.window + 1) +"-"+ str(int(end) + self.window)
for item in pysam.faidx(self.reference_genome, range):
# if item[0] == ">": continue
seq = seq + item.rstrip('\n').upper()
seq = seq.replace('>', '')
seq = seq.replace(range.upper(), '')

if re.search(r'[^ACGTUWSMKRYBDHVN]', seq) is not None:
print >> sys.stderr, "The return value in get_seq function includes non-nucleotide characters:"
print >> sys.stderr, seq
sys.exit(1)

print >> hOUT, '>' + label + "_ref"
print >> hOUT, seq

# for insertion
if ref == "-": seq = seq[0:(self.window + 1)] + alt + seq[-self.window:]
# for deletion
elif alt == "-": seq = seq[0:self.window] + seq[-self.window:]
# for SNV
else: seq = seq[0:self.window] + alt + seq[-self.window:]

print >> hOUT, '>' + label + "_alt"
print >> hOUT, seq

hOUT.close()


############################################################
def extractRead(self, bamfile, chr,start,end, output):

Expand Down Expand Up @@ -158,10 +123,15 @@ def makeTwoReference(self, chr,start,end,ref,alt, output):
label = ','.join([chr, str(start), str(end), ref, alt])
range = chr + ":" + str(int(start) - self.window + 1) +"-"+ str(int(end) + self.window)
for item in pysam.faidx(self.reference_genome, range):
if item[0] == ">": continue
# if item[0] == ">": continue
seq = seq + item.rstrip('\n').upper()
seq = seq.replace('>', '')
seq = seq.replace(range, '')
seq = seq.replace('>', '')
seq = seq.replace(range.upper(), '')

if re.search(r'[^ACGTUWSMKRYBDHVN]', seq) is not None:
print >> sys.stderr, "The return value in get_seq function includes non-nucleotide characters:"
print >> sys.stderr, seq
sys.exit(1)

print >> hOUT, '>' + label + "_ref"
print >> hOUT, seq
Expand Down

0 comments on commit 8dde12b

Please sign in to comment.