MCPcopy Create free account
hub / github.com/DunbrackLab/IPSAE / contiguous_ranges

Function contiguous_ranges

ipsae.py:269–296  ·  view source on GitHub ↗
(numbers)

Source from the content-addressed store, hash-verified

267
268# Function for printing out residue numbers in PyMOL scripts
269def contiguous_ranges(numbers):
270 if not numbers: # Check if the set is empty
271 return
272
273 sorted_numbers = sorted(numbers) # Sort the numbers
274 start = sorted_numbers[0]
275 end = start
276 ranges = [] # List to store ranges
277
278 def format_range(start, end):
279 if start == end:
280 return f"{start}"
281 else:
282 return f"{start}-{end}"
283
284 for number in sorted_numbers[1:]:
285 if number == end + 1:
286 end = number
287 else:
288 ranges.append(format_range(start, end))
289 start = end = number
290
291 # Append the last range after the loop
292 ranges.append(format_range(start, end))
293
294 # Join all ranges with a plus sign and print the result
295 string='+'.join(ranges)
296 return(string)
297
298# Initializes a nested dictionary with all values set to 0
299def init_chainpairdict_zeros(chainlist):

Callers 1

ipsae.pyFile · 0.85

Calls 1

format_rangeFunction · 0.85

Tested by

no test coverage detected