MCPcopy Index your code
hub / github.com/InternScience/InternAgent / PertData

Class PertData

tasks/AutoTPPR/code/experiment.py:915–1372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

913 return False
914
915class PertData:
916 def __init__(self, data_path,
917 gene_set_path=None,
918 default_pert_graph=True):
919
920 # Dataset/Dataloader attributes
921 self.data_path = data_path
922 self.default_pert_graph = default_pert_graph
923 self.gene_set_path = gene_set_path
924 self.dataset_name = None
925 self.dataset_path = None
926 self.adata = None
927 self.dataset_processed = None
928 self.ctrl_adata = None
929 self.gene_names = []
930 self.node_map = {}
931
932 # Split attributes
933 self.split = None
934 self.seed = None
935 self.subgroup = None
936 self.train_gene_set_size = None
937
938 if not os.path.exists(self.data_path):
939 os.mkdir(self.data_path)
940 server_path = 'https://dataverse.harvard.edu/api/access/datafile/6153417'
941 with open(os.path.join(self.data_path, 'gene2go_all.pkl'), 'rb') as f:
942 self.gene2go = pickle.load(f)
943
944 def set_pert_genes(self):
945 """
946 Set the list of genes that can be perturbed and are to be included in
947 perturbation graph
948 """
949
950 if self.gene_set_path is not None:
951 # If gene set specified for perturbation graph, use that
952 path_ = self.gene_set_path
953 self.default_pert_graph = False
954 with open(path_, 'rb') as f:
955 essential_genes = pickle.load(f)
956
957 elif self.default_pert_graph is False:
958 # Use a smaller perturbation graph
959 all_pert_genes = get_genes_from_perts(self.adata.obs['condition'])
960 essential_genes = list(self.adata.var['gene_name'].values)
961 essential_genes += all_pert_genes
962
963 else:
964 # Otherwise, use a large set of genes to create perturbation graph
965 server_path = 'https://dataverse.harvard.edu/api/access/datafile/6934320'
966 path_ = os.path.join(self.data_path,
967 'essential_all_data_pert_genes.pkl')
968 with open(path_, 'rb') as f:
969 essential_genes = pickle.load(f)
970
971 gene2go = {i: self.gene2go[i] for i in essential_genes if i in self.gene2go}
972

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected