TypeError Issue

Issue #44 new
Former user created an issue

Hello, I'm trying to use the ROSE tool and it gives me the following error:

mapping to GFF and making a matrix with fixed bin number Traceback (most recent call last): File "ROSE_bamToGFF.py", line 247, in <module> main() File "ROSE_bamToGFF.py", line 238, in main newGFF = mapBamToGFF(bamFile,gffFile,options.sense,int(options.extension),options.floor,options.rpm,options.matrix) File "ROSE_bamToGFF.py", line 40, in mapBamToGFF MMR= round(float(bam.getTotalReads('mapped'))/1000000,4) TypeError: float() argument must be a string or a number {'matrix': '1', 'extension': '200', 'floor': '1', 'sense': 'both', 'output': 'example/mappedGFF/HG18_MM1S_MED1_MM1S_WCE.hg18.bwt.sorted.bam_MAPPED.gff', 'bam': './MM1S_WCE.hg18.bwt.sorted.bam', 'rpm': True, 'input': './HG18_MM1S_MED1.gff'} [] mapping to GFF and making a matrix with fixed bin number Traceback (most recent call last): File "ROSE_bamToGFF.py", line 247, in <module> main() File "ROSE_bamToGFF.py", line 238, in main newGFF = mapBamToGFF(bamFile,gffFile,options.sense,int(options.extension),options.floor,options.rpm,options.matrix) File "ROSE_bamToGFF.py", line 40, in mapBamToGFF MMR= round(float(bam.getTotalReads('mapped'))/1000000,4) TypeError: float() argument must be a string or a number WAITING FOR MAPPING TO COMPLETE. ELAPSED TIME (MIN): 0

All my files formats and types are compliant with the requirements of ROSE. I also tried to run the code with your example data and it gives me the same error. Could you please assist me regarding this issue?

Thanks, Aishwarya

Comments (10)

  1. Gavin Fullstone

    As a few people (including myself) have had this issue. I will post the solution we found for the benefit of others. So this TypeError occurs when trying to interpret the output of the getTotalReads function in ROSE_utils.py (line 631), where it calls samtools and reads information from the output.
    First of make sure it ROSE can access samtools by adding to path or simply placing the samtools.exe in the same folder.
    I will put the fix here and a bit of explanation underneath.

    FIX:
    Make the following changes to ROSE_utils.py:

    Line 602 (original): command = 'samtools view %s | head -n 1' % (bamFile)
    Line 602 (new): command = './samtools view %s | head -n 1' % (bamFile)

    Line 632 (original): command = 'samtools flagstat %s' % (self._bam)
    Line 632 (new): command = './samtools flagstat %s' % (self._bam)

    Line 657 (original): command = 'samtools view %s %s' % (self._bam,locusLine)
    Line 657 (new): command = './samtools view %s %s' % (self._bam,locusLine)

    EXPLANATION:
    Both the mac and linux systems I used failed to execute the command at line 633 correctly: “stats = subprocess.Popen(command,stdin = subprocess.PIPE,stderr = subprocess.PIPE,stdout = subprocess.PIPE,shell = True)”

    This line basically runs the variable command declared at line 632: “command = 'samtools flagstat %s' % (self._bam)”

    Trying to run these two commands alone in my terminal showed that samtools was not running correctly. I found it fixed the issue and ran correctly when I introduced “./” to call samtools. A few other instances need changing, again for calling samtools, on line 602 and 657.

    I hope this is of help to people 🙂

  2. hhhh

    I tried all posiblely change to deal with this issue. But the error still existed. I really have to give up.

  3. hhhh

    Traceback (most recent call last):
    File "ROSE_bamToGFF.py", line 247, in <module>
    main()
    File "ROSE_bamToGFF.py", line 238, in main
    newGFF = mapBamToGFF(bamFile,gffFile,options.sense,int(options.extension),options.floor,options.rpm,options.matrix)
    File "ROSE_bamToGFF.py", line 40, in mapBamToGFF
    MMR= round(float(bam.getTotalReads('mapped'))/1000000,4)
    TypeError: float() argument must be a string or a number
    Traceback (most recent call last):
    File "ROSE_bamToGFF.py", line 247, in <module>
    main()
    File "ROSE_bamToGFF.py", line 238, in main
    newGFF = mapBamToGFF(bamFile,gffFile,options.sense,int(options.extension),options.floor,options.rpm,options.matrix)
    File "ROSE_bamToGFF.py", line 40, in mapBamToGFF
    MMR= round(float(bam.getTotalReads('mapped'))/1000000,4)
    TypeError: float() argument must be a string or a number

    Why?

    I’m crying.

    Three days of endless try for handle this issue.

    Oh my god!

  4. Gavin Fullstone

    hhhh, so you made the changes suggested by myself to ROSE_utils.py (see above)? As I said this issue stems from using samtools, so if you made the changes above then the issue might be running the samtools executable itself (either it can’t find it or it is not compiled correctly). What happens if you go to the ROSE folder and type:

    ./samtools

    I get the following, indicating it is working correctly:

    Program: samtools (Tools for alignments in the SAM format)

    Version: 0.1.18 (r982:295)

    Usage: samtools <command> [options]

    Command: view SAM<->BAM conversion

    sort sort alignment file

    mpileup multi-way pileup

    depth compute the depth

    faidx index/extract FASTA

    tview text alignment viewer

    index index alignment

    idxstats BAM index stats (r595 or later)

    fixmate fix mate information

    flagstat simple stats

    calmd recalculate MD/NM tags and '=' bases

    merge merge sorted alignments

    rmdup remove PCR duplicates

    reheader replace BAM header

    cat concatenate BAMs

    targetcut cut fosmid regions (for fosmid pool only)

    phase phase heterozygotes

    Let me know. If it doesn’t work, also let me know what operating system (unix, mac, windows) you are using.

    Best,

    Gavin

  5. hhhh

    Gavin Fullstone, Happy New Year. Thanks for your help and patience.

    Program: samtools (Tools for alignments in the SAM format)
    Version: 1.9 (using htslib 1.9)

    Usage: samtools <command> [options]

    Commands:
    -- Indexing
    dict create a sequence dictionary file
    faidx index/extract FASTA
    fqidx index/extract FASTQ
    index index alignment

    -- Editing
    calmd recalculate MD/NM tags and '=' bases
    fixmate fix mate information
    reheader replace BAM header
    targetcut cut fosmid regions (for fosmid pool only)
    addreplacerg adds or replaces RG tags
    markdup mark duplicates

    -- File operations
    collate shuffle and group alignments by name
    cat concatenate BAMs
    merge merge sorted alignments
    mpileup multi-way pileup
    sort sort alignment file
    split splits a file by read group
    quickcheck quickly check if SAM/BAM/CRAM file appears intact
    fastq converts a BAM to a FASTQ
    fasta converts a BAM to a FASTA

    -- Statistics
    bedcov read depth per BED region
    depth compute the depth
    flagstat simple stats
    idxstats BAM index stats
    phase phase heterozygotes
    stats generate stats (former bamcheck)

    -- Viewing
    flags explain BAM flags
    tview text alignment viewer
    view SAM<->BAM<->CRAM conversion
    depad convert padded BAM to unpadded BAM

    I notice we have different version of samtools. I will change mine for yours. My operating system is Windows 10 with ubuntu 18.04.

    Best,

    hhhh

  6. Gavin Fullstone

    OK, I think you should try and look at the commands individually which create the errors. Still convinced the problem is caused by samtools failing somehow. I did this when I first fixed it myself:

    Added the following to ROSE_utils.py (lines 603, 633 and 658):

    print command

    It should be placed like so:

    def getTotalReads(self,readType = 'mapped'):

    command = './samtools flagstat %s' % (self._bam)

    print command

    stats = subprocess.Popen(command,stdin = subprocess.PIPE,stderr = subprocess.PIPE,stdout = subprocess.PIPE,shell = True)

    It should then print something along the lines of “./samtools flagstat /Path/to/file

    Maybe one of the folders/files it is trying to access doesn’t exist or it can’t find for some reason or something. Could try running the command yourself in terminal rather than as a subprocess to see if that works correctly.

  7. hhhh

    Gavin Fullstone, I forgot to tell you example data always run correctly. The real issue should be my inport file? But my own data was in accordance with the requirement of ROSE exactly.

  8. Log in to comment