rnaglib.transforms.FeaturesComputer¶
- class rnaglib.transforms.FeaturesComputer(nt_features=None, nt_targets=None, rna_features=None, rna_targets=None, bp_features=None, bp_targets=None, extra_useful_keys=None, custom_encoders=None)[source]¶
This class takes as input an RNA in the networkX form and computes the
features_dict
which maps node IDs to a tensor of features. Thefeatures_dict
contains keys:'nt_features'``for node features, ``'nt_targets'
for node-level prediction targets. InRNADataset
construction, theFeaturesComputer.compute_features()
method is called during theRNADataset
__getitem__()
call.- Parameters:
nt_features (
Union
[List
,str
,None
]) – List of keys to use as node features, choose from the dataset[i][‘rna’] node attributes dictionary.nt_targets (
Union
[List
,str
,None
]) – List of keys to use as node features, choose from the dataset[i][‘rna’] node attributes dictionary.rna_features (
Union
[List
,str
,None
]) –rna_targets (
Union
[List
,str
,None
]) –bp_features (
Union
[List
,str
,None
]) –bp_targets (
Union
[List
,str
,None
]) –post_transform –
extra_useful_keys (
Union
[List
,str
,None
]) –
- __init__(nt_features=None, nt_targets=None, rna_features=None, rna_targets=None, bp_features=None, bp_targets=None, extra_useful_keys=None, custom_encoders=None)[source]¶
Methods
__init__
([nt_features, nt_targets, ...])add_feature
([feature_names, ...])Update the input/output feature selector with either an extra available named feature or a custom encoder :type feature_names: :param feature_names: Name of the input feature to add :param transforms: A Transform object to compute new features with :type input_feature: :param input_feature: Set to true to modify the input feature encoder, false for the target one :return: None
build_edge_feature_parser
([asked_features])build_feature_parser
([asked_features, ...])This function will load the predefined feature maps available globally.
compute_dim
(node_parser)Based on the encoding scheme, we can compute the shapes of the in and out tensors
encode_nodes
(g, node_parser)Simply apply the node encoding functions in node_parser to each node in the graph Then use torch.cat over the result to get a tensor for each node in the graph.
encode_rna
(g, parser)Simply apply the rna encoding functions in
parser
for all features.forward
(rna_dict)Add 3 dictionaries to the rna_dict wich maps nts, edges, and the whole graph to a feature vector each.
remove_feature
([feature_name, input_feature])Update the input/output feature selector with either an extra available named feature or a custom encoder :type feature_name: :param feature_name: Name of the input feature to remove :type input_feature: :param input_feature: Set to true to modify the input feature encoder, false for the target one :return: None
remove_useless_keys
(rna_graph)Copy the original graph to only retain keys relevant to this FeaturesComputer :type rna_graph: :param rna_graph: :return:
Attributes
input_dim
output_dim