IRanges start bigger than end
1
0
Entering edit mode
@vedranfranke-7218
Last seen 6.0 years ago
Germany

I was just wondering why this code doesn't produce an error?

    IRanges(start=1,end=0)

 

Best regards,

Vedran

 

I'm using IRanges_2.2.9 

iranges • 1.0k views
ADD COMMENT
0
Entering edit mode

Why do you think it should produce an error? The starting position of a range has nothing to do with the width.

ADD REPLY
2
Entering edit mode
@michael-lawrence-3846
Last seen 2.3 years ago
United States

I think you mean why can the start be larger than the end? If the start is 1 less than the end, it indicates an empty range.

ADD COMMENT
0
Entering edit mode

Thank you for the prompt answer!

I edited the question for the clarification - width was a typo.

Could you please just clarify the logic behind this implementation?

I still do not see why the above creates a valid IRanges object?

 

ADD REPLY
1
Entering edit mode

Hi,

Zero-width ranges are used to represent insertion points. It might be a little bit shocking at first to see a start that is equal to end + 1 but that's because we use a representation where the interval is closed on both sides:

IRanges(11, width=3:0)
# IRanges of length 4
#     start end width
# [1]    11  13     3
# [2]    11  12     2
# [3]    11  11     1
# [4]    11  10     0

The last range is a zero-width range. It represents an insertion between positions 10 and 11. Yes it might be a little bit shocking to see that it ends before it even started but... what else could the start and end be for this range?

For example such zero-width range can be used to perform an insertion in a DNA sequence:

library(Biostrings)
## Insert 3 nucleotides between positions 10 and 11:
replaceAt(DNAString("AAAAATTTTTGG"), IRanges(11, 10), "ACA")
##   15-letter "DNAString" instance
## seq: AAAAATTTTTACAGG

Hope this helps,

H.

ADD REPLY
0
Entering edit mode

The problem arose when a student used a combination of trim(shift()) on a GRanges object, and

obtained a range with coordinates of start=1 and end=0.

This makes sense now.

Thank you so much!

 

ADD REPLY

Login before adding your answer.

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