def find_cross_contamination(databases, pair, tmpdir='tmp', log='log.txt', threads=1):
    """
    Usese mash to find out whether or not a sample has more than one genus present, indicating cross-contamination.
    :param databases: A databases folder, which must contain refseq.msh, a mash sketch that has one representative
    per genus from refseq.
    :param tmpdir: Temporary directory to store mash result files in.
    :param pair: Array with path to forward reads at index 0 and path to reverse reads at index o
    :param log: Logfile to write to.
    :param threads: Number of threads to run mash wit.
    :return: cross_contam: a bool that is True if more than one genus is found, and False otherwise.
    :return: genera_present: A string. If only one genus is found, string is just genus. If more than one genus is found,
    the string is a list of genera present, separated by colons (i.e. for Escherichia and Salmonella found, string would
    be 'Escherichia:Salmonella'. If no genus found, return 'NA'
    """
    genera_present = list()
    out, err, cmd = mash.screen('{}/refseq.msh'.format(databases), pair[0],
                                pair[1], threads=threads, w='', i='0.95',
                                output_file=os.path.join(tmpdir, 'screen.tab'), returncmd=True)
    write_to_logfile(log, out, err, cmd)
    screen_output = mash.read_mash_screen(os.path.join(tmpdir, 'screen.tab'))
    for item in screen_output:
        mash_genus = item.query_id.split('/')[-3]
        if mash_genus == 'Shigella':
            mash_genus = 'Escherichia'
        if mash_genus not in genera_present:
            genera_present.append(mash_genus)
    if len(genera_present) == 1:
        genera_present = genera_present[0]
    elif len(genera_present) == 0:
        genera_present = 'NA'
    else:
        tmpstr = ''
        for mash_genus in genera_present:
            tmpstr += mash_genus + ':'
        genera_present = tmpstr[:-1]
    return genera_present
def find_cross_contamination ( databases , pair , tmpdir = 'tmp' , log = 'log.txt' , threads = 1 ) : genera_present = list ( ) out , err , cmd = mash . screen ( '{}/refseq.msh' . format ( databases ) , pair [ 0 ] , pair [ 1 ] , threads = threads , w = '' , i = '0.95' , output_file = os . path . join ( tmpdir , 'screen.tab' ) , returncmd = True ) write_to_logfile ( log , out , err , cmd ) screen_output = mash . read_mash_screen ( os . path . join ( tmpdir , 'screen.tab' ) ) for item in screen_output : mash_genus = item . query_id . split ( '/' ) [ - 3 ] if mash_genus == 'Shigella' : mash_genus = 'Escherichia' if mash_genus not in genera_present : genera_present . append ( mash_genus ) if len ( genera_present ) == 1 : genera_present = genera_present [ 0 ] elif len ( genera_present ) == 0 : genera_present = 'NA' else : tmpstr = '' for mash_genus in genera_present : tmpstr += mash_genus + ':' genera_present = tmpstr [ : - 1 ] return genera_present
Usese mash to find out whether or not a sample has more than one genus present, indicating cross-contamination.
    :param databases: A databases folder, which must contain refseq.msh, a mash sketch that has one representative
    per genus from refseq.
    :param tmpdir: Temporary directory to store mash result files in.
    :param pair: Array with path to forward reads at index 0 and path to reverse reads at index o
    :param log: Logfile to write to.
    :param threads: Number of threads to run mash wit.
    :return: cross_contam: a bool that is True if more than one genus is found, and False otherwise.
    :return: genera_present: A string. If only one genus is found, string is just genus. If more than one genus is found,
    the string is a list of genera present, separated by colons (i.e. for Escherichia and Salmonella found, string would
    be 'Escherichia:Salmonella'. If no genus found, return 'NA'