Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion pyaptamer/aptanet/_feature_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@
from sklearn.feature_selection import SelectFromModel
from sklearn.pipeline import Pipeline
from sklearn.utils.multiclass import type_of_target
from sklearn.utils.validation import check_is_fitted, validate_data
from sklearn.utils.validation import check_is_fitted
import sklearn
from packaging.version import Version

if Version(sklearn.__version__) >= Version("1.6"):
from sklearn.utils.validation import validate_data
else:
from sklearn.utils.validation import check_array, check_X_y

def validate_data(estimator, X, y=None, **kwargs):
if y is not None:
return estimator._validate_data(X, y, **kwargs)
return estimator._validate_data(X, **kwargs)
from torch import optim

from pyaptamer.aptanet._aptanet_nn import AptaNetMLP
Expand Down
3 changes: 3 additions & 0 deletions pyaptamer/trafos/encode/_greedy.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ def get_test_params(self):
params : dict
Test parameters for GreedyEncoder.
"""

param0 = {
"words": {"A": 1, "C": 2, "G": 3, "U": 4, "AC": 5, "GU": 6},
"max_len": 10,
}

param1 = {
"words": {"A": 1, "C": 2, "G": 3, "U": 4},
"max_len": 10,
Expand Down
33 changes: 16 additions & 17 deletions pyaptamer/utils/_rna.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,22 @@ def rna2vec(
]

# skip sequences that convert to an empty list
if any(converted):
# truncate if too long
if max_sequence_length is not None and len(converted) > max_sequence_length:
converted = converted[:max_sequence_length]

# pad if too short
if max_sequence_length is not None:
pad_length = max_sequence_length - len(converted)
padded_sequence = np.pad(
array=converted,
pad_width=(0, pad_length),
constant_values=0,
)
else:
padded_sequence = np.array(converted)

result.append(padded_sequence)
# truncate if too long
if max_sequence_length is not None and len(converted) > max_sequence_length:
converted = converted[:max_sequence_length]

# pad if too short (including empty/short sequences which become all zeros)
if max_sequence_length is not None:
pad_length = max_sequence_length - len(converted)
padded_sequence = np.pad(
array=converted,
pad_width=(0, pad_length),
constant_values=0,
)
else:
padded_sequence = np.array(converted)

result.append(padded_sequence)

return np.array(result)

Expand Down