jbkinney / logomaker

Software for the visualization of sequence-function relationships
MIT License
179 stars 34 forks source link

stack_order='fixed' sorts alphabetically instead of using given order #32

Open bas-stringer opened 1 year ago

bas-stringer commented 1 year ago

See title.

Logo(df, stack_order='fixed') results in stacks wherein the glyphs appear in alphabetic order, rather than in the order of df.columns

atareen commented 1 year ago

Thanks, I'll work on fixing this soon. Could you please provide a minimal example to reproduce this.

Ammar

tjlundgren commented 4 weeks ago

I also would like to see this work! Here's an example: (edit: formatting)

amino_acids = ['A', 'R', 'N', 'D', 'C', 'Q', 'E', 'G', 'H', 'I', 'L', 'K', 'M', 'F', 'P', 'S', 'T', 'W', 'Y', 'V']

Sort amino acids in reverse alphabetical order

amino_acids_sorted = sorted(amino_acids, reverse=True)

Generate random integers between 1 and 20 for 3 rows

data = np.random.randint(1, 21, size=(3, len(amino_acids_sorted)))

Create DataFrame with columns in reverse alphabetical order

df = pd.DataFrame(data, columns=amino_acids_sorted) print(df) logomaker.Logo(df,stack_order='fixed')

tjlundgren commented 4 weeks ago

It looks like the columns are reordered to pandas default (alphabetical) when either self.df = validate_matrix(...) or self.df = transform_matrix(...) edit: my quick fix didn't work. Please disregard.