Skip to content

Commit 55b4f27

Browse files
committed
combine gtdb and user data
1 parent a7741d9 commit 55b4f27

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

unifygtdb.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
# Usage: bash unify.sh gtdb_taxonomy.tsv gtdbtk_species_representatives.tsv memberships.tsv > unified.tsv
3+
4+
GTDB_TAX="$1"
5+
GTDBTK="$2"
6+
MEMBERS="$3"
7+
8+
awk '
9+
BEGIN { OFS="\t"; print "#user_representative\tgtdb_representative" }
10+
11+
# File 1: gtdb_taxonomy.tsv -> species -> GTDB reference genome
12+
FILENAME==ARGV[1] {
13+
if ($0 ~ /^#/) next
14+
genome = $1
15+
split($0, a, "s__")
16+
species = a[length(a)]
17+
if (species != "" && !(species in gtdb_ref))
18+
gtdb_ref[species] = genome
19+
gtdb_species[species] = 1
20+
next
21+
}
22+
23+
# File 2: gtdbtk_species_representatives.tsv -> your_rep -> species
24+
FILENAME==ARGV[2] {
25+
if ($0 ~ /^#/) next
26+
your_rep = $1
27+
split($0, a, "s__")
28+
species = a[length(a)]
29+
bin_species[your_rep] = species
30+
next
31+
}
32+
33+
# File 3: memberships.tsv -> process each representative
34+
FILENAME==ARGV[3] {
35+
if ($0 ~ /^#/) next
36+
your_rep = $1
37+
species = (your_rep in bin_species) ? bin_species[your_rep] : ""
38+
if (species != "" && species in gtdb_ref) {
39+
print your_rep, gtdb_ref[species] # user rep -> matched GTDB ref
40+
covered[species] = 1
41+
} else {
42+
print your_rep, "unknown" # no GTDB species match
43+
}
44+
next
45+
}
46+
47+
END {
48+
# GTDB species not covered by any user representative
49+
for (species in gtdb_ref) {
50+
if (!(species in covered)) {
51+
ref = gtdb_ref[species]
52+
print ref, ref
53+
}
54+
}
55+
}
56+
' "$GTDB_TAX" "$GTDBTK" "$MEMBERS"

0 commit comments

Comments
 (0)