range

Processing the input file based on range overlap

亡梦爱人 提交于 2019-12-17 20:16:18
问题 I have a huge input file (a representative sample of which is shown below as input ): > input CT1 CT2 CT3 1 chr1:200-400 chr1:250-450 chr1:400-800 2 chr1:800-970 chr2:200-500 chr1:700-870 3 chr2:300-700 chr2:600-1000 chr2:700-1400 I want to process it by following some rules (described below) so that I get an output like: > output CT1 CT2 CT3 chr1:200-400 1 1 0 chr1:800-970 1 0 0 chr2:300-700 1 1 0 chr1:250-450 1 1 0 chr2:200-500 1 1 0 chr2:600-1000 0 1 1 chr1:400-800 0 0 1 chr1:700-870 0 1 1

Changing the number of iterations in a for loop

房东的猫 提交于 2019-12-17 19:58:12
问题 I have code like this: loopcount = 3 for i in range(1, loopcount) somestring = '7' newcount = int(somestring) loopcount = newcount so what I want is to modify the range of the for 'inside' the loop. I wrote this code expecting the range of the for loop would change to (1,7) during the first loop, but it didn't happen. Instead, no matter what number I put in, it only runs 2 times. (I want 6 times.. in this case) I checked the value using print like this: loopcount = 3 for i in range(1,

Keep text selection when focus changes

时光毁灭记忆、已成空白 提交于 2019-12-17 19:52:37
问题 I have a normal textbox, and a lightbox with a text input. I want to keep the user's selection in the textbox, even when the user focuses on the lightbox's text input. Select text in normal textbox Toggle lightbox Focus on lightbox input At step 3., the user's text selection is discarded. How can this be prevented? See Google docs link insertion lightbox for example. Thanks :) Update Ok, so Google docs uses an iframe for the blank page section, which is how they are handling the multiple

Regular expression for a date range

喜你入骨 提交于 2019-12-17 19:49:21
问题 If I have a directory structure like this yyyy/dd/mm/<files> Is there a way to grep for a string in all files in a given time frame using a regex? For example, I have a time frame: 2010/12/25 - 2011/01/01, I need to grep all files in directories corresponding to dates from 25th december to jan 1st If I am doing this programmatically, is it better to iterate over the date range and grep files in each yyyy/dd/mm directory than to use a regex to do this? Or would it not make a difference? 回答1:

Ruby: intersection between two ranges

非 Y 不嫁゛ 提交于 2019-12-17 19:16:09
问题 In ruby, given two date ranges, I want the range that represents the intersection of the two date ranges, or nil if no intersection. For example: (Date.new(2011,1,1)..Date.new(2011,1,15)) & (Date.new(2011,1,10)..Date.new(2011,2,15)) => Mon, 10 Jan 2011..Sat, 15 Jan 2011 Edit: Should have said that I want it to work for DateTime as well, so interval can be down to mins and secs: (DateTime.new(2011,1,1,22,45)..Date.new(2011,2,15)) & (Date.new(2011,1,1)..Date.new(2011,2,15)) => Sat, 01 Jan 2011

Merging overlapping ranges in PHP arrays?

醉酒当歌 提交于 2019-12-17 18:28:37
问题 I have an array in the following format: array( 0 => array(1, 5), 1 => array(4, 8), 2 => array(19, 24), 3 => array(6, 9), 4 => array(11, 17), ); Where each item is a X-to-Y range. What I would like to merge the overlapping ranges in the array, to get something more like this: array( 0 => array(1, 9), // 1-5, 4-8 and 6-9 are overlapping, so they are merged 1 => array(11, 17), 2 => array(19, 24), ); What would be the best way to accomplish this? 回答1: Untested, but the idea here is to sort the

Excel VBA worksheet.names vs worksheet.range

偶尔善良 提交于 2019-12-17 16:52:58
问题 I have created a defined name/range on a worksheet called bob , pointing to a single cell. There are a number of other name/ranges set up on this worksheet, which I didn't create. All the number/ranges work perfectly except for mine. I should be able to refer to the contents of this cell by using either of the following statements: (worksheet object).Names("bob").RefersToRange.Value (worksheet object).Range("bob").Value However, only the second statement, referring to the Range works for some

Java - limit number between min and max

僤鯓⒐⒋嵵緔 提交于 2019-12-17 16:45:11
问题 I want to return the number as long as it falls within a limit, else return the maximum or minimum value of the limit. I can do this with a combination of Math.min and Math.max . public int limit(int value) { return Math.max(0, Math.min(value, 10)); } I'm wondering if there's an existing limit or range function I'm overlooking. 3rd party libraries welcome if they are pretty common (eg: Commons or Guava) 回答1: As of version 21, Guava includes Ints.constrainToRange() (and equivalent methods for

range and xrange for 13-digit numbers in Python?

微笑、不失礼 提交于 2019-12-17 16:35:39
问题 range() and xrange() work for 10-digit-numbers. But how about 13-digit-numbers? I didn't find anything in the forum. 回答1: You could try this. Same semantics as range: import operator def lrange(num1, num2 = None, step = 1): op = operator.__lt__ if num2 is None: num1, num2 = 0, num1 if num2 < num1: if step > 0: num1 = num2 op = operator.__gt__ elif step < 0: num1 = num2 while op(num1, num2): yield num1 num1 += step >>> list(lrange(138264128374162347812634134, 138264128374162347812634140))

How can the built-in range function take a single argument or three?

风格不统一 提交于 2019-12-17 16:34:07
问题 I would like to know, if anyone can tell me, how the range function can take either: a single argument, range(stop) , or range(start, stop) , or range(start, stop, step) . Does it use a variadic argument like *arg to gather the arguments, and then use a series of if statements to assign the correct values depending on the number of arguments supplied? In essence, does range() specify that if there is one argument, then it set as the stop argument, or if there are two then they are start , and