This is a test version of Biostars. For the public version, visit https://www.biostars.org.
BigWig library for Java

Does anybody have recommended Java or Scala library for writing BigWig / BedGraph files?

I am aware that there is a Java bigwig library that was developed by the IGV team. However, it seems to only provide BigWig / BedGraph reading functions; nothing on writing. After contacting the developers I was told that the library will not be further developed.

I am also aware that there are ways to make Java work with the C library (there are ways to make Java work with the C library). What I am looking for, however, is a pure Java (preferably Scala) library.

This feels like like something that could have been used by a number of people out there. So before I even attempt to reinvent the wheel, I feel like I should ask :).

java bigwig bedgraph

3 answers

There is a bigwig library for Kotlin https://github.com/JetBrains-Research/big which runs on the JVM. And since kotlin can be used from Java (see https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html) it might be an option for you.

I suggest you avoid Wig and Bed formats; they're poorly designed. Are you sure you absolutely need them?

Not wig and bed per se, but yes, I do need them. Unless there is a similar (or better) format that allows me to view tracks without uploading them to the track browser..

Can you suggest any replacements for wig and bed?

I don't know what IGV specifically requires for a track; personally, I find their coverage plot from bam+bai files to be sufficient for most uses. What exactly do you need that is not present in the bam files or IGV display of bam files? I might already be able to generate it.

I need to share data with other people and sometimes load them into the track browser myself. BAM files are not that suitable because wading through multiple BAM files in IGV slows it down quite a lot. This is not the case with BigWig files. It's also easier and more compact to share BigWig files given their size.

Other advantages of bigwig/tdf. 1) it keeps mean/median depth for different window lengths. When you zoom out to the entire chromosome, IGV can only display depth with bigwig/tdf. 2) The index of bigwig/tdf is integrated in data and the index can be retrieved partially. This is much more convenient for remote access.

If you want something manageable for IGV look at the TDF format which can be created with igvtools.

If you want to create bigwig from bam you could use bedtools genomeCoverageBed followed by bedGraphToBigWig (from UCSC utilities). So something on these lines:

genomeCoverageBed -bg -ibam aln.bam > tmp.bedGraph &&
  bedGraphToBigWig tmp.bedGraph chromInfo.txt out.bw &&
  rm tmp.bedGraph

This doesn't answer your question for Java libraries but from your comments I thought it could help...

Hmm..the TDF format is usable only within IGV it seems?

And yes, I am aware of other ways to create BigWig files from BAM files. This is actually the way we are doing this now in-house. But we're trying to reduce external dependencies (that step, for example, requires 2 executables and 1 extra data file, not to mention unecessary disk space for the intermediate file), since this makes it more difficult to share things (also when we work on different environments). Not a new problem really. So we want to move this into our Scala-based toolkit. All the information to create the BigWig file is already present in the BAM file anyway, so I thought this should be doable via a single step without any extra data files.

I see... In fact I'm surprised myself that the bam -> bigwig conversion is somewhat clunky at the moment.

Log in to answer this question.