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
      New Genomics Tools and Methods Shared at AGBT 2025
      by seqadmin


      This year’s Advances in Genome Biology and Technology (AGBT) General Meeting commemorated the 25th anniversary of the event at its original venue on Marco Island, Florida. While this year’s event didn’t include high-profile musical performances, the industry announcements and cutting-edge research still drew the attention of leading scientists.

      The Headliner
      The biggest announcement was Roche stepping back into the sequencing platform market. In the years since...
      03-03-2025, 01:39 PM
    • seqadmin
      Investigating the Gut Microbiome Through Diet and Spatial Biology
      by seqadmin




      The human gut contains trillions of microorganisms that impact digestion, immune functions, and overall health1. Despite major breakthroughs, we’re only beginning to understand the full extent of the microbiome’s influence on health and disease. Advances in next-generation sequencing and spatial biology have opened new windows into this complex environment, yet many questions remain. This article highlights two recent studies exploring how diet influences microbial...
      02-24-2025, 06:31 AM

    ad_right_rmr

    Collapse

    News

    Collapse

    Topics Statistics Last Post
    Started by seqadmin, Today, 12:50 PM
    0 responses
    10 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 03-03-2025, 01:15 PM
    0 responses
    181 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 02-28-2025, 12:58 PM
    0 responses
    275 views
    0 likes
    Last Post seqadmin  
    Started by seqadmin, 02-24-2025, 02:48 PM
    0 responses
    663 views
    0 likes
    Last Post seqadmin  
    Working...
    X