shenwei356 / csvtk

A cross-platform, efficient and practical CSV/TSV toolkit in Golang
http://bioinf.shenwei.me/csvtk
MIT License
992 stars 84 forks source link

Summary does not respect "column:operation" order #282

Closed tetedange13 closed 4 weeks ago

tetedange13 commented 1 month ago

Prerequisites

Describe your issue

csvtk summary apply operations based on column order in file, rather than CLI-provided order

$ csvtk csv2md test.csv

ReadNB Lane Density ClusterPF Reads ReadsPF
Read 1 1 231 89.08 49.93 44.48
Read 1 2 232 88.76 50.11 44.48
Read 1 3 228 89.19 49.23 43.91
Read 1 4 229 88.67 49.48 43.87
Read 3 1 231 89.08 49.93 44.48
Read 3 2 232 88.76 50.11 44.48
Read 3 3 228 89.19 49.23 43.91
Read 3 4 229 88.67 49.48 43.87

$ csvtk summary --groups Lane -f ReadsPF:sum -f Reads:sum -f ClusterPF:first -f Density:first test.csv | csvtk headers

Lane Density:sum ClusterPF:sum Reads:first ReadsPF:first

Instead of expected (based on above command-line) :

Lane Density:first ClusterPF:first Reads:sum ReadsPF:sum

Thank you

I'm grateful to users who have greatly helped to report bugs and suggested new features.

I may respond to issues or fix bugs quickly, but I usually implement new features periodically (two or more weeks).

shenwei356 commented 1 month ago

Fixed.

csvtk summary --groups Lane -f ReadsPF:sum -f Reads:sum -f ClusterPF:first -f Density:first test.csv  \
     | csvtk pretty 

Lane   ReadsPF:sum   Reads:sum   ClusterPF:first   Density:first
----   -----------   ---------   ---------------   -------------
1      88.96         99.86       89.08             231          
2      88.96         100.22      88.76             232          
3      87.82         98.46       89.19             228          
4      87.74         98.96       88.67             229