<commit_before>import sys,os
import SolidDataExtractor

class Experiment:
    def __init__(self):
        self.name = None
        self.type = None
        self.sample = None
        self.library = None

def match(pattern,word):
    """Check if word matches pattern"""
    if not pattern or pattern == '*':
        # No pattern/wildcard, matches everything
        return True
    # Only simple patterns considered now
    if pattern.endswith('*'):
        # Match the start
        return word.startswith(pattern[:-1])
    else:
        # Match the whole word exactly
        return (word == pattern)

def getLinkName(filen,sample,library):
    """Return the 'analysis' file name based on a source file name.
    
    The analysis file name is constructed as

    <instrument>_<datestamp>_<sample>_<library>.csfasta

    or

    <instrument>_<datestamp>_<sample>_QV_<library>.qual
    
    Arguments:
      filen: name of the source file
      sample: SolidSample object representing the parent sample
      library: SolidLibrary object representing the parent library

    Returns:
    Name for the analysis file.
    """
    # Construct new name
    link_filen_elements = [sample.parent_run.run_info.instrument,
                           sample.parent_run.run_info.datestamp,
                           sample.name]
    ext = os.path.splitext(filen)[1]
    if ext == ".qual":
        link_filen_elements.append("QV")
    link_filen_elements.append(library.name)
    link_filen = '_'.join(link_filen_elements) + ext
    return link_filen

def replace_string(s,replace_substr,with_str=''):
    """Do query/replace on a string

    Arguments:
      s: original string
      replace_substr: substring in s to be replaced
      with_str: (optional) string to substitute replace_substring by

    Returns:
      Modified string
    """
    s1 = s
    slen = len(replace_substr)
    while True:
        try:
            i = s1.rindex(replace_substr)
            s1 = s1[0:i]+str(with_str)+s1[i+slen:]
        except ValueError:
            return s1

def mkdir(dirn):
    """Make a directory"""
    ##print "Making %s" % dirn
    if not os.path.isdir(dirn):
        os.mkdir(dirn)

def mklink(target,link_name):
    """Make a symbolic link"""
    ##print "Linking to %s from %s" % (target,link_name)
    os.symlink(target,link_name)

if __name__ == "__main__":
    print """ build_analysis_dir.py [--dry-run]
                --name=<user> [--type=<expt_type>] --source=<sample>/<library>
                [--source=...]
                [--name=<user> ... ]
                <solid_run_dir>

Build analysis directory structure and populate with links to primary data.<commit_msg>build_analysis_dir.py: remove replace_string() function as it's no longer used.<commit_after>import sys,os
import SolidDataExtractor

class Experiment:
    def __init__(self):
        self.name = None
        self.type = None
        self.sample = None
        self.library = None

def match(pattern,word):
    """Check if word matches pattern"""
    if not pattern or pattern == '*':
        # No pattern/wildcard, matches everything
        return True
    # Only simple patterns considered now
    if pattern.endswith('*'):
        # Match the start
        return word.startswith(pattern[:-1])
    else:
        # Match the whole word exactly
        return (word == pattern)

def getLinkName(filen,sample,library):
    """Return the 'analysis' file name based on a source file name.
    
    The analysis file name is constructed as

    <instrument>_<datestamp>_<sample>_<library>.csfasta

    or

    <instrument>_<datestamp>_<sample>_QV_<library>.qual
    
    Arguments:
      filen: name of the source file
      sample: SolidSample object representing the parent sample
      library: SolidLibrary object representing the parent library

    Returns:
    Name for the analysis file.
    """
    # Construct new name
    link_filen_elements = [sample.parent_run.run_info.instrument,
                           sample.parent_run.run_info.datestamp,
                           sample.name]
    ext = os.path.splitext(filen)[1]
    if ext == ".qual":
        link_filen_elements.append("QV")
    link_filen_elements.append(library.name)
    link_filen = '_'.join(link_filen_elements) + ext
    return link_filen

def mkdir(dirn):
    """Make a directory"""
    ##print "Making %s" % dirn
    if not os.path.isdir(dirn):
        os.mkdir(dirn)

def mklink(target,link_name):
    """Make a symbolic link"""
    ##print "Linking to %s from %s" % (target,link_name)
    os.symlink(target,link_name)

if __name__ == "__main__":
    print """ build_analysis_dir.py [--dry-run]
                --name=<user> [--type=<expt_type>] --source=<sample>/<library>
                [--source=...]
                [--name=<user> ... ]
                <solid_run_dir>

Build analysis directory structure and populate with links to primary data.
{'fraction_non_alphanumeric': 0.10782715042804729, 'fraction_numerical': 0.002242152466367713, 'mean_word_length': 2.495014245014245, 'pattern_counts': {'":': 4, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '930421', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1451, 'n_words': 398}