Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added sum/mean/none to ScoreBigwig
  • Loading branch information
msbentsen committed May 2, 2019
1 parent 3c1bd97 commit ce5e13c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGES
@@ -1,3 +1,6 @@
## 0.5.0 (2019-05-02)
- Added sum/mean/none scoring to ScoreBigwig as well as the option to get --absolute of input signal

## 0.4.1 (2019-04-29)
- Fixed weird "can't pickle SwigPyObject objects"-error in bindetect

Expand Down
4 changes: 3 additions & 1 deletion setup.py
Expand Up @@ -18,6 +18,7 @@
cmdclass = {'build_ext': build_ext}
except ImportError:
use_cython = False

else:
use_cython = True

Expand Down Expand Up @@ -56,7 +57,7 @@ def readme():
author='Mette Bentsen',
author_email='mette.bentsen@mpi-bn.mpg.de',
license='MIT',
packages=find_packages(), #"tobias"), #['tobias', 'tobias.footprinting', 'tobias.plotting', 'tobias.motifs', 'tobias.misc', 'tobias.utils'],
packages=find_packages(),
entry_points={
'console_scripts': ['TOBIAS=tobias.TOBIAS:main']
},
Expand All @@ -77,6 +78,7 @@ def readme():
'pyBigWig',
'MOODS-python',
],
scripts=["tobias/utils/filter_important_factors.py"],
classifiers=[
'License :: OSI Approved :: MIT License',
'Intended Audience :: Science/Research',
Expand Down
2 changes: 1 addition & 1 deletion tobias/__init__.py
@@ -1 +1 @@
__version__ = "0.4.1"
__version__ = "0.5.0"
31 changes: 21 additions & 10 deletions tobias/footprinting/scorebigwig.py
Expand Up @@ -48,13 +48,12 @@ def add_scorebigwig_arguments(parser):
required.add_argument('-r', '--regions', metavar="<bed>", help="Genomic regions to run footprinting within")

optargs = parser.add_argument_group('Optional arguments')
optargs.add_argument('--score', metavar="<score>", choices=["footprint", "sum"], help="Type of scoring to perform on cutsites (footprint/sum) (default: footprint)", default="footprint")
#mean
#abs convert bigwig signal to absolute scores before calculating score
optargs.add_argument('--score', metavar="<score>", choices=["footprint", "sum", "mean", "none"], help="Type of scoring to perform on cutsites (footprint/sum/mean/none) (default: footprint)", default="footprint")
optargs.add_argument('--absolute', action='store_true', help="Convert bigwig signal to absolute values before calculating score")
optargs.add_argument('--extend', metavar="<int>", type=int, help="Extend input regions with bp (default: 100)", default=100)
optargs.add_argument('--smooth', metavar="<int>", type=int, help="Smooth output signal by mean in <bp> windows (default: no smoothing)", default=1)
optargs.add_argument('--min-limit', metavar="<float>", type=float, help="Limit input bigwig score range (default: no lower limit)") #default none
optargs.add_argument('--max-limit', metavar="<float>", type=float, help="Limit input bigwig score range (default: no upper limit)") #default none
optargs.add_argument('--min-limit', metavar="<float>", type=float, help="Limit input bigwig value range (default: no lower limit)") #default none
optargs.add_argument('--max-limit', metavar="<float>", type=float, help="Limit input bigwig value range (default: no upper limit)") #default none

footprintargs = parser.add_argument_group('Parameters for score == footprint')
footprintargs.add_argument('--fp-min', metavar="<int>", type=int, help="Minimum footprint width (default: 20)", default=20)
Expand Down Expand Up @@ -93,27 +92,37 @@ def calculate_scores(regions, args):
signal = region.get_signal(pybw_signal)
signal = np.nan_to_num(signal).astype("float64")

#
#-------- Prepare signal for score calculation -------#
if args.absolute:
signal = np.abs(signal)

if args.min_limit != None:
signal[signal < args.min_limit] = args.min_limit
if args.max_limit != None:
signal[signal > args.max_limit] = args.max_limit

#Calculate scores
#------------------ Calculate scores ----------------#
if args.score == "sum":
signal = np.abs(signal)
scores = fast_rolling_math(signal, args.window, "sum")

elif args.score == "mean":
scores = fast_rolling_math(signal, args.window, "mean")

elif args.score == "footprint":
scores = tobias_footprint_array(signal, args.flank_min, args.flank_max, args.fp_min, args.fp_max) #numpy array

elif args.score == "FOS":
scores = FOS_score(signal, args.flank_min, args.flank_max, args.fp_min, args.fp_max)
scores = -scores
scores = FOS_score(signal, args.flank_min, args.flank_max, args.fp_min, args.fp_max)
scores = -scores

elif args.score == "none":
scores = signal

else:
sys.exit("Scoring {0} not found".format(args.score))

#----------------- Post-process scores --------------#

#Smooth signal with args.smooth bp
if args.smooth > 1:
scores = fast_rolling_math(scores, args.smooth, "mean")
Expand Down Expand Up @@ -175,6 +184,8 @@ def run_scorebigwig(args):
args.region_flank = int(args.window/2.0)
elif args.score == "footprint" or args.score == "FOS":
args.region_flank = int(args.flank_max)
else:
args.region_flank = 0

#Go through each region
for i, region in enumerate(regions):
Expand Down
2 changes: 1 addition & 1 deletion tobias/utils/regions.py
Expand Up @@ -666,7 +666,7 @@ def get_cluster_names(self):
self.cluster_names[cluster] = "C_" + self.names[ordered_idx[0]] #cluster is the idx for cluster
else:
self.cluster_names[cluster] = self.clusters[cluster]["member_names"][0]
self.clusters[cluster]["representative"] = self.cluster_names[cluster]
self.clusters[cluster]["representative"] = "C_" + self.cluster_names[cluster]

self.clusters[cluster]["cluster_name"] = self.cluster_names[cluster]

Expand Down

0 comments on commit ce5e13c

Please sign in to comment.