Coder Social home page Coder Social logo

pyBigWig using 30+ cores about pybigwig HOT 5 CLOSED

deeptools avatar deeptools commented on August 16, 2024
pyBigWig using 30+ cores

from pybigwig.

Comments (5)

dpryan79 avatar dpryan79 commented on August 16, 2024

30! It shouldn't ever use more than 1. Can you post an example where this happens?

from pybigwig.

goodez avatar goodez commented on August 16, 2024

30! It shouldn't ever use more than 1. Can you post an example where this happens?

Without posting a bunch of code I think I can describe my simple script:

First I load in a bed file of ~20,000 annotated genes. I then open up a single bigwig file:
bw=pyBigWig.open(args.bigwig)

Then I loop through each line of the bed file. For each entry in the bed, I evaluate the coverage of my bigwig. These are all of the functions I use in total:

               tss_covs=bw.values(chrom, tss_pos-n, tss_pos+n, numpy=True)
               pA_covs=bw.values(chrom, pA_pos+1-n, pA_pos+n+2, numpy=True)
               mid_covs=bw.values(chrom, tss_pos+n, pA_pos+1-n, numpy=True)[indexes.astype(int)]
                covs=np.concatenate((tss_covs,mid_covs,pA_covs))
                all_covs=np.vstack((all_covs,covs))

I am also using the modules numpy and argparse. Maybe numpy is causing the issue?

from pybigwig.

goodez avatar goodez commented on August 16, 2024

Ah I have just looked into numpy a bit more. I think the issue is there and I can solve it this way:

export MKL_NUM_THREADS=1
export NUMEXPR_NUM_THREADS=1
export OMP_NUM_THREADS=1

I am sorry for blaming your wonderful project! Thank you for such a quick response.

from pybigwig.

dpryan79 avatar dpryan79 commented on August 16, 2024

It's quite likely that numpy is causing this, particularly if you've installed it via conda. At the beginning of your script, try adding the following:

import os

# This should force numpy to run single threaded. See issue #697
# This module MUST be imported before numpy
# Note that these environment variables are internal to deepTools (they won't exist on the shell after the command completes)
if 'MKL_NUM_THREADS' not in os.environ:
    os.environ['MKL_NUM_THREADS'] = 'sequential'
if 'NUMEXPR_NUM_THREADS' not in os.environ:
    os.environ['NUMEXPR_NUM_THREADS'] = '1'
if 'OMP_NUM_THREADS' not in os.environ:
    os.environ['OMP_NUM_THREADS'] = '1'
if 'VECLIB_MAXIMUM_THREADS' not in os.environ:
    os.environ['VECLIB_MAXIMUM_THREADS'] = '1

I've placed that code at the very beginning of all the deepTools executables to prevent similar issues with numpy.

from pybigwig.

goodez avatar goodez commented on August 16, 2024

Thanks that's even better! Woo!

from pybigwig.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.