69 lines
No EOL
1.4 KiB
Python
69 lines
No EOL
1.4 KiB
Python
#!/usr/bin/env python
|
|
|
|
# simple script to organize the vxheaven collection
|
|
#
|
|
# Usage:
|
|
# Create input list
|
|
# Run this script
|
|
# ... Watch it go?
|
|
|
|
|
|
import os
|
|
import sys
|
|
|
|
from pathlib import Path, PurePath
|
|
|
|
import tree
|
|
import vxheaven_parse
|
|
|
|
# tree used to hold samples
|
|
sample_tree = tree.Tree()
|
|
|
|
|
|
def get_sample_name_from_tree_node(node):
|
|
sample_name = ''
|
|
if not node.is_sample:
|
|
return sample_name
|
|
|
|
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
|
|
|
|
for item in reversed(parent_list):
|
|
sample_name += f'{item}.'
|
|
|
|
sample_name += node.item
|
|
return sample_name
|
|
|
|
# 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)
|
|
|
|
if node.item is not None:
|
|
node_name = node.item
|
|
|
|
# Tab the list for clarity
|
|
tab = ''
|
|
for i in range(0, node.get_parent_count()):
|
|
tab += '\t'
|
|
|
|
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) |