Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'getSmoothRange' is not defined #1332

Open
4 tasks done
beyondpie opened this issue Oct 12, 2024 · 1 comment
Open
4 tasks done

NameError: name 'getSmoothRange' is not defined #1332

beyondpie opened this issue Oct 12, 2024 · 1 comment

Comments

@beyondpie
Copy link

beyondpie commented Oct 12, 2024

Welcome to deepTools GitHub repository! Before opening the issue please check
that the following requirements are met :

  • Search whether this issue (or a similar issue) has been solved before
    using the search tab above. Link the previous issue if appropriate below.

  • Paste your deepTools version (deeptools --version) and your python
    version (python --version) below.

deeptools 3.5.5
Python 3.10.12

  • Paste the full deepTools command that produces the issue below
    (ignore if you simply spotted the issue in the code/documentation).
    The error is generated when using the function writeBedGraph_bam_and_bw.writeBedGraph.
from deeptools import writeBedGraph_bam_and_bw
import os
from argparse import ArgumentParser
import numpy as np

def getType(fname):
    """
    function from deeptools bigwigAverage.py

    Tries to determine if a file is a wiggle file a bigWig file.
    Returns 'wiggle' if the file name ends with .wig, otherwise 'bigwig'
    """
    if fname.endswith(".wig") or fname.endswith(".wiggle"):
        return "wiggle"
    elif fname.lower().endswith(".bedgraph") or fname.endswith(".bdg"):
        return "bedgraph"
    else:
        return "bigwig"

def identity(tileCoverage, args):
    '''
    an identity function to map over the tileCoverage object
    '''
    # print('running function')
    # return [float(cov[0]) for cov in tileCoverage]
    return np.mean(tileCoverage)

def smooth_bigwig(bigwig, smooth_length, outpath=None, n_threads=1, as_bedgraph=False):
    if outpath == None:
        outpath = os.path.dirname(bigwig) + '/' + os.path.basename(bigwig)[0] + f'_smooth_{smooth_length}.bw'
    format = 'bigwig'
    if as_bedgraph:
        format = 'bedgraph'
    print(bigwig, smooth_length, outpath,getType(bigwig) )
    writeBedGraph_bam_and_bw.writeBedGraph([(bigwig, getType(bigwig))], numberOfProcessors=n_threads,
                                           outputFileName=outpath,
                                            fragmentLength=0,
                                            format=format,
                                            extendPairedEnds=False,
                                            func=identity, funcArgs=[0],
                                            smoothLength=smooth_length,
                                            # skipOverZero=False
                                            )
  • Paste the output printed on screen from the command that produces the issue
    below (ignore if you simply spotted the issue in the code/documentation).
Traceback (most recent call last):
  File "/tscc/projects/ps-renlab2/szu/projects/amb_pairedtag/02.track/src/main/python/smooth_bigwig.py", line 83, in <module>
    main()
  File "/tscc/projects/ps-renlab2/szu/projects/amb_pairedtag/02.track/src/main/python/smooth_bigwig.py", line 75, in main
    smooth_bigwig(bigwig=args.input,
  File "/tscc/projects/ps-renlab2/szu/projects/amb_pairedtag/02.track/src/main/python/smooth_bigwig.py", line 40, in smooth_bigwig
    writeBedGraph_bam_and_bw.writeBedGraph([(bigwig, getType(bigwig))], numberOfProcessors=n_threads,
  File "/home/szu/mambaforge/lib/python3.10/site-packages/deeptools/writeBedGraph_bam_and_bw.py", line 211, in writeBedGraph
    res = mapReduce.mapReduce((tileSize, fragmentLength, bamOrBwFileList,
  File "/home/szu/mambaforge/lib/python3.10/site-packages/deeptools/mapReduce.py", line 146, in mapReduce
    res = list(map(func, TASKS))
  File "/home/szu/mambaforge/lib/python3.10/site-packages/deeptools/writeBedGraph_bam_and_bw.py", line 42, in writeBedGraph_wrapper
    return writeBedGraph_worker(*args)
  File "/home/szu/mambaforge/lib/python3.10/site-packages/deeptools/writeBedGraph_bam_and_bw.py", line 88, in writeBedGraph_worker
    vectorStart, vectorEnd = getSmoothRange(
NameError: name 'getSmoothRange' is not defined

Thanks!
Sincerely,
Songpeng

@ejarmand
Copy link

ejarmand commented Oct 12, 2024

For some more information, "getSmoothRange" is defined as a class method of "CountReadsPerBin", with no references to self within the function countReadsPerBin.py line 906.

I addressed the issue on my own end by copying the function to writeBedGraph_bam_and_bw.py, and simply removing "self" from the function inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants