Skip to content

Commit

Permalink
log added
Browse files Browse the repository at this point in the history
  • Loading branch information
furacca committed May 10, 2022
1 parent 26aef60 commit 5c9da24
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 50 deletions.
10 changes: 5 additions & 5 deletions create_html_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def html_body(fasta_file, tsv_file, result_dictionary, table_list):
<head>
<meta charset="UTF-8">
<title>Cuterle</title>
<link rel="icon" href="images/favicon.ico">
<link rel="icon" href="../images/favicon.ico">
</head>
<body>
<img style="max-width:35%;" src="images/00_logo.png"><br>
<img style="max-width:35%;" src="../images/00_logo.png"><br>
<table style="border:1px solid black">
<tr>
<td>Fasta file input:</td>
Expand All @@ -113,7 +113,7 @@ def html_body(fasta_file, tsv_file, result_dictionary, table_list):
<td>{number_of_sequeces}</td>
</tr>
<tr>
<td>Number of domains:</td>
<td>Domains found:</td>
<td>{number_of_domains}</td>
</tr>
<table style="border:1px solid black">
Expand All @@ -126,8 +126,8 @@ def html_body(fasta_file, tsv_file, result_dictionary, table_list):
return text


def create_html_output(fasta_file, tsv_file, i, result_dictionary, table_list):
with open("graphical_output%i.html" % i, "w") as file:
def create_html_output(folder_name, fasta_file, tsv_file, result_dictionary, table_list):
with open(f"{folder_name}/graphical_output.html", "w") as file:
texts_to_write = html_body(fasta_file, tsv_file, result_dictionary, table_list)
file.write(texts_to_write)
# pdfkit.from_file(file)
Expand Down
56 changes: 33 additions & 23 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tabulate import tabulate
from Bio import SeqIO
from datetime import date
import csv


# Create a file_list with all the file with the extension requested
Expand Down Expand Up @@ -48,34 +49,43 @@ def check_column_name(tsv_file):
file.write(copia)


# def i_counter():
#
# list_of_file = os.listdir("./")
# if "extracted_domains.fasta" in list_of_file \
# or "domains_table.csv" in list_of_file \
# or "domains_list.csv" in list_of_file:
# i = 1
# while os.path.exists("extracted_domains%s.fasta" % i):
# i += 1
# while os.path.exists("domains_table%s.csv" % i):
# i += 1
# while os.path.exists("domains_list%s.csv" % i):
# i += 1
# else:
# i = ""
# return i

def i_counter():
# Set the date
today = date.today()

list_of_file = os.listdir("./")
i = 1
if f"{str(today)}_Analyis_number_1" in list_of_file:
while os.path.exists(f"{str(today)}_Analyis_number_{i}"):
i += 1
# if "log.txt" in list_of_file:
# with open("log.txt", "r") as file:
# firstline = csv.reader(file)
# for everyrow in firstline:
# if everyrow[0] == f"{today}_counter":
# i = int(everyrow[1])
# else:

if "log.txt" in list_of_file:
old_log = []
with open("log.txt", "r") as file:
everyline = csv.reader(file)
for everyrow in everyline:
old_log.append(everyrow)

i = int(old_log[len(old_log) - 1][1])
i += 1
with open("log.txt", "w") as file:
counter = "counter"
for everyitem in old_log:
file.write(f"{everyitem[0]},{everyitem[1]}\n")
file.write(f"{today}_{counter},{i}")
else:
i = "1"
with open("log.txt", "w") as file:
i = 1
counter = "counter"
file.write(f"{today}_{counter},{i}")

# if f"{str(today)}_Analyis_number_1" in list_of_file:
# while os.path.exists(f"{str(today)}_Analyis_number_{i}"):
# i += 1
# else:
# i = "1"

folder_name = f"{str(today)}_Analyis_number_{i}"

Expand Down
28 changes: 6 additions & 22 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@
type=str,
)

cuterle_parser.add_argument("-savetable",
help="Export all kind of domains extracted in ~.csv file, sort by matches",
action="store_true"
)

cuterle_parser.add_argument("-html",
help="Graphical output",
action="store_true"
)

cuterle_parser.add_argument("-draw_image",
help="FOR EACH sequences create a ~.jpg file reporting sequence+domains",
action="store_true"
Expand All @@ -102,8 +92,6 @@
prior_choice = cuterle_options.a
name_format = cuterle_options.nf
accession = cuterle_options.accession
table_choice = cuterle_options.savetable
html_choice = cuterle_options.html
draw_choice = cuterle_options.draw_image

# *********************************************************************************************
Expand Down Expand Up @@ -160,11 +148,8 @@
print(f"{fasta_file} doesn't exist or doesn't has .fasta extension. Retry.")
pass



folder_name = i_counter()


# Checks (and eventually add) if the tsv file already has columns' name (0, 1, 2, 3, ...)
check_column_name(tsv_file)

Expand Down Expand Up @@ -192,14 +177,13 @@

# Create a table
table_list = create_table_row_list(result_dictionary)

if manual_mode:
if table_choice:
with open(f"{folder_name}/domains_list.csv", "w") as domain_csv:
for everyrow in table_list:
domain_csv.write(f"{everyrow[0]},{everyrow[1]},{everyrow[2]}\n")
if html_choice:
create_html_output(fasta_file, tsv_file, result_dictionary, table_list)
# if table_choice:
with open(f"{folder_name}/domains_list.csv", "w") as domain_csv:
for everyrow in table_list:
domain_csv.write(f"{everyrow[0]},{everyrow[1]},{everyrow[2]}\n")
# if html_choice:
create_html_output(folder_name, fasta_file, tsv_file, result_dictionary, table_list)

save_choice_list = []
domain_to_save = []
Expand Down

0 comments on commit 5c9da24

Please sign in to comment.