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
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.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 useifelse
and/or rethink the whole operation. If you already have aGRanges
, use the typical subsetting operations based on the conditional vector that you provide to theif
function.As always, please provide a fully reproducible example including the expected output.
Best,
Marcel