Question: converting bam file to bed
0
gravatar for azzopardiannalise
4 months 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 • 258 views
ADD COMMENTlink modified 4 months ago by Alex Reynolds28k • written 4 months 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 months ago by WouterDeCoster38k

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 months 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 months ago by WouterDeCoster38k
1
gravatar for Alex Reynolds
4 months ago by
Alex Reynolds28k
Seattle, WA USA
Alex Reynolds28k wrote:

Via BEDOPS:

$ bam2bed < reads.bam > reads.bed
ADD COMMENTlink written 4 months ago by Alex Reynolds28k
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: 1163 users visited in the last hour