How to make a compressed file directly usable as a

2019-07-29 00:18发布

问题:

We have a custom compressor for genomic data called CRAM, and althogugh it provides superior compression people are afraid to use it, because it is not-so-easy to handle with bioinformatic tools as "regular" files. We would like to allow compressed file to be used for example as parameters to scripts, be opened in GUIs, etc. just like classic files.

Like a named pipe or block device file that automatically executes the unzip command whenever it is read from. If it is easy to copy from system to system (to email, sftp, etc. it), it would be even better.

Our current solution:

  1. let's say we have two commands, cram and uncram (you can substitute gzip and gunzip here), and an input file fileX.

  2. we compress:

    cram < fileX > fileX.cram

  3. we create self extracting archive for cram:

    echo "uncram < fileX.cram" > fileX.cram.sex
    chmod +x fileX.cram.sex

  4. we use it as a parameter(s) in tools:

    mytool <(fileX.cram.sex)

now it is almost easy-to-use except for the "<()" notation, and the fact that you cannot immediately open it in a GUI.

Any ideas how to make the process transparent?

回答1:

You could try providing a simple wrapper around each command that processes your files:

$ mytool () {
>  command mytool <( "$1" )
> }
$ mytool fileX.cram.sex

The command builtin allows you run the original command, rather than the function that shadows it.

Note that fileX.cram.sex isn't a self-extracting archive; it's just a shell script that has a hard-coded input file.