Unconfigured Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aevgup
    Member
    • Jul 2011
    • 17

    #1

    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
  • ECO
    --Site Admin--
    • Oct 2007
    • 1360

    #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

    • SEQadmin2
      Multiomic Liquid Biopsy: What DNA/RNA Panels Reveal That DNA Alone Can’t
      by SEQadmin2



      Tumors contain complex mixtures of cell populations that evolve in response to treatment and host-specific factors. Tissue biopsies provide only static snapshots of a tumor’s state. But what if we could follow that evolution over time using a minimally invasive technique?

      Liquid biopsies can detect tumor-derived material circulating in the bloodstream, providing a way to study treatment response, detect emerging resistance, and discover new biomarkers. Circulating
      ...
      10-14-2026, 09:55 AM
    • SEQadmin2
      New Genomics Technologies Take Aim at Long-Standing Limits
      by SEQadmin2


      Researchers using sequencing and genomics tools often have to make trade-offs. They can choose between speed or scale, short reads or long-range information, or targeted panels or a view of the whole transcriptome. New technologies that have been released this year are built to address those tough choices.

      We asked six companies the same four questions to learn about their latest products. The new technologies bring a lot to the table, including rethinking sequencing
      ...
      09-28-2026, 10:25 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by SEQadmin2, 10-22-2026, 11:13 AM
    0 responses
    23 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-22-2026, 10:48 AM
    0 responses
    20 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-15-2026, 10:52 AM
    0 responses
    36 views
    0 reactions
    Last Post SEQadmin2  
    Started by SEQadmin2, 10-14-2026, 05:39 AM
    0 responses
    42 views
    0 reactions
    Last Post SEQadmin2  
    Working...