bamWriter-class: Class '"bamWriter"': Representation of a file connection to a...

Description Objects from the Class Slots Methods Author(s) References Examples

Description

The bamWriter class represents the writing connection to a BAM-file. Usually, this class is used to create an empty BAM-file and to copy aligns from another BAM-file into the new file.

Objects from the Class

Objects can be created by calls of the form writer<-bamWriter(reader,filename).

Slots

filename:

Object of class "character".

writer:

Object of class "externalptr". Points to samtools struct samtile_t.

Methods

bamClose

signature(object = "bamWriter"): Closes BAM file.

bamSave

signature(object = "bamWriter", value = "bamAlign" or "bamRange",refid = "numeric"): Saves bamAlign or bamRange object to BAM-file. refid will be overwritten in all written aligns.

filename

signature(object = "bamWriter"): Returns filename of opened BAM-file.

initialize

signature(.Object = "bamWriter"): Opens BAM file for writing.

isOpen

signature(object = "bamWriter"): Returns TRUE when file connection is open.

Author(s)

Wolfgang Kaisers

References

The SAM Format Specification (v1.4-r985). The SAM Format Specification Working Group. September 7, 2011.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# +++++++++++++++++++++++++++++++++++++++++++++++
# In this example, we copy some complex (i.e. interesting) aligns
# into a new BAM file
bam<-system.file("extdata", "accepted_hits.bam", package="rbamtools")
idx<-paste(bam,"bai",sep=".")

# +++++++++++++++++++++++++++++++++++++++++++++++
# Open BAM file and read complex aligns from chr1
reader<-bamReader(bam)
loadIndex(reader,idx)
coords<-as.integer(c(0,0,249250621))
range<-bamRange(reader,coords,complex=TRUE)
bamClose(reader)
# +++++++++++++++++++++++++++++++++++++++++++++++

# +++++++++++++++++++++++++++++++++++++++++++++++
#  Create bamHeader from scratch
bh<-new("bamHeaderText")
headl<-new("headerLine")
setVal(headl,"SO","coordinate")
dict<-new("refSeqDict")
addSeq(dict,SN="chr1",LN=249250621)
addSeq(dict,SN="chr10",LN=135534747)
dict
prog<-new("headerProgram")
setVal(prog,"ID","1")
setVal(prog,"PN","tophat")
setVal(prog,"CL","tophat -p8 --library-type fr-unstranded hs_ucsc test.fq")
setVal(prog,"VN","2.0.0")
bh<-bamHeaderText(head=headl,dict=dict,prog=prog)
#getHeaderText(bh)
header<-bamHeader(bh)
# +++++++++++++++++++++++++++++++++++++++++++++++

# +++++++++++++++++++++++++++++++++++++++++++++++
#  Copy aligns in range into new BAM file

writer<-bamWriter(header, "chr1_complex.bam")
bamSave(writer, range, refid=0)
bamClose(writer)

# +++++++++++++++++++++++++++++++++++++++++++++++

rbamtools documentation built on Nov. 11, 2019, 5:09 p.m.