Project: s41467-024-52614-w | Function: meta (python)

system: You are an expert Python programmer implementing algorithms from scientific papers.
Complete the masked function based on the algorithm description.
Follow Python best practices and maintain consistent code style.
Return **only** the complete Python function code.

user: Complete this Python function:

**DESCRIPTION:** Core algorithm for constructing sequence similarity networks (SSNs) and generating metanodes from BLAST results. Implements graph clustering based on bitscore thresholds to group homologous sequences into metanodes and create network edges between them.

**KEY TERMS:** {
  "cluster_threshold": "bitscore threshold for metanode formation",
  "min_bitscore": "minimum bitscore for edge connections",
  "metanodes": "sequence clusters representing epistatic networks",
  "putative_linker": "edges between metanodes",
  "membership": "sequence-to-metanode assignments"
}

**CONTEXT CODE:** from libs.meta_helper import *
import os
import time
import math
import multiprocessing as mp
from itertools import islice

def main():
    cluster_threshold = 115
    min_bitscore = 50
    
    # light test case
    cols={'q':0,'s':1,'b':11} # q=query, s=subject, e=e-value, b=bitscore
    dir = '../input/blast/'
    files = ['b1_all_by_all.txt','b2_vs_b1_all_blast.txt','b2_vs_b1_all_as_subject.txt']
    meta( [dir+x for x in files], f'ssn_test_{min_bitscore}min_{cluster_threshold}clust', cols=cols, cluster_threshold=cluster_threshold, min_bitscore = min_bitscore)

def meta(files, outname = None, cluster_threshold=100, min_bitscore=50, cols={'q':0,'s':1,'b':2}, sep='\t', filter=None, to_file=True, outfile_names=None):
    '''
        Version 2 - Comparison of sequences to existing metanodes is now conducted by using dictionaries 
                    rather than set operations. Untested whether this is faster, but it functions the same as the original in terms of output.
        Version 3 - Discontinued tracking of e-value for nodes. Members are still tracked but are not 
                    written into the node table anymore. Edge tables no longer have the linker pairs and linker count, since those are inaccurate if the edges are culled in anyway, which they almost always are.
        Version 4 - Instead of loading and prefiltering all the BLAST results, stream each file and 
                    process the results as they come. Minor optimizations were also made by making the dictionary keys strings instead of tuples. Wasteful memory usage has been addressed by not recording hits with scores below the min bitscore as putative linkers. Memory consumpution is down by 50% in the worst case where all edges get collected for linker detection, and memory consumption is minimal when the number of putative linkers is small (e.g., when the cluster and min bitscores are close to each other). The results have been tested and are the exact same as V3 in terms of sequence membership in nodes as well as network connections. The overall run time is down by 50% from V3 (~11min to ~6min for an equivalent set of cut-offs). There was also a failed attempt to try multiprocessing, but it ended up being slower.
        
        Inputs:
            files - List of strings. Path to BLAST result files to use for metanode analysis
            outname - String. Name of analysis results. The output files will have this as the main identifier with suffixes attached.
            cluster_threshold - Number. The threshold at which different sequences in the BLAST results will be grouped into the same metanode. Expressed in bit_score.
            min_bitscore - Number. The lowest threshold to permit connecting edges between metanodes. Expressed in bit_score.
            cols - Dictionary with column indices as values. A mapping for which columns in the BLAST results file contains desired information. The contents should include: 'q' - column for query ID, 's' - column for subject ID, 'e' - column for E-value, 'b' - column for bit_score
            sep - String. Character used to separate columns in the BLAST result file. Defaults are not accurate, simply placeholders.
            filter - List. If given, only sequence IDs in this list will be considered for the network analysis.
        
        Outputs:
            3 files are created upon running the program.
            <outname>_meta-node_members.txt - A file that records the metanode membership of each sequence in the BLAST results input.
            <outname>_meta-node_summary.txt - A file that records information about each metanode, including the number and identity of member sequences. Used as the nodes table for a network.
            <outname>_meta-network.txt - A describing connection between metanodes. Used as the edge table for a network.
    '''
    raise NotImplementedError("Function implementation has been masked")
    
if __name__ == '__main__':
    main()
                        

Complete the function implementation replacing "raise NotImplementedError".