2015-04-15 7 views
5

ओवरलैपिंग क्षेत्र के लिए आप ओवरलैपिंग निर्देशांक कैसे प्राप्त करते हैं और संबंधित seg.mean मान निकालते हैं?ओवरलैपिंग क्षेत्र खोजें और संबंधित मान निकालें

data1 
     Rl  pValue  chr start end  CNA 
     2  2.594433 6 129740000 129780000 gain 
     2  3.941399 6 130080000 130380000 gain 
     1  1.992114 10 80900000 81100000 gain 
     1  7.175750 16 44780000 44920000 gain 

data2

ID  chrom loc.start loc.end num.mark seg.mean 
8410  6  129750000 129760000  8430 0.0039 
8410  10 80907000 81000000  5 -1.7738 
8410  16 44790000 44910000  12 0.0110 

dataoutput

Rl  pValue  chr start end  CNA seg.mean 
    2  2.594433 6 129750000 129760000 gain 0.0039 
    1  1.992114 10 80907000 81000000 gain -1.7738 
    1  7.175750 16 44790000 44910000 gain 0.0110 
+3

'लाइब्रेरी (डेटा.table); ? foverlaps' – Roland

+0

मैंने इस तरह से कोशिश की x <- setDT (data1) y <- setDT (data2) सेटकी (वाई, क्रोम, loc.start, loc.end, seg.mean) foverlaps (x, y, by.x = c ("chr", "start", "end"), टाइप = "कोई", जो = TRUE)। Foverlaps में त्रुटि (एक्स, वाई, by.x = c ("chr", "start", "end"), टाइप = "कोई"): लंबाई (by.x)! = लंबाई (by.y)। By.x में निर्दिष्ट कॉलम द्वारा निर्दिष्ट कॉलम के अनुरूप होना चाहिए और समान लंबाई का होना चाहिए। – Kryo

उत्तर

5

हम जीनोमिक्स डेटा के साथ Granges वस्तुओं के रूप में डेटा रखने के लिए आसान है काम कर रहे हैं, तो हम इस्तेमाल कर सकते हैं - mergeByOverlaps(g1,g2)GenomicRanges पैकेज से, उदाहरण के नीचे देखें:

library("GenomicRanges") 

#data 
x1 <- read.table(text="Rl  pValue  chr start end  CNA 
     2  2.594433 6 129740000 129780000 gain 
     2  3.941399 6 130080000 130380000 gain 
     1  1.992114 10 80900000 81100000 gain 
     1  7.175750 16 44780000 44920000 gain",header=TRUE) 

x2 <- read.table(text="ID  chrom loc.start loc.end num.mark seg.mean 
8410  6  129750000 129760000  8430 0.0039 
8410  10 80907000 81000000  5 -1.7738 
8410  16 44790000 44910000  12 0.0110",header=TRUE) 

g1 <- GRanges(seqnames=paste0("chr",x1$chr), 
       IRanges(start=x1$start, 
         end=x1$end), 
       CNA=x1$CNA, 
       Rl=x1$Rl) 


g2 <- GRanges(seqnames=paste0("chr",x2$chrom), 
       IRanges(start=x2$loc.start, 
         end=x2$loc.end), 
       ID=x2$ID, 
       num.mark=x2$num.mark, 
       seq.mean=x2$seg.mean) 

mergeByOverlaps(g1,g2) 
# DataFrame with 3 rows and 7 columns 
#        g1  CNA  Rl        g2  ID num.mark seq.mean 
#      <GRanges> <factor> <integer>      <GRanges> <integer> <integer> <numeric> 
# 1 chr6:*:[129740000, 129780000]  gain   2 chr6:*:[129750000, 129760000]  8410  8430 0.0039 
# 2 chr10:*:[ 80900000, 81100000]  gain   1 chr10:*:[ 80907000, 81000000]  8410   5 -1.7738 
# 3 chr16:*:[ 44780000, 44920000]  gain   1 chr16:*:[ 44790000, 44910000]  8410  12 0.0110 

संपादित करें : जोड़ा गया sessionInfo() आउटपुट:

R version 3.2.0 (2015-04-16) 
Platform: x86_64-w64-mingw32/x64 (64-bit) 
Running under: Windows 7 x64 (build 7601) Service Pack 1 

locale: 
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252 LC_MONETARY=English_United Kingdom.1252 
[4] LC_NUMERIC=C       LC_TIME=English_United Kingdom.1252  

attached base packages: 
[1] stats4 parallel stats  graphics grDevices utils  datasets methods base  

other attached packages: 
[1] GenomicRanges_1.20.3 GenomeInfoDb_1.4.0 IRanges_2.2.1  S4Vectors_0.6.0  BiocGenerics_0.14.0 
[6] BiocInstaller_1.18.1 

loaded via a namespace (and not attached): 
[1] XVector_0.8.0 tools_3.2.0 
+0

मैंने इसे http://stackoverflow.com/questions/29991606/merge-two-data-frame-with-condition-in-r/29992398?noredirect=1#29991606 पर करने की कोशिश की, लेकिन 'mergeByOverlaps (g1, g2) # त्रुटि: फ़ंक्शन "mergeByOverlaps" नहीं मिला, हालांकि मैंने 'जीनोमिक रेंज' लोड किया था। मैं 'GenomicRanges_1.16.4' – akrun

+0

@akrun का उपयोग कर रहा हूं 'sessionInfo()', अभी चेक किया गया है और यह काम करता है। – zx8754

+0

मैं यह देखने के लिए बायोकंडक्टर को अपग्रेड करने का प्रयास कर रहा हूं कि यह काम करता है या नहीं। मैंने अभी GenomicRanges स्थापित किया है, लेकिन यह '1.16.4' संस्करण है। – akrun

7

@Roland के रूप में सही ढंग से सुझाव दिया है, यहाँ एक संभव data.table::foverlaps समाधान है

library(data.table) 
setDT(data1) ; setDT(data2) # Convert data sets to data.table objects 
setnames(data2, c("loc.start", "loc.end"), c("start", "end")) # Rename columns so they will match in both sets 
setkey(data2, start, end) # key the smaller data so foverlaps will work 
foverlaps(data1, data2, nomatch = 0L)[, 1:5 := NULL][] # run foverlaps and remove the unnecessary columns 
# seg.mean Rl pValue chr i.start  i.end CNA 
# 1: 0.0039 2 2.594433 6 129740000 129780000 gain 
# 2: -1.7738 1 1.992114 10 80900000 81100000 gain 
# 3: 0.0110 1 7.175750 16 44780000 44920000 gain 

या

indx <- foverlaps(data1, data2, nomatch = 0L, which = TRUE) # run foverlaps in order to find indexes using `which` 
data1[indx$xid][, seg.mean := data2[indx$yid]$seg.mean][] # update matches 
# Rl pValue chr  start  end CNA seg.mean 
# 1: 2 2.594433 6 129740000 129780000 gain 0.0039 
# 2: 1 1.992114 10 80900000 81100000 gain -1.7738 
# 3: 1 7.175750 16 44780000 44920000 gain 0.0110 
संबंधित मुद्दे