Xinglab / rmats2sashimiplot

GNU General Public License v2.0
127 stars 54 forks source link

TypeError: cannot unpack non-iterable Axes object for rmats2sashimiplot From Singularity #107

Open yr542 opened 9 months ago

yr542 commented 9 months ago

The main error I have having (along with some basic .out file information before it):

<module 'misopy' from '/path/to/rmats2sashimiplot-2.0.4-py3.10.egg/MISO/misopy/__init__.py'>
Indexing GFF...
/path/to/Sashimi_index_isl2a_1/tmp.gff3 appears to already be indexed. Aborting.
Reading settings from: /path/to/Sashimi_index_isl2a_1/sashimi_plot_settings.txt
Parsing data:bam_prefix
Parsing data:miso_prefix
Parsing data:bam_files
Parsing data:miso_files
Parsing plotting:fig_height
Parsing plotting:fig_width
Parsing plotting:exon_scale
Parsing plotting:intron_scale
Parsing plotting:logged
Parsing plotting:font_size
Parsing plotting:bar_posteriors
Parsing plotting:nyticks
Parsing plotting:nxticks
Parsing plotting:show_ylabel
Parsing plotting:show_xlabel
Parsing plotting:plot_title
Parsing plotting:plot_label
Parsing plotting:show_posteriors
Parsing plotting:number_junctions
Parsing plotting:resolution
Parsing plotting:reverse_minus
Parsing plotting:min_counts
Parsing plotting:text_background
Parsing plotting:group_info
Parsing plotting:colors
Parsing plotting:sample_labels
Reading dimensions from settings...
 - Height: 7.00
 - Width: 8.00
Plotting read densities and MISO estimates along event...
  - Event: 25_32751863_32751982_-@25_32751362_32751551_-@25_32750076_32750338_-
Setting up plot using dimensions:  [8.0, 7.0]
Using intron scale  1.0
Using exon scale  1.0
Reading sample label: isl2a Control-1 IncLevel: 0.98
Error retrieving files from 25: invalid contig `25`
Are you sure 25 appears in your BAM file?
Aborting plot...
Traceback (most recent call last):

  File "/path/to/sashimi_plot.py", line 293, in <module>
    main()
  File "/path/to/sashimi_plot.py", line 285, in main
    plot_event(event_name, pickle_dir, settings_filename, output_dir,
  File "/path/to/sashimi_plot.py", line 155, in plot_event
    plot_density_from_file(settings_filename, pickle_filename, event_name,
  File "/path/to/plot_gene.py", line 845, in plot_density_from_file
    plot_density(sashimi_obj, pickle_filename, event, group_info=group_info,
  File "/path/to/plot_gene.py", line 386, in plot_density
    plotted_ax, maxy = plot_density_single(settings, sample_label,
TypeError: cannot unpack non-iterable Axes object

The error repeats on and one. The main section of the script as well as the variable are defined below. The paths cannot be given as I am on a HPC and they do not allow us to disclose any paths.

The variable(s):

The main section of the script:

# Create arrays to store Control and Experimental BAM files
control_bams=()
experimental_bams=()

# Iterate over files in the BAM directory
for bam_file in "${bam_directory}"/*.bam; do
    # Check if the file exists and its name matches the pattern
    if [ -f "$bam_file" ]; then
        filename=$(basename "$bam_file")
        if [[ "$filename" == Control* ]]; then
            control_bams+=("$bam_file")
        elif [[ "$filename" == Experimental* ]]; then
            experimental_bams+=("$bam_file")
        fi
    fi
done

# Define other parameters for rmats2sashimiplot
## Controls separated by a comma
s1_files=$(IFS=,; echo "${control_bams[*]}")
## Experimentals separated by a comma
s2_files=$(IFS=,; echo "${experimental_bams[*]}")

singularity exec ${singularity_image} rmats2sashimiplot \
  --b1 "$s1_files" \
  --b2 "$s2_files" \
  --event-type "$event_type" \
  -e "${event_file}" \
  --l1 Control \
  --l2 Experimental \
  --exon_s "$exon_skip" \
  --intron_s "$intron_skip" \
  -o "${output_directory}"

The bams I used for rMats2sashimiplot are aligned to the same GTF as the fq files used in a run of rMats-turbo (section of code used in rMats-turbo is used below):

rMats relevant section:

singularity exec "${singularity_image}" python "${RMATS_SCRIPT}" \
    --s1 "$s1_file" \
    --s2 "$s2_file" \
    --gtf "$gtf_file" \
    --bi "$star_binary_index" \
    -t paired \
    --readLength 50 \
    --variable-read-length \
    --nthread 10 \
    --od "$output_directory" \
    --tmp "$tmp_directory"

I had some issues using it with bams so I switched to fq. The issue was documented on the rMats-turbo repository issues here

How would I navigate around this issue for rMats2sashimiplot?

EricKutschera commented 9 months ago

The main error is:

Error retrieving files from 25: invalid contig `25`
Are you sure 25 appears in your BAM file?
Aborting plot...

The traceback is a result of the invalid contig error which causes that function to return a partial result: https://github.com/Xinglab/rmats2sashimiplot/blob/v3.0.0/src/MISO/misopy/sashimi_plot/plot_utils/plot_gene.py#L63

This post has some suggestions about handling the invalid contig error: https://github.com/Xinglab/rmats2sashimiplot/issues/101#issuecomment-1642016386

In this case, rmats2sashimiplot is looking for a contig named 25, but maybe the bam files actually have the contig named as chr25? Recent versions of rmats2sashimiplot have --keep-event-chr-prefix and --remove-event-chr-prefix which might get rmats2sashimiplot to use the right contig name

Also since you mentioned that the error repeats a lot, you may want to filter the rMATS output file before using it with rmats2sashimiplot so that only the events you're interested in get plotted