-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathotu2pg
More file actions
executable file
·63 lines (41 loc) · 1.07 KB
/
otu2pg
File metadata and controls
executable file
·63 lines (41 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
set -euo pipefail
OLD_IFS=${IFS}
#IFS=','
file=myosd2015-1000-otu-table.csv
declare -gr OUT_FILE='myosd-otu-count.csv'
# takes also first out col header
declare -i COL_NUM=$(head -n 1 ${file} | tr ',' '\n' | wc -l)
#COL_NUM=3
header=''
silva_otu='';
myosd_id=shoot;
function colcut () {
cut -d ',' -s -f 1,"$1" "$2"
}
function analyse_header () {
IFS=',' read id mid;
#echo "mid=${mid}"
myosd_id="${mid//_*a/}";
myosd_id="${myosd_id//\"MYOSD/}";
declare -gx myosd_id="${myosd_id//\"/}";
echo "${myosd_id}"
}
function cutheader() {
head -n 1 $2 | colcut "${1}" '-'
}
function cutcol () {
#echo "i=$1"
tail -n +2 "${2}"| colcut "$1" '-'
}
echo "Column count: ${COL_NUM}"
echo "myosd_id,silva_otu,num" > "${OUT_FILE}";
for i in $(seq 2 ${COL_NUM}); do
echo "working on head"
test=$(cutheader "${i}" "${file}" | analyse_header)
echo "myosdid=${test}"
echo "now rest"
while IFS=',' read -r id num; do
echo "${test},${id//\"/},$num" >> "${OUT_FILE}";
done < <(cutcol "${i}" "${file}")
done;