2024-10-20 06:33:49 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# simple script to organize the vxheaven collection
|
|
|
|
#
|
|
|
|
# Usage:
|
2024-10-21 10:56:44 -04:00
|
|
|
# Create input list
|
2024-10-20 06:33:49 -04:00
|
|
|
# Run this script
|
|
|
|
# ... Watch it go?
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from pathlib import Path, PurePath
|
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
import tree
|
|
|
|
import vxheaven_parse
|
2024-10-20 06:33:49 -04:00
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
# tree used to hold samples
|
|
|
|
sample_tree = tree.Tree()
|
2024-10-20 06:33:49 -04:00
|
|
|
|
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
def get_sample_name_from_tree_node(node):
|
|
|
|
sample_name = ''
|
|
|
|
if not node.is_sample:
|
|
|
|
return sample_name
|
2024-10-20 06:33:49 -04:00
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
parent_list = []
|
|
|
|
parent = node.parent
|
|
|
|
while parent is not None:
|
|
|
|
# reached the root node of the tree
|
|
|
|
if parent.item is None:
|
|
|
|
break
|
|
|
|
parent_list.append(parent.item)
|
|
|
|
parent = parent.parent
|
2024-10-20 06:33:49 -04:00
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
for item in reversed(parent_list):
|
|
|
|
sample_name += f'{item}.'
|
2024-10-20 06:33:49 -04:00
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
sample_name += node.item
|
|
|
|
return sample_name
|
2024-10-20 06:33:49 -04:00
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
# python doesn't have true anonymous functions.
|
|
|
|
# I really regret writing this in python but i've sunk too much
|
|
|
|
# in to rewrite this in C++ or something
|
|
|
|
def walk_cb(node):
|
|
|
|
node_name = '(root)'
|
|
|
|
sample_name = get_sample_name_from_tree_node(node)
|
2024-10-20 06:33:49 -04:00
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
if node.item is not None:
|
|
|
|
node_name = node.item
|
2024-10-20 06:33:49 -04:00
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
# Tab the list for clarity
|
|
|
|
tab = ''
|
|
|
|
for i in range(0, node.get_parent_count()):
|
|
|
|
tab += '\t'
|
2024-10-20 06:33:49 -04:00
|
|
|
|
2024-10-21 10:56:44 -04:00
|
|
|
leaf = ''
|
|
|
|
if node.is_sample:
|
|
|
|
leaf = f' (sample {sample_name})'
|
|
|
|
|
|
|
|
print(f"{tab}{node_name}{leaf}")
|
|
|
|
|
|
|
|
|
|
|
|
# Parse sample tree from vxheaven list
|
|
|
|
vxheaven_parse.parse_into_tree(sample_tree, './samples.sort')
|
|
|
|
|
|
|
|
# Walk the sample tree (currently, just dumps it for debugging)
|
|
|
|
sample_tree.walk(walk_cb)
|