Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy colors file to output directory instead of replacing working dir copy #54

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions ArrowerSVG.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
######################################################################

import os
from pathlib import Path
import sys
from Bio import SeqIO
from random import uniform
Expand All @@ -27,16 +28,14 @@
gene_contour_thickness = 2 # thickness grows outwards
stripe_thickness = 3

domains_color_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), "domains_color_file.tsv")


def read_color_domains_file():
def read_color_domains_file(output_folder):
# Try to read colors for domains
color_domains = {}

if os.path.isfile(domains_color_file):
if os.path.isfile(output_folder / Path("domains_color_file.tsv")):
print(" Found file with domains colors")
with open(domains_color_file, "r") as color_domains_handle:
with open(output_folder / Path("domains_color_file.tsv"), "r") as color_domains_handle:
for line in color_domains_handle:
# handle comments and empty lines
if line[0] != "#" and line.strip():
Expand All @@ -46,7 +45,7 @@ def read_color_domains_file():
color_domains[name] = [int(rgb[x]) for x in range(3)]
else:
print(" Domains colors file was not found. An empty file will be created")
color_domains_handle = open(domains_color_file, "a+")
color_domains_handle = open(output_folder / Path("domains_color_file.tsv"), "a+")

return color_domains

Expand Down Expand Up @@ -311,7 +310,7 @@ def new_color(gene_or_domain):
return [r, g, b]


def SVG(write_html, outputfile, GenBankFile, BGCname, pfdFile, use_pfd, color_genes, color_domains, pfam_domain_categories, pfam_info, loci, max_width, H=30, h=15, l=30, mX=10, mY=10, scaling=30, absolute_start=0, absolute_end=-1):
def SVG(output_folder, write_html, outputfile, GenBankFile, BGCname, pfdFile, use_pfd, color_genes, color_domains, pfam_domain_categories, pfam_info, loci, max_width, H=30, h=15, l=30, mX=10, mY=10, scaling=30, absolute_start=0, absolute_end=-1):
'''
Create the main SVG document:
- read pfd file with domain information (pfdFile contains complete path)
Expand Down Expand Up @@ -609,7 +608,7 @@ def SVG(write_html, outputfile, GenBankFile, BGCname, pfdFile, use_pfd, color_ge
#else:
#print(" Saving new color names for 10+ domains")

with open(domains_color_file, "a") as color_domains_handle:
with open(output_folder / Path("domains_color_file.tsv"), "a") as color_domains_handle:
for new_names in new_color_domains:
color_domains_handle.write(new_names + "\t" + ",".join([str(ncdom) for ncdom in new_color_domains[new_names]]) + "\n")

Expand Down
4 changes: 2 additions & 2 deletions bigscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2719,15 +2719,15 @@ def __init__(self, accession_id, description, product, records, max_width, bgc_s

if len(working_set) > 0:
color_genes = {}
color_domains = read_color_domains_file()
color_domains = read_color_domains_file(output_folder)
pfam_domain_categories = {}

#This must be done serially, because if a color for a gene/domain
# is not found, the text files with colors need to be updated
print(" Reading BGC information and writing SVG")
for bgc in working_set:
with open(genbankDict[bgc][0],"r") as handle:
SVG(False, os.path.join(svg_folder,bgc+".svg"), handle, bgc, os.path.join(pfd_folder,bgc+".pfd"), True, color_genes, color_domains, pfam_domain_categories, pfam_info, bgc_info[bgc].records, bgc_info[bgc].max_width)
SVG(output_folder, False, os.path.join(svg_folder,bgc+".svg"), handle, bgc, os.path.join(pfd_folder,bgc+".pfd"), True, color_genes, color_domains, pfam_domain_categories, pfam_info, bgc_info[bgc].records, bgc_info[bgc].max_width)

color_genes.clear()
color_domains.clear()
Expand Down