-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add first version of SequencePreprocessor (not tested and no examples)
- Loading branch information
1 parent
ca9e339
commit d729bdf
Showing
10 changed files
with
266 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 10 additions & 38 deletions
48
aaanalysis/data_handling/_backend/seq_preproc/get_sliding_aa_window.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,25 @@ | ||
""" | ||
This is a script for ... | ||
This is a script for the backend of the SequenceProcessor().get_sliding_aa_window() method. | ||
""" | ||
import pandas as pd | ||
|
||
from .get_aa_window import get_aa_window | ||
|
||
# Settings | ||
pd.set_option('expand_frame_repr', False) # Single line print for pd.Dataframe | ||
|
||
|
||
# I Helper Functions | ||
|
||
|
||
# II Main Functions | ||
def get_sliding_aa_window(seq: str, | ||
slide_start: int, | ||
slide_stop: int = None, | ||
window_size: int = 5, | ||
gap: str = '-', | ||
accept_gap: bool = True): | ||
""" | ||
Extracts sliding list_windows of amino acids from a sequence. | ||
Parameters: | ||
---------- | ||
seq : str | ||
The protein sequence from which to extract the list_windows. | ||
slide_start : int | ||
The starting position for sliding window extraction (1-based index). | ||
slide_end : int, optional | ||
The ending position for sliding window extraction (1-based index). If None, extract all possible list_windows. | ||
window_size : int, default=5 | ||
The size of each window to extract. | ||
gap : str, default='-' | ||
The character used to represent gaps. | ||
accept_gap : bool, default=True | ||
Whether to accept gaps in the list_windows. If False, list_windows containing gaps are rejected. | ||
Returns: | ||
------- | ||
List[str] | ||
A list of extracted list_windows of amino acids. | ||
""" | ||
def get_sliding_aa_window(seq=None, slide_start=0, slide_stop=None, window_size=5, gap='-', index1=False): | ||
"""Extracts sliding list_windows of amino acids from a sequence""" | ||
if slide_stop is None: | ||
slide_stop = len(seq) | ||
if not accept_gap: | ||
slide_stop -= window_size | ||
slide_stop = len(seq) - 1 | ||
if index1: | ||
slide_stop += 1 | ||
n_windows = slide_stop - window_size - slide_start + 1 | ||
list_windows = [] | ||
for start in range(slide_start, slide_stop + 1): | ||
aa_window = get_aa_window(seq, pos_start=start, window_size=window_size, gap=gap, accept_gap=accept_gap) | ||
for start in range(slide_start, slide_start + n_windows + 1): | ||
# Do not provide index1 again (it will be otherwise two time corrected) | ||
aa_window = get_aa_window(seq, pos_start=start, window_size=window_size, gap=gap) | ||
list_windows.append(aa_window) | ||
return list_windows |
Oops, something went wrong.