data_import/MiSeq_utils/basespace_csvs.py
def join_sample_csvs(AppResults_dir,
                     samp_ids=['08-120','UC-23 B','UC-23 A','UC-22 C'], 
                     samp_id_suffix=' (2)' ):
    ''' find and read csvs from basespace AppResults_dir dir '''
    dfs = {}
    for samp_id in samp_ids:
        sample_path = '{}/{}{}/Files/'.format(AppResults_dir, samp_id, samp_id_suffix)
        try:
            file_path = [sample_path + fn for fn in os.listdir(sample_path)
                          if fn.endswith('csv') ][0]
            # (fn.startswith(samp_id.replace(' ','-'))
            print('reading csv {} ...'.format(file_path), file=sys.stderr)        
            dfs[samp_id] = pd.read_table(file_path, sep=',')
            dfs[samp_id].set_index( list(dfs[samp_id].columns[:-2]) , inplace=True)
            dfs[samp_id].drop( "%_hits", axis=1, inplace=True)
        except:
            print('WARNING: no csv for samp_id {} found in {}'.format(samp_id ,sample_path ), file=sys.stderr)
    try:
        all = pd.concat(dfs, axis=1)
        all.columns = all.columns.get_level_values(0)
    except:
        all = pd.DataFrame()
    return all
 find and read csvs from basespace AppResults_dir dir 
find and read csvs from basespace AppResults_dir dir
find and read csvs from basespace AppResults_dir dir
def join_sample_csvs(AppResults_dir,
                     samp_ids=['08-120','UC-23 B','UC-23 A','UC-22 C'], 
                     samp_id_suffix=' (2)' ):
    dfs = {}
    for samp_id in samp_ids:
        sample_path = '{}/{}{}/Files/'.format(AppResults_dir, samp_id, samp_id_suffix)
        try:
            file_path = [sample_path + fn for fn in os.listdir(sample_path)
                          if fn.endswith('csv') ][0]
            print('reading csv {} ...'.format(file_path), file=sys.stderr)        
            dfs[samp_id] = pd.read_table(file_path, sep=',')
            dfs[samp_id].set_index( list(dfs[samp_id].columns[:-2]) , inplace=True)
            dfs[samp_id].drop( "%_hits", axis=1, inplace=True)
        except:
            print('WARNING: no csv for samp_id {} found in {}'.format(samp_id ,sample_path ), file=sys.stderr)
    try:
        all = pd.concat(dfs, axis=1)
        all.columns = all.columns.get_level_values(0)
    except:
        all = pd.DataFrame()
    return all
def join_sample_csvs ( AppResults_dir , samp_ids = [ '08-120' , 'UC-23 B' , 'UC-23 A' , 'UC-22 C' ] , samp_id_suffix = ' (2)' ) : dfs = { } for samp_id in samp_ids : sample_path = '{}/{}{}/Files/' . format ( AppResults_dir , samp_id , samp_id_suffix ) try : file_path = [ sample_path + fn for fn in os . listdir ( sample_path ) if fn . endswith ( 'csv' ) ] [ 0 ] print ( 'reading csv {} ...' . format ( file_path ) , file = sys . stderr ) dfs [ samp_id ] = pd . read_table ( file_path , sep = ',' ) dfs [ samp_id ] . set_index ( list ( dfs [ samp_id ] . columns [ : - 2 ] ) , inplace = True ) dfs [ samp_id ] . drop ( "%_hits" , axis = 1 , inplace = True ) except : print ( 'WARNING: no csv for samp_id {} found in {}' . format ( samp_id , sample_path ) , file = sys . stderr ) try : all = pd . concat ( dfs , axis = 1 ) all . columns = all . columns . get_level_values ( 0 ) except : all = pd . DataFrame ( ) return all
find and read csvs from basespace AppResults_dir dir
find and read csvs from basespace AppResults_dir dir
''' find and read csvs from basespace AppResults_dir dir ''' # (fn.startswith(samp_id.replace(' ','-'))
AppResults_dir
samp_ids
samp_id_suffix