|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": null, |
| 5 | + "execution_count": 23, |
6 | 6 | "metadata": {},
|
7 | 7 | "outputs": [],
|
8 | 8 | "source": [
|
|
11 | 11 | },
|
12 | 12 | {
|
13 | 13 | "cell_type": "code",
|
14 |
| - "execution_count": null, |
| 14 | + "execution_count": 24, |
15 | 15 | "metadata": {},
|
16 | 16 | "outputs": [],
|
17 | 17 | "source": [
|
|
23 | 23 | },
|
24 | 24 | {
|
25 | 25 | "cell_type": "code",
|
26 |
| - "execution_count": null, |
| 26 | + "execution_count": 25, |
27 | 27 | "metadata": {},
|
28 | 28 | "outputs": [],
|
29 | 29 | "source": [
|
|
34 | 34 | "import os\n",
|
35 | 35 | "import re\n",
|
36 | 36 | "\n",
|
37 |
| - "# Common to template\n", |
| 37 | + "# Common to template´\n", |
38 | 38 | "# add into settings.ini, requirements, package name is python-dotenv, for conda build ensure `conda config --add channels conda-forge`\n",
|
39 | 39 | "import dotenv # for loading config from .env files, https://pypi.org/project/python-dotenv/\n",
|
40 | 40 | "import envyaml # Allows to loads env vars into a yaml file, https://github.com/thesimj/envyaml\n",
|
|
54 | 54 | },
|
55 | 55 | {
|
56 | 56 | "cell_type": "code",
|
57 |
| - "execution_count": null, |
| 57 | + "execution_count": 26, |
58 | 58 | "metadata": {},
|
59 | 59 | "outputs": [],
|
60 | 60 | "source": [
|
|
72 | 72 | },
|
73 | 73 | {
|
74 | 74 | "cell_type": "code",
|
75 |
| - "execution_count": null, |
| 75 | + "execution_count": 27, |
76 | 76 | "metadata": {},
|
77 | 77 | "outputs": [],
|
78 | 78 | "source": [
|
|
81 | 81 | "def process_quast_data(\n",
|
82 | 82 | " input_path:str,\n",
|
83 | 83 | " output_path:str = './output.tsv',\n",
|
| 84 | + " add_header:str = '',\n", |
84 | 85 | " replace_header:str = None,\n",
|
85 | 86 | " filter_columns:str = None,\n",
|
86 | 87 | " transpose:bool = True):\n",
|
|
100 | 101 | " \"\"\"\n",
|
101 | 102 | "\n",
|
102 | 103 | " df = core.DataFrame()\n",
|
103 |
| - " df.import_data(input_path, file_type='csv', add_header='placeholder')\n", |
104 |
| - "\n", |
105 | 104 | " #df.print_header()\n",
|
106 | 105 | " #df.show()\n",
|
107 | 106 | "\n",
|
108 |
| - " if replace_header:\n", |
109 |
| - " df.rename_header(replace_header)\n", |
110 |
| - "\n", |
111 | 107 | " if transpose:\n",
|
| 108 | + " df.import_data(input_path, file_type='tsv', add_header=['column_names', 'values'])\n", |
112 | 109 | " df_df = df.df\n",
|
113 |
| - " df_df[['column_names','values']] = df_df['placeholder'].str.split('\\t',expand=True)\n", |
114 |
| - " df_df.drop('placeholder', axis = 1, inplace=True)\n", |
115 | 110 | " df_df = df_df.T\n",
|
116 | 111 | " df_df = df_df.rename(columns=df_df.loc['column_names'])\n",
|
117 | 112 | " df_df.drop('column_names', axis=0, inplace=True)\n",
|
118 |
| - " #print(df_df, df_df.shape)\n", |
| 113 | + " #print(df_df, df_df.shape, df_df.columns)\n", |
119 | 114 | " df.df = df_df\n",
|
120 | 115 | " #df_df.columns = df_df['column_names']\n",
|
| 116 | + " else:\n", |
| 117 | + " df.import_data(input_path, file_type='tsv', add_header=add_header)\n", |
| 118 | + " #print(df.df)\n", |
121 | 119 | "\n",
|
| 120 | + " if replace_header:\n", |
| 121 | + " df.rename_header(replace_header)\n", |
122 | 122 | "\n",
|
123 | 123 | " if filter_columns:\n",
|
124 | 124 | " df.filter_columns(filter_columns)\n",
|
125 | 125 | "\n",
|
126 | 126 | "\n",
|
127 |
| - " #print(df.df)\n", |
| 127 | + " #df.show()\n", |
128 | 128 | " #print(type(df.df))\n",
|
129 | 129 | "\n",
|
130 | 130 | " df.export_data(output_path, file_type='tsv')\n",
|
|
142 | 142 | },
|
143 | 143 | {
|
144 | 144 | "cell_type": "code",
|
145 |
| - "execution_count": null, |
| 145 | + "execution_count": 30, |
146 | 146 | "metadata": {},
|
147 | 147 | "outputs": [],
|
148 | 148 | "source": [
|
149 | 149 | "# |hide\n",
|
150 | 150 | "# Example usage of the function\n",
|
151 |
| - "#process_quast_data(\n", |
152 |
| - "# input_path='/Users/B246654/vscode_storage/ssi-dk/bifrost_bridge/test_data/quast.tsv', \n", |
153 |
| - "# output_path='/Users/B246654/vscode_storage/ssi-dk/bifrost_bridge/test_data/quast_test_out.tsv',\n", |
154 |
| - "# filter_columns='Assembly,# contigs (>= 0 bp), N50',\n", |
155 |
| - "# transpose=True\n", |
156 |
| - "#)" |
| 151 | + "process_quast_data(\n", |
| 152 | + " input_path='/Users/B246357/ssi_stuff/bifrost_bridge/test_data/quast.tsv', \n", |
| 153 | + " output_path='/Users/B246357/ssi_stuff/bifrost_bridge/test_data/quast_test_out.tsv',\n", |
| 154 | + " #filter_columns='Assembly,# contigs (>= 0 bp), N50',\n", |
| 155 | + " add_header = '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15',\n", |
| 156 | + " #replace_header = '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15',\n", |
| 157 | + " transpose=True\n", |
| 158 | + ")" |
| 159 | + ] |
| 160 | + }, |
| 161 | + { |
| 162 | + "cell_type": "code", |
| 163 | + "execution_count": 36, |
| 164 | + "metadata": {}, |
| 165 | + "outputs": [], |
| 166 | + "source": [ |
| 167 | + "# |hide\n", |
| 168 | + "# Example usage of the function\n", |
| 169 | + "process_quast_data(\n", |
| 170 | + " input_path='/Users/B246357/ssi_stuff/bifrost_bridge/test_data/quast_transposed.tsv', \n", |
| 171 | + " output_path='/Users/B246357/ssi_stuff/bifrost_bridge/test_data/quast_test_out.tsv',\n", |
| 172 | + " #filter_columns='Assembly,# contigs (>= 0 bp), N50',\n", |
| 173 | + " #add_header = '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15',\n", |
| 174 | + " add_header = '1',\n", |
| 175 | + " #replace_header = '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15',\n", |
| 176 | + " #filter_columns = '1,2,3',\n", |
| 177 | + " transpose=False\n", |
| 178 | + ")" |
157 | 179 | ]
|
158 | 180 | },
|
159 | 181 | {
|
|
178 | 200 | ],
|
179 | 201 | "metadata": {
|
180 | 202 | "kernelspec": {
|
181 |
| - "display_name": "python3", |
| 203 | + "display_name": "base", |
182 | 204 | "language": "python",
|
183 | 205 | "name": "python3"
|
| 206 | + }, |
| 207 | + "language_info": { |
| 208 | + "codemirror_mode": { |
| 209 | + "name": "ipython", |
| 210 | + "version": 3 |
| 211 | + }, |
| 212 | + "file_extension": ".py", |
| 213 | + "mimetype": "text/x-python", |
| 214 | + "name": "python", |
| 215 | + "nbconvert_exporter": "python", |
| 216 | + "pygments_lexer": "ipython3", |
| 217 | + "version": "3.11.10" |
184 | 218 | }
|
185 | 219 | },
|
186 | 220 | "nbformat": 4,
|
|
0 commit comments