Skip to content
This repository was archived by the owner on Feb 9, 2023. It is now read-only.
This repository was archived by the owner on Feb 9, 2023. It is now read-only.

Sorting in advanced way #10

@lee1043

Description

@lee1043

In the interactive portrait plot, would it be available to add below function replacing the python’s default sorting?

import copy
import re

def sort_human(input_list):
    l = copy.copy(input_list)
    convert = lambda text: float(text) if text.isdigit() else text
    alphanum = lambda key: [ convert(c) for c in re.split('([-+]?[0-9]*\.?[0-9]*)', key) ]
    l.sort( key=alphanum )
    return l

Above function is what that I have used for creating my own portrait plot before your modal capability has become available. It sorts labels more in recognizable way.

For example, default sorted sorts as below:
A_r10i1p1
A_r1i1p1
A_r20i1p1
A_r2i1p1
A_r3i1p1

And the function I implemented sorts as below:
A_r1i1p1
A_r2i1p1
A_r3i1p1
A_r10i1p1
A_r20i1p1

I guess the right place might be in click/click_plots/portrait_plots.py, line 174 and 176 where sorted has been used, but would be nicer if you could confirm this for me.

Below is for actual use example.

>>> a=['a_1', 'a_11', 'a_2']
>>> sorted(a)
['a_1', 'a_11', 'a_2']

>>> import copy
>>> import re
>>> def sort_human(input_list):
...     l = copy.copy(input_list)
...     convert = lambda text: float(text) if text.isdigit() else text
...     alphanum = lambda key: [ convert(c) for c in re.split('([-+]?[0-9]*\.?[0-9]*)', key) ]
...     l.sort( key=alphanum )
...     return l
>>> sort_human(a)
['a_1', 'a_2', 'a_11']
>>> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions