/usr/share/pyshared/MACS2/IO/bedGraphIO.py is in macs 2.0.9.1-1.
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 | # Time-stamp: <2011-09-07 22:28:15 Tao Liu>
"""Module Description: IO Module for bedGraph file
Copyright (c) 2011 Tao Liu <taoliu@jimmy.harvard.edu>
This code is free software; you can redistribute it and/or modify it
under the terms of the BSD License (see the file COPYING included with
the distribution).
@status: experimental
@version: $Revision$
@author: Tao Liu
@contact: taoliu@jimmy.harvard.edu
"""
# ------------------------------------
# python modules
# ------------------------------------
from MACS2.IO.cBedGraph import bedGraphTrackI
# ------------------------------------
# constants
# ------------------------------------
# ------------------------------------
# Misc functions
# ------------------------------------
# ------------------------------------
# Classes
# ------------------------------------
class bedGraphIO:
"""File Parser Class for bedGraph File.
There are two assumptions in my bedGraphTrackI object:
1. Continuous: the next region should be after the previous one
unless they are on different chromosomes;
2. Non-overlapping: the next region should never have overlaps
with preceding region.
If any of the above two criteria is violated, parsering will fail.
"""
def __init__ (self,f):
"""f must be a filename or a file handler.
"""
if type(f) == str:
self.fhd = open(f,"r")
elif type(f) == file:
self.fhd = f
else:
raise Exception("f must be a filename or a file handler.")
def build_bdgtrack (self, baseline_value=0):
"""Use this function to return a bedGraphTrackI object.
baseline_value is the value to fill in the regions not defined
in bedGraph. For example, if the bedGraph is like:
chr1 100 200 1
chr1 250 350 2
Then the region chr1:200..250 should be filled with
baseline_value. Default of baseline_value is 0.
"""
data = bedGraphTrackI(baseline_value=baseline_value)
add_func = data.add_loc
for i in self.fhd:
if i.startswith("track"):
continue
elif i.startswith("#"):
continue
elif i.startswith("browse"):
continue
else:
(chrom,startpos,endpos,value)=i.split()
add_func(chrom,int(startpos),int(endpos),float(value))
self.fhd.seek(0)
return data
|