I will use GATK for SNP calling (HaplotypeCaller). I need to feed the interval file in the command, otherwise I get errors (even though I want to use the whole genome, not a subset - btw it's not the point of the question, so will not elaborate).
The interval file for GATK can be for example a bed
file, with 3 columns: chr_name chr_start chr_end
. I don't have this file, but have the genome and the reads.
To obtain the intervals per chr/scaf, I proceeded this way:
- converted the alignment to interval file, using
bam2bed
(BEDOPS) - extract the columns $1,2,3 (using
cut
) - get the min & max coordinates per chr/scaff with a small R script:
bd <- read.table('all.bed', h=FALSE)
bd_min <- aggregate( bd$V3 ~ bd$V1 , bd, function(x) min(x))
bd_max <- aggregate( bd$V2 ~ bd$V1 , bd, function(x) max(x))
bd_coord <- merge(bd_min, bd_max, by='bd$V1')
write.table(bd_coord, file='coords.bed', sep='\t', quote=FALSE, col.names=FALSE, row.names=FALSE)
These should thus represent the mapped intervals, conceptually same as not feeding the intervals at all (= considering all the sequences).
The ideas for this:
- in the bed file:
$1
is be the feature,$2
the start position,$3
the end position - so, I need to get the min of
$2
for each unique item in$1
(for the start coord) and the max of$3
for each item in$1
(for the end coord)
The output looks plausible:
$ cat coords.bed | head -3
Bla_chrm1 678 43860826
Bla_chrm10 181 20381540
Bla_chrm11 343 20367560
My question here:
- is this a correct way to proceed?
- is there a standardized way to perform this?
My main concern is that I will have to re-build this "coordinate" files for every GATK run, because I think the coordinates per chr/scaf will shift, even slightly, at each GATK run with different datasets.
My other minor concern, is that this approach is a bit slow (given the 160M lines in the current bed file), so an unix-tools solution will also be accepted. I tried to compute myself the max/min using awk (e.g. awk '$3>max[$1]{max[$1]=$3; row[$1]=$0} END{for (i in row) print row[i]}'
), but I get different results than with the R approach...