How Do I Assign Names To Granges Without It Forcing Elementmetadata
1
0
Entering edit mode
12.0 years ago

It seems like the casting routine to assign names to GRanges from GappedAlignments is more natural than the GRanges constructor.

library("GenomicRanges")
feature1 <- GRanges(names="feature1",seqnames="chr1", IRanges(start=1, width=100), strand="*")

featureGA <- GappedAlignments(names="feature2", seqnames = Rle("chr1"), pos = as.integer(25),cigar = "100M", strand = strand("*"))
feature2<-as(feature2,"GRanges")

> feature1
GRanges with 1 range and 1 elementMetadata col:
      seqnames    ranges strand |       names
         <Rle> <IRanges>  <Rle> | <character>
  [1]     chr1  [1, 100]      * |    feature1
  ---
  seqlengths:
   chr1
     NA
> feature2
GRanges with 1 range and 0 elementMetadata cols:
       seqnames    ranges strand
          <Rle> <IRanges>  <Rle>
  feature2     chr1 [25, 124]      *
  ---
  seqlengths:
   chr1
     NA

both<-GRangesList(features=feature1,feature2=feature2)
Error in .Method(..., deparse.level = deparse.level) : 
  number of columns for arg 2 do not match those of first arg

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] GenomicRanges_1.8.4 IRanges_1.14.2      BiocGenerics_0.2.0 

loaded via a namespace (and not attached):
[1] stats4_2.15.0 tools_2.15.0
• 8.6k views
ADD COMMENT
4
Entering edit mode
12.0 years ago

Set the names() after the GRanges object is constructed:

feature1 <- GRanges(seqnames="chr1", IRanges(start=1, width=100), strand="*")
names(feature1) <- 'feature1'

featureGA <- GappedAlignments(names="feature2", seqnames = Rle("chr1"), pos = as.integer(25),cigar = "100M", strand = strand("*"))
feature2 <-as(featureGA,"GRanges")

Will almost get you what you want ...

GRangesList(features=feature1,feature2=feature2)
GRangesList of length 2:
$features 
GRanges with 1 range and 0 elementMetadata cols:
           seqnames    ranges strand
              <Rle> <IRanges>  <Rle>
  feature1     chr1  [1, 100]      *

$feature2 
GRanges with 1 range and 0 elementMetadata cols:
           seqnames    ranges strand
  feature2     chr1 [25, 124]      *

---
seqlengths:
 chr1
   NA

... almost

ADD COMMENT

Login before adding your answer.

Traffic: 2501 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6