converting bam file to bed
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
• 5,869 views
•
link
1 answer
Via BEDOPS:
$ bam2bed < reads.bam > reads.bed
• 0 views
•
link
Log in to answer this question.
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?
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
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.