def parse_data( file_path: pathlib.Path, interaction_threshold: float, pvalue_threshold: float, tqdm_func, global_tqdm, ) -> Tuple[Optional[dict], Optional[pd.DataFrame]]: HEADER = ["DC", "CC", "TA", "OP", "TL", "NI"] process_string = file_path.parent.parent.stem hash = hashlib.md5(process_string.encode("utf-8")).hexdigest() processes = process_string.split("-") x_dataitem = dict(zip(HEADER, processes)) x_dataitem["hash"] = hash network = Network.load_json(str(file_path)) network.interaction_threshold = interaction_threshold network.pvalue_threshold = pvalue_threshold filtered_network = network.filter(pvalue_filter=True, interaction_filter=True) # Create edge list y_dataitem = create_edge_df(filtered_network, hash) # tqdm_func.update() global_tqdm.update() if y_dataitem is None: return None, None return x_dataitem, y_dataitem
def main( folder: pathlib.Path, color_key_level: str, multigraph: bool, dc: str, cc: str, ta: str, op: str, ni: str, output: str, ): if not folder.exists(): raise ValueError(f"Folder {folder} must exist") networks_dict = { "default": dict(), "DC": dict(), "CC": dict(), "TA": dict(), "OP": dict(), "NI": dict(), } for step_folder in tqdm(list(folder.iterdir())): step_name = step_folder.stem assert step_name in networks_dict for process_folder in step_folder.iterdir(): process_name = process_folder.stem # STEP1: Get all the `Network` for a particular folder (combination) network_files = list(process_folder.glob("**/*.json")) if not network_files: continue networks = [ Network.load_json(str(network_file)) for network_file in network_files ] # STEP2: Convert all to `NetworkGroup` and perform `consensus` network_group = NetworkGroup(networks) cids = list(range(len(network_group.contexts))) consensus_network = network_group.get_consensus_network( cids, method="scaled_sum", parameter=0.5 ) # STEP3: Create a simple graph version of the consensus simple_consensus = consensus_network.to_network() simple_consensus.interaction_threshold = 0.1 simple_consensus.pvalue_threshold = 0.05 networks_dict[step_name][process_name] = simple_consensus.filter(True, True) # STEP4: Then, feed the above to the previous function output_path = pathlib.Path(output) assert output_path.exists() networks_choice_dict = { f"DC_{dc}": networks_dict["DC"][dc], f"CC_{cc}": networks_dict["CC"][cc], f"TA_{ta}": networks_dict["TA"][ta], f"OP_{op}": networks_dict["OP"][op], f"NI_{ni}": networks_dict["NI"][ni], "default": networks_dict["default"]["default"], } nodes, edges = write_networks( networks_choice_dict, multigraph, color_key_level, output_path ) write_l1_distance(networks_dict, output_directory=output_path)
def read_predictions( prediction_file: pathlib.Path, interaction_threshold: float, pvalue_threshold: float, ) -> Network: network = Network.load_json(str(prediction_file)) network.interaction_threshold = interaction_threshold network.pvalue_threshold = pvalue_threshold filtered_network = network.filter(pvalue_filter=True, interaction_filter=True) return filtered_network
def main( base_name: str, network_files: List[pathlib.Path], method: str, parameter: float, pvalue_filter: bool, interaction_filter: bool, id_field: str, ) -> None: networks: List[Network] = [] for network_file in network_files: networks.append(Network.load_json(str(network_file))) network_group = NetworkGroup(networks, id_field=id_field) pathlib.Path("consensus/").mkdir(parents=True, exist_ok=True) cids = list(range(len(network_group.contexts))) filtered_network_group = network_group.filter( pvalue_filter=pvalue_filter, interaction_filter=interaction_filter) consensus_network_group = filtered_network_group.get_consensus_network( cids, method=method, parameter=parameter) consensus_network_group.write("consensus/" + base_name + "_network.json")
def main( base_name: str, corr_file: str, meta_file: str, cmeta_file: str, obsmeta_file: str, children_file: str, interaction_threshold: float, interaction_type: str, ) -> None: network = Network.load_data( interaction_file=corr_file, meta_file=meta_file, cmeta_file=cmeta_file, obsmeta_file=obsmeta_file, children_file=children_file, interaction_type=interaction_type, interaction_threshold=interaction_threshold, pvalue_correction=None, ) network.write(base_name + "_network.json")
def main( base_name: str, corr_file: str, meta_file: str, cmeta_file: str, obsmeta_file: str, children_file: str, ) -> None: network = Network.load_data( interaction_file=corr_file, meta_file=meta_file, cmeta_file=cmeta_file, obsmeta_file=obsmeta_file, children_file=children_file, interaction_threshold=0.2, ) network_group = NetworkGroup([network]) network_group.write(base_name + "_network.json") network_group.write(base_name + "_thres_network.json", pvalue_filter=False, interaction_filter=True)