2つの値に基づく熱転置

2つの値に基づく熱転置

次の構造のファイルがあります。

Numero_di_conferimento  Numero_Campione Identificazione Valore Data_del_prelievo Data Analisi
358172 1 80_T1_Glu_Gln 0,14 17/10/2019 Granulociti_basofili_(K/µL)
358172 1 80_T1_Glu_Gln 0,23 17/10/2019 Granulociti_eosinofili_(K/µL)
358172 1 80_T1_Glu_Gln 0,42 17/10/2019 Monociti_(K/µL)
358172 1 80_T1_Glu_Gln 0,60 17/10/2019 Granulociti_basofili_%_(%)
358172 1 80_T1_Glu_Gln 2,02 17/10/2019 Granulociti_eosinofili_%_(%)
358172 1 80_T1_Glu_Gln 2,21 17/10/2019 Linfociti_(K/µL)
358172 1 80_T1_Glu_Gln 1,67 17/10/2019 Granulociti_neutrofili_(K/µL)
358172 1 80_T1_Glu_Gln 2,96 17/10/2019 Monociti_%_(%)
358172 1 80_T1_Glu_Gln 2,4 17/10/2019 Leucociti_(WBC)_(K/µL)
358172 1 80_T1_Glu_Gln 5,74 17/10/2019 Eritrociti_(RBC)_(M/µL)
358172 1 80_T1_Glu_Gln 10,2 17/10/2019 Emoglobina_(g/dL)
358172 1 80_T1_Glu_Gln 12,6 17/10/2019 Emoglobina_globulare_media_(MCH)_(pg)
358172 1 80_T1_Glu_Gln 40,2 17/10/2019 Ampiezza_distribuzione_eritrocitaria_(RDW)_(%)
358172 1 80_T1_Glu_Gln 40,9 17/10/2019 Concentrazione_media_emoglobina_globulare_(MCHC)_(g/dL)
358172 1 80_T1_Glu_Gln 15,1 17/10/2019 Linfociti_%_(%)
358172 1 80_T1_Glu_Gln 32,2 17/10/2019 Ematocrito_(HCT)_(%)
358172 1 80_T1_Glu_Gln 63,7 17/10/2019 Volume_globulare_medio_(MCV)_(fl)
358172 1 80_T1_Glu_Gln 27,3 17/10/2019 Granulociti_neutrofili_%_(%)
358172 1 80_T1_Glu_Gln 453 17/10/2019 Piastrine_(PLT)_(K/µL)
358172 2 97_T1_Glu_Gln 2,16 17/10/2019 Granulociti_basofili_(K/µL)
358172 2 97_T1_Glu_Gln 3,47 17/10/2019 Granulociti_eosinofili_(K/µL)
358172 2 97_T1_Glu_Gln 2,79 17/10/2019 Monociti_(K/µL)
358172 2 97_T1_Glu_Gln 1,1 17/10/2019 Granulociti_basofili_%_(%)
358172 2 97_T1_Glu_Gln 4 17/10/2019 Granulociti_eosinofili_%_(%)
358172 2 97_T1_Glu_Gln 5,63 17/10/2019 Granulociti_neutrofili_(K/µL)
...

デフォルトでは、最後の列の内容は19行ごとに繰り返されます。この19行では、列は$ 4を除いて常に同じです。ファイル全体の長さは数千行です。

私はこれを次のように変更したいと思います:

Numero_di_conferimento  Numero_Campione Identificazione Data_del_prelievo    Ampiezza_distribuzione_eritrocitaria_(RDW)_(%) Concentrazione_media_emoglobina_globulare_(MCHC)_(g/dL) Ematocrito_(HCT)_(%)    Emoglobina_(g/dL)   Emoglobina_globulare_media_(MCH)_(pg)    Eritrociti_(RBC)   Granulociti_basofili_%_(%)  Granulociti_basofili_(K/µL) Granulociti_eosinofili_%_(%)    Granulociti_eosinofili_(K/µL)   Granulociti_neutrofili_%_(%)    Granulociti_neutrofili_(K/µL)   Leucociti_(WBC)_(K/µL)  Linfociti_%_(%)  Linfociti_(K/µL)   Monociti_%_(%)  Monociti_(K/µL) Piastrine_(PLT)_(K/µL)  Volume_globulare_medio_(MCV)_(fl)
358172 1 86_T1_Glu_Gln 17/10/2019   40,2    40,9    32,2    11,2    12,6    6,74    0,6 0,14    2,08    0,23    57,3    3,67    6,4 35,1    2,24    4,96    0,42    453 63,7
358172 2 98_T1_Glu_Gln 17/10/2019   23,5    32,3    30,4    9,82    18,3    5,36    1   0,16    3   0,47    23  3,63    15,8    68  10,74   5   0,79    420 56,8

次の2つのコマンドを実行してこれを行います。

awk -F"\t" '{print $1, $2, $3, $5}' Original_file | uniq > Intermediate_file

for i in `sed 's\/\-\g' Original_file | awk '{print $6}' | sort -u`; do sed 's\/\-\g' Original_file | grep -w "$i" | awk '{print $4}' > tmp${i}; done; paste Intermediate_file tmp* > File_endproduct # the sed 's\/\-\g' was because of the / giving problems when grepping

次に、タイトルを手動でコピーして貼り付けます。

しかし、この自家製のソリューションが私が望むファイルを生成しても、これが最善のアプローチではないようです。より安全な別の方法で目的のファイルを生成するにはどうすればよいですか?

ベストアンサー1

奇妙なことではありませんが、あなたの目標に役立つと思い、ここに追加しています。

から始まる

Numero_di_conferimento  Numero_Campione Identificazione Valore  Data_del_prelievo   Analisi
358172  1   80_T1_Glu_Gln   0,14    17/10/2019  Granulociti_basofili_(K/µL)
358172  1   80_T1_Glu_Gln   0,23    17/10/2019  Granulociti_eosinofili_(K/µL)
358172  1   80_T1_Glu_Gln   0,42    17/10/2019  Monociti_(K/µL)
358172  1   80_T1_Glu_Gln   0,60    17/10/2019  Granulociti_basofili_%_(%)
358172  1   80_T1_Glu_Gln   2,02    17/10/2019  Granulociti_eosinofili_%_(%)
358172  1   80_T1_Glu_Gln   2,21    17/10/2019  Linfociti_(K/µL)
358172  1   80_T1_Glu_Gln   1,67    17/10/2019  Granulociti_neutrofili_(K/µL)
358172  1   80_T1_Glu_Gln   2,96    17/10/2019  Monociti_%_(%)
358172  1   80_T1_Glu_Gln   2,4 17/10/2019  Leucociti_(WBC)_(K/µL)
358172  1   80_T1_Glu_Gln   5,74    17/10/2019  Eritrociti_(RBC)_(M/µL)
358172  1   80_T1_Glu_Gln   10,2    17/10/2019  Emoglobina_(g/dL)
358172  1   80_T1_Glu_Gln   12,6    17/10/2019  Emoglobina_globulare_media_(MCH)_(pg)
358172  1   80_T1_Glu_Gln   40,2    17/10/2019  Ampiezza_distribuzione_eritrocitaria_(RDW)_(%)
358172  1   80_T1_Glu_Gln   40,9    17/10/2019  Concentrazione_media_emoglobina_globulare_(MCHC)_(g/dL)
358172  1   80_T1_Glu_Gln   15,1    17/10/2019  Linfociti_%_(%)
358172  1   80_T1_Glu_Gln   32,2    17/10/2019  Ematocrito_(HCT)_(%)
358172  1   80_T1_Glu_Gln   63,7    17/10/2019  Volume_globulare_medio_(MCV)_(fl)
358172  1   80_T1_Glu_Gln   27,3    17/10/2019  Granulociti_neutrofili_%_(%)
358172  1   80_T1_Glu_Gln   453 17/10/2019  Piastrine_(PLT)_(K/µL)
358172  2   97_T1_Glu_Gln   2,16    17/10/2019  Granulociti_basofili_(K/µL)
358172  2   97_T1_Glu_Gln   3,47    17/10/2019  Granulociti_eosinofili_(K/µL)
358172  2   97_T1_Glu_Gln   2,79    17/10/2019  Monociti_(K/µL)
358172  2   97_T1_Glu_Gln   1,1 17/10/2019  Granulociti_basofili_%_(%)
358172  2   97_T1_Glu_Gln   4   17/10/2019  Granulociti_eosinofili_%_(%)
358172  2   97_T1_Glu_Gln   5,63    17/10/2019  Granulociti_neutrofili_(K/µL)

ミラーの使用(https://github.com/johnkerl/miller)このコマンドを長さから幅で実行します。

mlr --tsv reshape -s Analisi,Valore then unsparsify input.tsv >output.tsv

あなたはやる

+------------------------+-----------------+-----------------+-------------------+-----------------------------+-------------------------------+-----------------+----------------------------+------------------------------+------------------+-------------------------------+----------------+------------------------+-------------------------+-------------------+---------------------------------------+------------------------------------------------+---------------------------------------------------------+-----------------+----------------------+-----------------------------------+------------------------------+------------------------+
| Numero_di_conferimento | Numero_Campione | Identificazione | Data_del_prelievo | Granulociti_basofili_(K/µL) | Granulociti_eosinofili_(K/µL) | Monociti_(K/µL) | Granulociti_basofili_%_(%) | Granulociti_eosinofili_%_(%) | Linfociti_(K/µL) | Granulociti_neutrofili_(K/µL) | Monociti_%_(%) | Leucociti_(WBC)_(K/µL) | Eritrociti_(RBC)_(M/µL) | Emoglobina_(g/dL) | Emoglobina_globulare_media_(MCH)_(pg) | Ampiezza_distribuzione_eritrocitaria_(RDW)_(%) | Concentrazione_media_emoglobina_globulare_(MCHC)_(g/dL) | Linfociti_%_(%) | Ematocrito_(HCT)_(%) | Volume_globulare_medio_(MCV)_(fl) | Granulociti_neutrofili_%_(%) | Piastrine_(PLT)_(K/µL) |
+------------------------+-----------------+-----------------+-------------------+-----------------------------+-------------------------------+-----------------+----------------------------+------------------------------+------------------+-------------------------------+----------------+------------------------+-------------------------+-------------------+---------------------------------------+------------------------------------------------+---------------------------------------------------------+-----------------+----------------------+-----------------------------------+------------------------------+------------------------+
| 358172                 | 1               | 80_T1_Glu_Gln   | 17/10/2019        | 0,14                        | 0,23                          | 0,42            | 0,60                       | 2,02                         | 2,21             | 1,67                          | 2,96           | 2,4                    | 5,74                    | 10,2              | 12,6                                  | 40,2                                           | 40,9                                                    | 15,1            | 32,2                 | 63,7                              | 27,3                         | 453                    |
| 358172                 | 2               | 97_T1_Glu_Gln   | 17/10/2019        | 2,16                        | 3,47                          | 2,79            | 1,1                        | 4                            | -                | 5,63                          | -              | -                      | -                       | -                 | -                                     | -                                              | -                                                       | -               | -                    | -                                 | -                            | -                      |
+------------------------+-----------------+-----------------+-------------------+-----------------------------+-------------------------------+-----------------+----------------------------+------------------------------+------------------+-------------------------------+----------------+------------------------+-------------------------+-------------------+---------------------------------------+------------------------------------------------+---------------------------------------------------------+-----------------+----------------------+-----------------------------------+------------------------------+------------------------+

おすすめ記事