Hi Alex Wu,
Very interesting concept. thanks for sharing the github. I'm facing a error in the last step. looks like it has more to do with torch but I was not able to debug.
code :X = ad.X.toarray() if issparse(ad.X) else ad.X
Y = data1.X.toarray() if issparse(data1.X) else data1.X
X_feature_names = ad.var.index.values
Y_feature_names = data1.var.index.values
candidate_XY_pairs = [(x,y) for x,y in candidates_df[['atac_id','gene']].values]
File ~/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, *kwargs)
1496 # If we don't have any hooks, we want to skip the rest of the logic in
1497 # this function, and just call forward.
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1499 or _global_backward_pre_hooks or _global_backward_hooks
1500 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1501 return forward_call(args, **kwargs)
1502 # Do not call functions when jit is used
1503 full_backward_hooks, non_full_backward_hooks = [], []
File ~/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, *kwargs)
1496 # If we don't have any hooks, we want to skip the rest of the logic in
1497 # this function, and just call forward.
1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks
1499 or _global_backward_pre_hooks or _global_backward_hooks
1500 or _global_forward_hooks or _global_forward_pre_hooks):
-> 1501 return forward_call(args, **kwargs)
1502 # Do not call functions when jit is used
1503 full_backward_hooks, non_full_backward_hooks = [], []
Hi Alex Wu, Very interesting concept. thanks for sharing the github. I'm facing a error in the last step. looks like it has more to do with torch but I was not able to debug. code :X = ad.X.toarray() if issparse(ad.X) else ad.X Y = data1.X.toarray() if issparse(data1.X) else data1.X X_feature_names = ad.var.index.values Y_feature_names = data1.var.index.values candidate_XY_pairs = [(x,y) for x,y in candidates_df[['atac_id','gene']].values]
results_df = gridnet.run_gridnet(X,Y,X_feature_names,Y_feature_names, candidate_XY_pairs,dag_adjacency_matrix,device="cpu",shuffle=False,)
Error:
IndexError Traceback (most recent call last) Cell In [227], line 7 4 Y_feature_names = data1.var.index.values 5 candidate_XY_pairs = [(x,y) for x,y in candidates_df[['atac_id','gene']].values] ----> 7 results_df = gridnet.run_gridnet(X,Y,X_feature_names,Y_feature_names, 8 candidate_XY_pairs,dag_adjacency_matrix,device="cpu",shuffle=False)
File ~/miniconda3/lib/python3.9/site-packages/gridnet/train.py:107, in run_gridnet(X, Y, X_feature_names, Y_feature_names, candidate_XY_pairs, dag_adjacency_matrix, n_layers, device, seed, shuffle, batch_size, optim, initial_learning_rate, beta_1, beta_2, max_epochs, train_separate, save_dir, save_name, verbose) 102 train_model(model,Y,X,Y_idx[shuffled_idx_list],X_idx[shuffled_idx_list], 103 pairs_idx[shuffled_idx_list],optimizer,device,max_epochs,batch_size, 104 criterion=nn.MSELoss(),early_stop=True,tol=0.1/len(candidate_XY_pairs), 105 verbose=verbose,S_0=S_0,S_1=S_1,train_separate=False) 106 else: --> 107 train_model(model,Y,X,Y_idx,X_idx,pairs_idx,optimizer,device,max_epochs,batch_size, 108 criterion=nn.MSELoss(),early_stop=True,tol=0.1/len(candidate_XY_pairs), 109 verbose=verbose,S_0=S_0,S_1=S_1,trainseparate=False) 111 ,results_dict = run_epoch('Inference',Y,X,Y_idx,X_idx,pairs_idx, 112 S_0,S_1,model,optimizer,device,batch_size,criterion=nn.MSELoss(), 113 verbose=verbose,train=False,statistics=['rss_ratio','ftest']) 115 if not os.path.exists(save_dir):
File ~/miniconda3/lib/python3.9/site-packages/gridnet/train.py:140, in train_model(model, rna_X, atac_X, rna_idx, atac_idx, pair_idx, optimizer, device, num_epochs, batch_size, criterion, early_stop, tol, verbose, S_0, S_1, train_separate) 134 def train_model(model,rna_X,atac_X,rna_idx,atac_idx,pair_idx,\ 135 optimizer,device,num_epochs,batch_size,\ 136 criterion=nn.MSELoss(),early_stop=True,tol=0.01,verbose=True,\ 137 S_0=None,S_1=None,train_separate=False): 139 for epoch_no in range(num_epochs): --> 140 run_epoch(epoch_no,rna_X,atac_X,rna_idx,atac_idx,pair_idx, 141 S_0,S_1,model,optimizer,device,batch_size,criterion=criterion, 142 verbose=verbose,train=True,train_separate=train_separate)
File ~/miniconda3/lib/python3.9/site-packages/gridnet/train.py:169, in run_epoch(epoch_no, rna_X, atac_X, rna_idx, atac_idx, pair_idx, S_0, S_1, model, optimizer, device, batch_size, criterion, verbose, train, statistics, train_separate) 166 batch_rna_idx = torch.from_numpy(rna_idx[ibatch_size:batch_size(i+1)]).long().to(device) 167 batch_pair_idx = torch.from_numpy(pair_idx[ibatch_size:batch_size(i+1)]).long().to(device) --> 169 full_preds,red_preds = model(batch_atac_x,batch_rna_x,\ 170 batch_atac_idx,batch_rna_idx,batch_pair_idx,S_0,S_1) 172 targets = batch_rna_x 174 if train_separate == 'full' and not statistics:
File ~/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, *kwargs) 1496 # If we don't have any hooks, we want to skip the rest of the logic in 1497 # this function, and just call forward. 1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks 1499 or _global_backward_pre_hooks or _global_backward_hooks 1500 or _global_forward_hooks or _global_forward_pre_hooks): -> 1501 return forward_call(args, **kwargs) 1502 # Do not call functions when jit is used 1503 full_backward_hooks, non_full_backward_hooks = [], []
File ~/miniconda3/lib/python3.9/site-packages/gridnet/models.py:48, in GraphGrangerModule.forward(self, atac_x, rna_x, atac_idx, rna_idx, pair_idx, S_0, S_1) 45 rna_out_list = [] 46 rna_r_out_list = [] ---> 48 atac_out = self.atac_gcn_1(atac_x,S_0,atac_idx) 49 rna_out = self.rna_gcn_1(rna_x,S_0,rna_idx) 50 rna_r_out = self.rna_gcn_r_1(rna_x,S_0,rna_idx)
File ~/miniconda3/lib/python3.9/site-packages/torch/nn/modules/module.py:1501, in Module._call_impl(self, *args, *kwargs) 1496 # If we don't have any hooks, we want to skip the rest of the logic in 1497 # this function, and just call forward. 1498 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks 1499 or _global_backward_pre_hooks or _global_backward_hooks 1500 or _global_forward_hooks or _global_forward_pre_hooks): -> 1501 return forward_call(args, **kwargs) 1502 # Do not call functions when jit is used 1503 full_backward_hooks, non_full_backward_hooks = [], []
File ~/miniconda3/lib/python3.9/site-packages/gridnet/models.py:14, in GraphConvLayer.forward(self, x, S, idx) 13 def forward(self,x,S,idx): ---> 14 return (x @ S) * self.W[idx] + self.b[idx]
IndexError: index 255555 is out of bounds for dimension 0 with size 255555