Dear Stine,
the function getPairedGRange() contains the relevant interfaces to Rsamtools for importing bam files. These are:
(...)
scanFlag = scanBamFlag(isPaired = T, isProperPair = TRUE,
hasUnmappedMate = FALSE, isUnmappedQuery = F, isFirstMateRead = T,
isSecondMateRead = F, isSecondaryAlignment = isSecondaryAlignment)
(...)
scanParam = ScanBamParam(flag = scanFlag, simpleCigar = simpleCigar, what = c("rname",
"pos", "strand", "qwidth", "isize", "mpos”))
(...)
regions = scanBam(file = paste(path, fileName, sep = "/"),
param = scanParam)
(…)
The insert size is accessed by
regions$isize
According to https://bioconductor.org/packages/devel/bioc/manuals/Rsamtools/man/Rsamtools.pdf, isize is defined as:
isize: This is the TLEN field in SAM Spec v1.4. Inferred insert size for paired end alignments.
The samtools definition on TLEN says:
If all segments are mapped to the same reference, the unsigned observed template length equals the number of bases from the leftmost mapped base to the rightmost mapped base.
Therefore, to the best of my knowledge, the insert size represents the entire sequenced DNA fragment.
Hope that helps.
All the best,
Lukas