Question: converting bam file to bed
0
gravatar for azzopardiannalise
4 weeks ago by
azzopardiannalise0 wrote:

Hi,

I am trying to convert a bam file to a bed file using R software however, I am currently unsuccessful. The below is what I have inputted so far in R-software can anyone help me please?

#load library
library(Rsamtools)
library(RNAseqData.HNRNPC.bam.chr14)
library(GenomicAlignments)
bamfile <- file.path("C:","Users","azzop","Desktop","I16-1144-01-esd_m1_CGCTCATT-AGGCGAAG_tophat2","accepted_hits.bam")

system(paste("bedtools bamtobed -i", bamfile, "> myBed.bed"))
library(data.table)
myData <- fread("myBed.bed")

Does anyone know how I can use the package bedtools in R? What am I doing is it correct?

Also, my goal is to combine more than 1 bam file together as I have 9 bam files and I would need to analyze the data holistically? Any suggestions?

Thanks, A

R • 146 views
ADD COMMENTlink modified 4 weeks ago by Alex Reynolds27k • written 4 weeks ago by azzopardiannalise0

The first question would be why you are trying to do this in R... Looks you are using windows, can you use the WSL/Ubuntu?

ADD REPLYlink written 4 weeks ago by WouterDeCoster36k

Yes I am using windows as this is part of my dissertation for MSc in statistics and I will be using R stoftware to analyze the data

ADD REPLYlink written 4 weeks ago by azzopardiannalise0
2

If you are using Windows 10 I recommend WSL: the Windows Subsystem for Linux. That will make your work a lot easier.

R is a programming language. While you technically can execute bedtools through R you are then no longer using R itself. It's just a vehicle to execute bedtools and it adds an unnecessary layer of complexity.

ADD REPLYlink written 4 weeks ago by WouterDeCoster36k
1
gravatar for Alex Reynolds
4 weeks ago by
Alex Reynolds27k
Seattle, WA USA
Alex Reynolds27k wrote:

Via BEDOPS:

$ bam2bed < reads.bam > reads.bed
ADD COMMENTlink written 4 weeks ago by Alex Reynolds27k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 806 users visited in the last hour