Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update return_panda_indegree() and return_panda_outdegree() #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
Binary file removed panda_topgenes.png
Binary file not shown.
14 changes: 10 additions & 4 deletions pypanda/lioness.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .panda import Panda
from .timer import Timer


class Lioness(Panda):
"""Using LIONESS to infer single-sample gene regulatory networks.

Expand Down Expand Up @@ -43,7 +44,7 @@ def __init__(self, obj, start=1, end=None, save_dir='lioness_output', save_fmt='
os.makedirs(save_dir)

# Run LIONESS
self.lioness_network = self.__lioness_loop()
self.total_lioness_network = self.__lioness_loop()

# create result data frame
#self.export_lioness_results = pd.DataFrame(self.lioness_network)
Expand Down Expand Up @@ -78,10 +79,15 @@ def __lioness_loop(self):
else:
print("Unknown format %s! Use npy format instead." % self.save_fmt)
np.save(path, lioness_network)
return lioness_network
if i == 0:
self.total_lioness_network = np.fromstring(np.transpose(lioness_network).tostring(),dtype=lioness_network.dtype)
else:
self.total_lioness_network=np.column_stack((self.total_lioness_network ,np.fromstring(np.transpose(lioness_network).tostring(),dtype=lioness_network.dtype)))

return self.total_lioness_network

def save_lioness_results(self, file='lioness.txt'):
'''Write lioness results to file.'''
#self.lioness_network.to_csv(file, index=False, header=False, sep="\t")
np.savetxt(file, self.lioness_network, delimiter="\t",header="")
return None
np.savetxt(file, self.total_lioness_network, delimiter="\t",header="")
return None
9 changes: 7 additions & 2 deletions pypanda/panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, expression_file, motif_file, ppi_file, save_memory = False, s
print('Unique TFs:', self.num_tfs)
else:
self.motif_data = None
self.num_tfs = 0

if expression_file:
with Timer('Loading expression data ...'):
Expand Down Expand Up @@ -69,6 +70,7 @@ def __init__(self, expression_file, motif_file, ppi_file, save_memory = False, s
if self.motif_data is None:
print('Returning the correlation matrix of expression data in <Panda_obj>.correlation_matrix')
#self.panda_network = self.correlation_matrix
self.panda_network = self.correlation_matrix
self.__pearson_results_data_frame()
return
# Auxiliary dicts
Expand Down Expand Up @@ -330,12 +332,15 @@ def split_label(label):
def return_panda_indegree(self):
'''Return Panda indegree.'''
#subset_indegree = self.export_panda_results.loc[:,['gene','force']]
subset_indegree = self.panda_results.loc[:,['gene','force']]
export_panda_results_pd = pd.DataFrame(self.export_panda_results,columns=['tf','gene','motif','force'])
subset_indegree = export_panda_results_pd.loc[:,['gene','force']]
subset_indegree['force']=pd.to_numeric(subset_indegree.force)
self.panda_indegree = subset_indegree.groupby('gene').sum()
return self.panda_indegree
def return_panda_outdegree(self):
'''Return Panda outdegree.'''
export_panda_results_pd = pd.DataFrame(self.export_panda_results,columns=['tf','gene','motif','force'])
subset_outdegree = export_panda_results_pd.loc[:,['tf','force']]
subset_outdegree['force']=pd.to_numeric(subset_outdegree.force)
self.panda_outdegree = subset_outdegree.groupby('tf').sum()
return self.panda_outdegree
return self.panda_outdegree