/usr/lib/python2.7/dist-packages/pbsuite/utils/BedIO.py is in python-pbsuite-utils 15.8.24+dfsg-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | """
Bed Entry and Files objects
"""
class BedEntry:
"""
Holds a Bed Entry with accessors to chrom, start, end, name
all other fields are held in BedEntry.rest as a list
"""
def __init__(self, chrom, start, end, name, *args):
self.chrom = chrom
self.start = int(start)
self.end = int(end)
self.name = name
self.rest = list(args)
def plainStr(self):
"""
Doesn't write all the infomation, just the first 4 columns
"""
return "%s\t%d\t%d\t%s" % (self.chrom, self.start, self.end, self.name)
def __str__(self):
extra = ""
if len(self.rest) > 0:
extra = "\t" + "\t".join([str(x) for x in self.rest])
return self.plainStr() + extra
def __lt__(self, other):
if self.chrom != other.chrom:
return cmp(self.chrom, other.chrom)
return self.start < other.start
def __gt__(self, other):
if self.chrom != other.chrom:
return cmp(self.chrom, other.chrom)
return self.start > other.start
class BedFile(list):
"""
Create a .bed file either from a file or from a set of entries
"""
def __init__(self, fileName=None, entries=None):
super(list)
if entries is not None:
self.extend(entries)
self.fileName = fileName
@classmethod
def fromFile(cls, fileName):
"""
Create a BedFile directly from file
"""
fh = open(fileName, 'r')
entries = []
for line in fh.readlines():
entries.append(BedEntry(*line.strip().split('\t')))
fh.close()
return cls(fileName, entries)
def plainStr(self):
"""
Doesn't write all the infomation, just the first 4 columns
"""
ret = ""
for i in self:
ret += i.plainStr() + '\n'
return ret
def __str__(self):
ret = ""
for i in self:
ret += str(i)+"\n"
return ret
class BedPEEntry():
"""
Same as a bed except the less than doesn't sort for chromosomes
"""
def __init__(self, chrom1, start1, end1, chrom2, start2, end2, name, *args):
self.chrom1 = chrom1
self.start1 = start1
self.end1 = end1
self.chrom2 = chrom2
self.start2 = start2
self.end2 = end2
self.name = name
self.rest = args
def plainStr(self):
"""
Doesn't write all the infomation, just the first 7 columns
"""
return "%s\t%d\t%d\t%s\t%d\t%d\t%s" % (self.chrom1, self.start1, self.end1, \
self.chrom2, self.start2, self.end2, self.name)
def __str__(self):
extra = ""
if len(self.rest) > 0:
extra = "\t" + "\t".join([str(x) for x in self.rest])
return self.plainStr() + extra
def __lt__(self, other):
#if self.chrom != other.chrom:
#return cmp(self.chrom, other.chrom)
return self.start < other.start
def __gt__(self, other):
#if self.chrom != other.chrom:
#return cmp(self.chrom, other.chrom)
return self.start > other.start
|