Seqanswers Leaderboard Ad

Collapse

Announcement

Collapse
No announcement yet.
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • plotting graph in R from a bed file

    Hi Everyone,

    I have a bed file. I am showing you a section of the bed file.

    Code:
    Slc19a1	81	144	1
    Slc19a1	192	255	6
    Slc19a1	273	336	7
    Slc19a1	363	426	4
    Slc19a1	465	528	3
    Slc19a1	540	603	5
    Slc19a1	813	876	5
    Slc19a1	912	975	6
    Slc19a1	987	1050	8
    Slc19a1	1062	1125	6
    Slc19a1	1170	1233	8
    Slc19a1	1278	1341	6
    The 4th column is the number of reads for particular interval. For eg the read count is 6 for the interval 192-255.

    I want to draw a histogram in R for these intervals with x axis having the intervals and y axis the counts

    How can I do it. I am a beginner in R.

    Thanks for the help

    Regards

  • #2
    There will be a lot of fiddling to get it to look better, but here is my approach.

    1. Get the data into a dataframe.

    I use this function to read from the clipboard on a mac. You can also use read.table to read the whole bed file more efficiently:

    Code:
    >cboardf<- function(){
    >read.table(pipe("pbpaste"),sep='\t',header=F)}
    
    > d <- cboardf()
    
    > str(d)
    'data.frame':	12 obs. of  4 variables:
     $ V1: Factor w/ 1 level "Slc19a1": 1 1 1 1 1 1 1 1 1 1 ...
     $ V2: int  81 192 273 363 465 540 813 912 987 1062 ...
     $ V3: int  144 255 336 426 528 603 876 975 1050 1125 ...
     $ V4: int  1 6 7 4 3 5 5 6 8 6 ...
    2. Then you need to make a "name" for your regions...just a string...

    Code:
    > d$V5 <- paste(d$V2,"-",d$V3)  #make a new string for the region in column called V5
    
    > str(d)
    'data.frame':	12 obs. of  5 variables:
     $ V1: Factor w/ 1 level "Slc19a1": 1 1 1 1 1 1 1 1 1 1 ...
     $ V2: int  81 192 273 363 465 540 813 912 987 1062 ...
     $ V3: int  144 255 336 426 528 603 876 975 1050 1125 ...
     $ V4: int  1 6 7 4 3 5 5 6 8 6 ...
     $ V5: chr  "81 - 144" "192 - 255" "273 - 336" "363 - 426" ...
    3. Then make a plot (using ggplot2)

    Code:
    qplot(V5,V4,data=d,geom='bar') + opts(axis.text.x=theme_text(angle=90))
    Voila:


    You'll have to work a lot harder to make it look better, label axes is easy, sorting the X regions is more annoying, but pretty easy.

    Good luck.

    Comment

    Latest Articles

    Collapse

    • seqadmin
      Recent Advances in Sequencing Analysis Tools
      by seqadmin


      The sequencing world is rapidly changing due to declining costs, enhanced accuracies, and the advent of newer, cutting-edge instruments. Equally important to these developments are improvements in sequencing analysis, a process that converts vast amounts of raw data into a comprehensible and meaningful form. This complex task requires expertise and the right analysis tools. In this article, we highlight the progress and innovation in sequencing analysis by reviewing several of the...
      05-06-2024, 07:48 AM
    • seqadmin
      Essential Discoveries and Tools in Epitranscriptomics
      by seqadmin




      The field of epigenetics has traditionally concentrated more on DNA and how changes like methylation and phosphorylation of histones impact gene expression and regulation. However, our increased understanding of RNA modifications and their importance in cellular processes has led to a rise in epitranscriptomics research. “Epitranscriptomics brings together the concepts of epigenetics and gene expression,” explained Adrien Leger, PhD, Principal Research Scientist...
      04-22-2024, 07:01 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by seqadmin, Yesterday, 06:35 AM
    0 responses
    15 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 05-09-2024, 02:46 PM
    0 responses
    21 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 05-07-2024, 06:57 AM
    0 responses
    18 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 05-06-2024, 07:17 AM
    0 responses
    19 views
    0 likes
    Last Post seqadmin  
    Working...
    X