YuSugihara / MutMap

MutMap pipeline to identify causative mutations responsible for a phenotype
GNU General Public License v3.0
49 stars 16 forks source link

SystemError: tile cannot extend outside image #11

Closed 2005xpb closed 2 years ago

2005xpb commented 2 years ago

Dear Yu, Thank you for MutMap. I've had some problems with it. When I use mutmap with BAM file, I found I can obtain the file of mutmap.vcf.gz, but I can not obtain the result files in 40_mutmap. I guess the problem is mutplot. Could you help me see how to solve this problem. The details of error are as follows: (mutmap) root@ecs-75cc:~/snp2# mutmap -r /root/snp/genome/Fragaria_vesca_v4.0.a1.fasta -c /root/snp/mapping/wt.MarkDup.bam -b /root/snp/mapping/mut.sorted.bam -n 33 -o example_dir [MutMap:2021-12-12 17:26:17] start to run MutMap. [MutMap:2021-12-12 17:26:17] maximum number of threads which you can use is up to 8. [MutMap:2021-12-12 17:26:17] start to index reference fasta. [MutMap:2021-12-12 17:29:19] indexing of reference successfully finished. [MutMap:2021-12-12 17:29:19] start to merge BAMs. [MutMap:2021-12-12 17:41:48] merging process successfully finished. [MutMap:2021-12-12 17:41:48] start to call variants. [MutMap:2021-12-12 17:52:56] variant calling successfully finished. [MutMap:2021-12-12 17:52:56] start to index VCF. [MutMap:2021-12-12 17:52:56] indexing VCF successfully finished. [MutMap:2021-12-12 17:52:57] start to run MutPlot. [MutMap:2021-12-12 17:52:57] start to calculate SNP-index. [MutMap:2021-12-12 17:52:58] SNP-index successfully finished. [MutMap:2021-12-12 17:52:58] start to smooth SNP-index. [MutMap:2021-12-12 17:52:58] smoothing process successfully finished. [MutMap:2021-12-12 17:52:58] plotting now... Traceback (most recent call last): File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/PIL/ImageFile.py", line 504, in _save fh = fp.fileno() AttributeError: '_idat' object has no attribute 'fileno'

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/root/BSA/enter/envs/mutmap/bin/mutplot", line 10, in sys.exit(main()) File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/mutmap/mutplot.py", line 189, in main mp.run() File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/mutmap/mutplot.py", line 178, in run pt.run() File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/mutmap/plot.py", line 143, in run plt.savefig('{}/mutmap_plot.{}'.format(self.out, self.args.format)) File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/matplotlib/pyplot.py", line 958, in savefig res = fig.savefig(args, kwargs) File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/matplotlib/figure.py", line 3012, in savefig self.canvas.print_figure(fname, kwargs) File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 2314, in print_figure result = print_method( File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/matplotlib/backend_bases.py", line 1643, in wrapper return func(args, *kwargs) File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/matplotlib/_api/deprecation.py", line 412, in wrapper return func(inner_args, inner_kwargs) File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/matplotlib/backends/backend_agg.py", line 541, in print_png mpl.image.imsave( File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/matplotlib/image.py", line 1675, in imsave image.save(fname, pil_kwargs) File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/PIL/Image.py", line 2240, in save save_handler(self, fp, filename) File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/PIL/PngImagePlugin.py", line 1348, in _save ImageFile._save(im, _idat(fp, chunk), [("zip", (0, 0) + im.size, 0, rawmode)]) File "/root/BSA/enter/envs/mutmap/lib/python3.10/site-packages/PIL/ImageFile.py", line 512, in _save e.setimage(im.im, b) SystemError: tile cannot extend outside image [MutMap:2021-12-12 17:52:59] MutMap successfully finished.

Best wishes.

Pengbo Xu

2005xpb commented 2 years ago

I also use mutplot with the file of mutmap.vcf.gz, but the same problems arise.

YuSugihara commented 2 years ago

When you reference genome is too contiguous, this plotting error sometimes happen. I plan to implement the solution, but so far you need to plot the result by yourself.

I think, except for plotting, all results are fine basically.

mgalland commented 2 years ago

@YuSugihara I have the same error message "SystemError: tile cannot extend outside image" but in my case the "sliding_window.tsv" and "snp_index.tsv" files are also empty. This is weird since the VCF file looks fine. Any clue?

YuSugihara commented 2 years ago

Would you restart from MutPlot again, inputting the VCF? If you face the same problem again, I would like to check your VCF.

So far, I have never heard the problem that you faced.

mgalland commented 2 years ago

@YuSugihara OK yes, I have restarted from mutplot with this command:
mutplot --vcf results/merged_vcf/mutant_01.merged_with_reference.vcf --window 2000 --N-bulk 50 --out results/mutplot/mutant_01/

I still have the same error message: SystemError: tile cannot extend outside image and it seems to come from the PIL plotting package.

Please find my VCF attached along with the reference FASTA file.

Curious to have your opinion on this! Thanks Marc

mutant_01.merged_with_reference.vcf.gz mutmap_ref.fasta.gz

YuSugihara commented 2 years ago

I checked your VCF. The format of VCF is ok.

I am not sure the exact reason for "SystemError: tile cannot extend outside image", but I speculate this error was caused by the empty "snp_index.tsv".

If you would like to check why "snp_index.tsv" is empty, you can relax the parameters like below:

mutplot --vcf mutant_01.merged_with_reference.vcf.gz \
             --window 200  \
             --N-bulk 50   \
             --out test \
             -d 0 \
             -m 0 \
             --indel

In this case, most SNP-index were lower than 0.3 (default: -m 0.3). Some SNP-index was higher than 0.3, but the depths were too thin (default : -d 8)

Probably, this was the main reason why you got the empty file.

I may need to update MutMap/QTL-seq to handle the error from the empty file. However, if all SNP-index are lower than 0.3, it is a bit strange because we can assume that SNP-index is around 0.5 under mendelian inheritance.

Please check the VCF that you attached. Especially, GT (genotype) field in the parental cultivar and AD (allele depth) field in the mutant bulk.

mgalland commented 2 years ago

Hello Yu, Your solution works! Relaxing the default was the solution. This VCF file is generated using the test files you provide if I remember well (archived here for myself: https://zenodo.org/record/5710370). I guess having small FASTQ files for testing purposes can sometimes result in weird/half empty VCF files causing that problem.

I have also bumped into that same error recently on a normal FASTQ file using default settings. I am now trying with relaxed settings to see if I can get the plot and the SNP-index: mutmap --min-depth 0 --window 200 ...

Thank you for your rapid answer and your follow-up, much appreciated.

YuSugihara commented 2 years ago

I am happy to hear that! Once you check the result under the relaxed parameters, you can try more strict parameters. Note that too relaxed parameters may result in unreliable QTLs.