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

Adding function converting topology to .npz #99

Merged
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
43 changes: 43 additions & 0 deletions GenNet_utils/Convert_topology_npz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import argparse
import numpy as np
import pandas as pd
import sys
import os
import scipy
import h5py
import tables
from scipy import stats

def main():
"""
args:
snp: the name of the column in the topology.csv dataset with the ID for the SNP column
gene: the name of the column in the topology.csv dataset with the ID for the gene column
direc: (Optional) the directory where the topology.csv file is located, if omitted it takes the current directory

Return: SNP_gene_mask.npz, the .npz file corresponding to the topology.csv
"""
parser = argparse.ArgumentParser(description="A simple script with command-line arguments")
parser.add_argument("--snp", help="Your snp", required=True)
parser.add_argument("--gene", help="Your gene", required=True)
parser.add_argument("--direc", help="Your Directory", required=False)
args = parser.parse_args()
if args.direc:
try:
os.chdir(args.direc)
print(f"Navigated to directory: {os.getcwd()}")
except FileNotFoundError:
print(f"Directory '{args.direc}' not found.")

snp_level = args.snp #"layer0_node"
gene_level = args.gene #"layer1_node"
topology = pd.read_csv("topology.csv")
data = np.ones(len(topology), np.bool)
coord = ( topology[snp_level].values, topology[gene_level].values )
SNP_gene_matrix = scipy.sparse.coo_matrix(((data),coord), shape = (topology[snp_level].max()+1, topology[gene_level].max()+1 ))
scipy.sparse.save_npz('SNP_gene_mask', SNP_gene_matrix)

if __name__ == "__main__":
main()


Loading