deeptools / deepTools

Tools to process and analyze deep sequencing data.
Other
677 stars 210 forks source link

NameError: name 'getSmoothRange' is not defined #1332

Open beyondpie opened 1 week ago

beyondpie commented 1 week ago

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

deeptools 3.5.5 Python 3.10.12

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
                                            )
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 commented 1 week ago

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.