thanks ATpoint for answering! Both bam and bed were sorted as you mentioned. However, when I try to run genomeCoverageBed with a bam file, I get this error message: Input error: Chromosome scaffold_17 found in non-sequential lines. This suggests that the input file is not sorted correctly.
With the bed file I manage to obtain a coverage file. However, when I run bedGraphToBigWig, I obtain this error: end (297) before start (343) line 344 of coverage.bed
Not sure why, in my coverage file I have endings that are previous to the beginnings, as for example this:
scaffold_1 343 297 233710445 1.2708e-06
Any idea of what is going on?