Summary
Class to downsample a SAM/BAM file based on the position of the read in a flowcell. As with
DownsampleSam, all the
reads with the same queryname are either kept or dropped as a unit.
Details
The downsampling is
not random (and there is no random seed). It is deterministically determined by the position
of each read within its tile. Specifically, it draws an ellipse that covers a
FRACTION of the total tile's
area and of all the edges of the tile. It uses this area to determine whether to keep or drop the record. Since reads
with the same name have the same position (mates, secondary and supplemental alignments), the decision will be the
same for all of them. The main concern of this downsampling method is that due to "optical duplicates" downsampling
randomly can create a result that has a different optical duplicate rate, and therefore a different estimated library
size (when running MarkDuplicates). This method keeps (physically) close read together, so that (except
for reads near the boundary of the circle) optical duplicates are kept or dropped as a group.
By default the program expects the read names to have 5 or 7 fields separated by colons (:), and it takes the last two
to indicate the x and y coordinates of the reads within the tile whence it was sequenced. See
ReadNameParser.DEFAULT_READ_NAME_REGEX for more detail. The program traverses the
INPUT twice: first
to find out the size of each of the tiles, and next to perform the downsampling.
Downsampling invalidates the duplicate flag because duplicate reads before downsampling may not all remain duplicated
after downsampling. Thus, the default setting also removes the duplicate information.
Example
java -jar picard.jar PositionBasedDownsampleSam \
I=input.bam \
O=downsampled.bam \
FRACTION=0.1
Caveats
-
This method is technology and read-name dependent. If the read-names do not have coordinate information
embedded in them, or if your BAM contains reads from multiple technologies (flowcell versions, sequencing machines).
this will not work properly. It has been designed to work with Illumina technology and reads-names. Consider
modifying
READ_NAME_REGEX in other cases.
-
The code has been designed to simulate, as accurately as possible, sequencing less, not for getting an exact
downsampled fraction (Use
DownsampleSam for that.) In particular, since the reads may be distributed non-evenly
within the lanes/tiles, the resulting downsampling percentage will not be accurately determined by the input argument
FRACTION.
-
Consider running
MarkDuplicates after downsampling in order to "expose" the duplicates whose representative has
been downsampled away.
-
The downsampling assumes a uniform distribution of reads in the flowcell.
Input already downsampled with PositionBasedDownsampleSam violates this assumption.
To guard against such input,
PositionBasedDownsampleSam always places a PG record in the header of its output,
and aborts whenever it finds such a PG record in its input.