def format_data(tax_order, relAbs):
    """
    Formats data for plotting
    
    Arguments:
        tax_order (list) -- names of tax groups in order of decreasing median median relative abundance
        relAbs (dict) -- maps tax group index (determined by which column it is in the csv file) to list of the group name and relative abundances per sample (e.g.: {1: ['Streptococcus', 0.5, 0.25, 0.25]})
    
    Returns:
        data_to_plot (list) -- for each taxon, a list of relative abundance per sample
        phyla_labels (list) -- names of tax groups, from least to most abundant/common
    """
    data_to_plot = []  
    phyla_labels = []   
    
    for i in tax_order:
        for key in relAbs:
            if relAbs[key][0] == i:
                data_to_plot.append(relAbs[key][1:]) # remember element 0 is the english name of the tax group
        
        # Add alphanumeric identifiers to candidate phyla labels
        if i == "SR1":
            phylum = "Absconditabacteria (SR1)"
        elif "Saccharibacteria" in i: 
            phylum = "Saccharibacteria (TM7)"
        elif "Parcubacteria" in i: 
            phylum = "Parcubacteria (OD1)"
        elif "Microgenomates" in i: 
            phylum = "Microgenomates (OP11)"
        elif "Armatimonadetes" in i: 
            phylum = "Armatimonadetes (OP10)"
        elif "Marinimicrobia" in i: 
            phylum = "Marinimicrobia (SAR406)"
        elif "Latescibacteria" in i: 
            phylum = "Latescibacteria (WS3)"
        elif "Aminicenantes" in i: 
            phylum = "Aminicenantes (OP8)"
        elif "Cloacimonetes" in i: 
            phylum = "Cloacimonetes (WWE1)"
        else:
            phylum = i
            
        phyla_labels.append(phylum)
    
    data_to_plot.reverse()
    phyla_labels.reverse()
    
    return data_to_plot, phyla_labels