Skip to content

Commit

Permalink
Merge pull request #35 from dpryan79/fix28_GenomicIntervalsComparisons
Browse files Browse the repository at this point in the history
Fix #28, #31 and related issues
  • Loading branch information
jpiper committed Mar 29, 2018
2 parents d2c4845 + e8acbcd commit 4ab1593
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
87 changes: 87 additions & 0 deletions pyDNase/__init__.py
Expand Up @@ -493,6 +493,93 @@ def __len__(self):
"""
return self.endbp - self.startbp

def __lt__(self, other):
"""
Implements foo < bar
"""
if self.chromosome == other.chromosome:
if self.startbp < other.startbp:
return True
elif self.startbp == other.startbp:
if self.endbp < other.endbp:
return True
else:
return False
else:
return False
elif self.chromosome < other.chromosome:
return True
else:
return False

def __le__(self, other):
"""
Implements foo <= bar
"""
if self.chromosome == other.chromosome:
if self.startbp < other.startbp:
return True
elif self.startbp == other.startbp:
if self.endbp <= other.endbp:
return True
else:
return False
else:
return False
elif self.chromosome < other.chromosome:
return True
else:
return False

def __eq__(self, other):
"""
Implements foo == bar
"""
if self.chromosome == other.chromosome and \
self.startbp == other.startbp and \
self.endbp == other.endbp:
return True
return False

def __gt__(self, other):
"""
Implements foo > bar
"""
if self.chromosome == other.chromosome:
if self.startbp > other.startbp:
return True
elif self.startbp == other.startbp:
if self.endbp > other.endbp:
return True
else:
return False
else:
return False
elif self.chromosome > other.chromosome:
return True
else:
return False

def __ge__(self, other):
"""
Implements foo >= bar
"""
if self.chromosome == other.chromosome:
if self.startbp > other.startbp:
return True
elif self.startbp == other.startbp:
if self.endbp >= other.endbp:
return True
else:
return False
else:
return False
elif self.chromosome > other.chromosome:
return True
else:
return False


class FASTAHandler(object):
def __init__(self, fasta_file, vcf_file = None):
self.ffile = pysam.Fastafile(fasta_file)
Expand Down
4 changes: 2 additions & 2 deletions pyDNase/scripts/wellington_footprints.py
Expand Up @@ -18,7 +18,7 @@
parser.add_argument("-pv","--pv_cutoffs", help=" (Provide multiple values separated by spaces) Select footprints using a range of pvalue cutoffs (default: -10 -20 -30 -40 -50 -75 -100 -300 -500 -700",default=[-10,-20,-30,-40,-50,-75,-100,-300,-500,-700],type=int, nargs="+")
parser.add_argument("-dm","--dont-merge-footprints",action="store_true", help="Disables merging of overlapping footprints (Default: False)",default=False)
parser.add_argument("-o","--output_prefix", help="The prefix for results files (default: <reads.regions>)",default="",type=str)
parser.add_argument("-p", help="Number of processes to use (default: uses all CPUs)",default=0,type=int)
parser.add_argument("-p", help="Number of processes to use, use 0 to use all cores (default: 1)",default=1,type=int)
parser.add_argument("-A",action="store_true", help="ATAC-seq mode (default: False)",default=False)
parser.add_argument("regions", help="BED file of the regions you want to footprint")
parser.add_argument("reads", help="The BAM file containing the DNase-seq reads")
Expand Down Expand Up @@ -83,7 +83,7 @@ def xrange_from_string(range_string):
print("track type=wiggle_0", file=wigout)

#Iterate in chromosome, basepair order
orderedbychr = [item for sublist in sorted(regions.intervals.values(),key=lambda genomicIntervalList: genomicIntervalList[0].chromosome) for item in sorted(sublist, key=lambda peak: peak.startbp)]
orderedbychr = [item for sublist in sorted(regions.intervals.values()) for item in sublist] # Flatten the list of lists
puts_err("Calculating footprints...")

if clargs.p:
Expand Down

0 comments on commit 4ab1593

Please sign in to comment.