Coordinates of genomic regions are frequently stored in BED files, containing (at least) three columns:
Positions in a BED file are 0-based. The bedGraph format is similar but adds a specific fourth column, containing some continuous-valued data, such as probability scores or transcriptome data (e.g. the number of reads mapped to each genomic region in an RNA-seq experiment).
An example of a few lines in a bedGraph file:
Chr1 1100 1120 50
Chr1 1143 1155 225
Chr1 1155 1156 229
Chr1 1241 1456 2
Chr2 10 100 454
Chr2 100 488 589
These bedGraph files are useful for data visualization and supported by standard bioinformatics tools such as the UCSC Genome Browser.
Write a self-executable Bash script that takes three arguments:
example.bedgraph.Chr1.The script outputs the score associated to that position on the given chromosome, as specified in the given bedGraph file. Some examples for the bedGraph records shown above:
$ ./getvalue.sh example.bedgraph Chr1 1144
225
$ ./getvalue.sh example.bedgraph Chr1 1155
229
$ ./getvalue.sh example.bedgraph Chr2 100
589
Some special cases to handle appropriately:
"Expecting 3 arguments"."Invalid position"."Invalid bedGraph file: overlapping regions".Important note: in case an error is produced, the script should have exit code 1 (not 0) so that it is clear that the script failed.