Sliding window 2 X99827


Statement
 

pdf   zip

Recall that a string (genomic sequence) can be split in words of length 3 (codons) by sliding a window of size 3 over the string, with a step size of 3. More in general, a string can be split in overlapping words of length xx and overlap size xyx-y by sliding a window of size xx and step size yy over the string. For example, sliding a window of size 3 and step size 2 over the string TATAAT gives the overlapping words TAT and TAA.

Write code for the sliding window problem. The program must implement and use the SLIDING-WINDOW function in the pseudocode discussed in class, which is recursive and is not allowed to perform input/output operations. Make one submission with Python code and another submission with C++ code.

Input

The input is a string ss (a genomic sequence) over the alphabet Σ={A,C,G,T}\Sigma=\{A,C,G,T\}, an integer xx (the window size), and an integer yy (the step size).

Output

The output is all substrings of ss of size xx starting at positions 1,1+y,1+2y,1,1+y,1+2y,\ldots

Hint

Notice that there are no “partial” substrings of ss (of size smaller than xx) in the output.

Public test cases
  • Input

    ACGGTAGACCT
    3
    1
    

    Output

    ACG
    CGG
    GGT
    GTA
    TAG
    AGA
    GAC
    ACC
    CCT
    
  • Input

    ACGGTAGACCT
    3
    3
    

    Output

    ACG
    GTA
    GAC
    
  • Input

    ACGGTAGACCT
    3
    5
    

    Output

    ACG
    AGA
    
  • Input

    ACGGTAGACCT
    5
    2
    

    Output

    ACGGT
    GGTAG
    TAGAC
    GACCT
    
  • Information
    Author
    Gabriel Valiente
    Language
    English
    Official solutions
    C++ Python
    User solutions
    C++ Python