Untitled
unknown
python
2 years ago
1.1 kB
11
Indexable
def generate_windows(chromosome_size: int, window_size: int, print_results: bool = False) -> list: # For the love of god, use type hinting. # Empty list to store all the results windows = [] # Iterate over the chromosome in steps equal to the window size. # 'start' begins from 1 and goes up to chromosome_size in steps of window_size. for start in range(1, chromosome_size + 1, window_size): # Calculate the end of the window. # It's the minimum of 'start + window_size - 1' and 'chromosome_size' # to ensure the window doesn't exceed the chromosome size. end = min(start + window_size - 1, chromosome_size) # Append the window range (start-end) as a string to the windows list. windows.append(f"{start}-{end}") # print if set to true if print_results: print(windows) return windows # Usage: CHROMOSOME_SIZE = 100 WINDOW_SIZE = 20 results = generate_windows(CHROMOSOME_SIZE, WINDOW_SIZE, True) # do optional stuff with the results here... #PS: you can give me cash payment once I go to france.
Editor is loading...
Leave a Comment