conditional command within GRanges
0
0
Entering edit mode
Marcus • 0
@5c953da8
Last seen 12 months ago
Germany

Hello!

I am working with SummarizedExperiment that contain genomis data. I want to extract a certaimn part of this sequence, but only if it is encoded on the reverse strand. I am using the code below but that doesnt work. When I exclude the if argument, everything works and I get the result I was looking for but when I try to include the condition, it fails. Can someone explain to me what I am doing wrong?


#**Test1:**
GRanges(
  seqnames(data1),
  if (rowRanges(data1)@strand == "-")
  {  
  IRanges(
      start(data1$nc_end), 
      end(data1)
  },
  strand(data1))

#**Test2**
GRanges(
  seqnames(data1),
  if (data1@strand == "-")
  {  
  IRanges(
      start(data1$nc_end), 
      end(data1)
  },
  strand(data1))

Results of R Session1

Error in MatrixGenerics:::.load_next_suggested_package_to_search(x) : Failed to find a rowRanges() method for GRanges objects.

Results of R Session2

Error in if (includedExonsLMI@strand == "+") { : argument is not interpretable as logical

SummarizedExperiment • 868 views
ADD COMMENT
1
Entering edit mode

I can't reproduce your issue because you did not provided an example of your dataset (example with dput(head(data1)), but in the first case you use rowRanges() which require an input of type "matrix, array, or numeric" (https://rdrr.io/bioc/MatrixGenerics/man/rowRanges.html). In the second case, there is a missing parenthesis which doesn't close the IRanges() function so it cannot work.

ADD REPLY
0
Entering edit mode

I'm not sure I understand what you're trying to do. if should evaluate a scalar, it looks like you're using a vector. Perhaps use ifelse and/or rethink the whole operation. If you already have a GRanges, use the typical subsetting operations based on the conditional vector that you provide to the if function.

As always, please provide a fully reproducible example including the expected output.

Best,

Marcel

ADD REPLY

Login before adding your answer.

Traffic: 748 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