Sliding window 1 X38951


Statement
 

pdf   zip

html

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 x and overlap size xy by sliding a window of size x and step size y 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 iterative 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 s over the alphabet Σ={A,C,G,T}, an integer x (the window size), and an integer y (the step size).

Output

The output is all substrings of s of size x starting at positions 1,1+y,1+2y,…

Hint Notice that there are no “partial” substrings of s (of size smaller than x) 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