anvi-get-split-coverages should report sample background colors in a separate file
The program anvi-script-visualize-split-coverages (see #1171) accepts additional data files for samples to set background colors which has currently two columns, sample_name and sample_color. If there is a default state in the PRFOFILE.db, the program anvi-get-split-coverages can report an additional TAB-delimited file to utilize the color information stored in the database during visualization.
I was poking around the code thinking about working on this...do you have any hints to get started on it?
hey @mooreryan! :) I think one of the best ways to do it is to read the state json text from the profile database and see if the sample names have any colors somewhere in the anvi-get-split-coverages file.
I just put this together for you instead of sending line numbers from the codebase so you have an idea about the way to access it. this will work on any profile database and will give you layer colors if the user stored a default state in their db.
import sys
import json
import argparse
import anvio
import anvio.utils as utils
import anvio.terminal as terminal
from anvio.dbops import TablesForStates
# for pretty outputs:
run = terminal.Run()
parser = argparse.ArgumentParser(description='Tadaa')
parser.add_argument(*anvio.A('profile-db'), **anvio.K('profile-db'))
args = parser.parse_args()
profile_db_path = args.profile_db
utils.is_profile_db(profile_db_path)
# get an instance of the states table
states_table = TablesForStates(profile_db_path)
# if there are no states stored, there are no states stored.
if not len(states_table.states):
run.info_single("This database has no states.")
sys.exit()
# so there are some? kewl. list states:
states_table.list_states()
# is there a default one?
if 'default' in states_table.states:
run.info_single("Default state found! Here are some information on layer colors:", mc='green')
default_state = json.loads(states_table.states['default']['content'])
for layer_name in default_state['layers']:
layer_info = default_state['layers'][layer_name]
if 'color' in layer_info:
run.info(layer_name, 'Color: %s' % layer_info['color'])
else:
run.info(layer_name, 'No layer color :/')
else:
run.info_single("No default state.", mc='green')
I hope it makes sense :)