Skip to content

Commit

Permalink
cleanup.
Browse files Browse the repository at this point in the history
when -s is selected, the fasta output is grouped by motif for ease of comparison
when -s is not selected, the output is per organism.

this may change in the future, may be confusing.
  • Loading branch information
nlabrad committed Nov 21, 2022
1 parent af4921f commit bd647d5
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 67 deletions.
Empty file removed KJ746516.1output.fasta
Empty file.
Empty file removed KM438182.1output.fasta
Empty file.
Empty file removed KM438187.1output.fasta
Empty file.
Empty file removed KM438189.1output.fasta
Empty file.
Empty file removed KU925869.1output.fasta
Empty file.
Empty file removed KY379857.1output.fasta
Empty file.
Empty file removed KY379868.1output.fasta
Empty file.
Empty file removed MF351541.1output.fasta
Empty file.
Empty file removed MT488084.1output.fasta
Empty file.
Empty file removed MT488195.1output.fasta
Empty file.
Empty file removed ON685819.1output.fasta
Empty file.
57 changes: 34 additions & 23 deletions cims.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,22 +329,31 @@ def trna_check(motifs):
else:
print(Fore.RED + "tRNA1: " + trnas['tRNA_ile'])

def generate_fasta(organisms):
def generate_fasta(organisms, bymotif = False):
"""Writes output to fasta file
Args:
organisms (list): list of organisms to write
singlefile (bool, optional): If -s is enabled, output to one file per motif with multiple organisms. Defaults to False.
"""

p = Path('output')
p.mkdir(exist_ok=True) #If ./output doesn't exist, create it.
for org in organisms:
p = Path('output')
p.mkdir(exist_ok=True)
#with (p / org["name"].replace('.','') + "-motifs.fasta").open('w') as fasta_output:
fasta_output = open("./output/" + org["name"].replace('.','') + "-motifs.fasta","w")
if not bymotif:
fasta_output = open("./output/" + org["name"].replace('.','') + "-motifs.fasta","w", encoding="utf8")
for key in org:
if key != "name":
if (org[key]is not None):
if (len(org[key]) > 1):
for i in range(len(org[key])):
fasta_output.write(">" + org["name"] + " - " + str(key) + "." + str(i) + "\n" + str(org[key][i]) + "\n")
else:
for entry in org[key]:
fasta_output.write(">" + org["name"] + " - " + str(key) + "\n" + str(entry) + "\n")
if bymotif:
if key != "name":
fasta_output = open("./output/" + key + "-output.fasta","w", encoding="utf8")
if (org[key]is not None):
if (len(org[key]) > 1):
for i in range(len(org[key])):
fasta_output.write(">" + org["name"] + " - " + str(key) + "." + str(i) + "\n" + str(org[key][i]) + "\n")
else:
for entry in org[key]:
fasta_output.write(">" + org["name"] + " - " + str(key) + "\n" + str(entry) + "\n")

fasta_output.close()


Expand Down Expand Up @@ -426,14 +435,16 @@ def generate_fasta(organisms):
for organism in processed_organisms:
trna_check(organism)
else:
delete_items = ["ITS_region", "leader", "d1d1", "sp_d2d3_sp", "tRNA_ile", "sp_v2_sp", "tRNA_ala", "BoxB", "BoxA", "D4", "V3"]
if args.select == 'all':
delete_items.clear()
else:
delete_items = [x for x in delete_items if x not in args.select]
for organism in processed_organisms:
for item in delete_items:
del organism[item]
print_motifs(organism)
if args.select:
delete_items = ["ITS_region", "leader", "d1d1", "sp_d2d3_sp", "tRNA_ile", "sp_v2_sp", "tRNA_ala", "BoxB", "BoxA", "D4", "V3"]
if args.select == 'all':
delete_items.clear()
else:
delete_items = [x for x in delete_items if x not in args.select]
for organism in processed_organisms:
for item in delete_items:
del organism[item]
print_motifs(organism)
if args.output:
generate_fasta(processed_organisms)
generate_fasta(processed_organisms, args.select != 'all')

Empty file removed output.fasta
Empty file.
2 changes: 0 additions & 2 deletions output/KJ7465161-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
>KJ746516.1 - d1d1
GACAAACTGATCATGATGTC
6 changes: 0 additions & 6 deletions output/KM4381821-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
>KM438182.1 - d1d1.0
GACCAAACCCATTAGACTCTGAAACAATTTGGAATAGGAGCTAGTGAGGTC
>KM438182.1 - d1d1.1
GACCAAACCCATTAGACTCTGAAACAATTTGGAATAGGAGCTAGTGAGGTCATCCTAGGTC
>KM438182.1 - d1d1.2
GACCAAACCCATTAGACTCTGAAACAATTTGGAATAGGAGCTAGTGAGGTCATCCTAGGTCGCAACGAGGGGCAACTGGAGATGCTTTCAAACTAGAGTTCAGGTC
6 changes: 0 additions & 6 deletions output/KM4381871-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
>KM438187.1 - d1d1.0
GACCTAACCCATTCGACTCCGAAAAAAAGTTAAGAGGAGCGAGTGAGGTC
>KM438187.1 - d1d1.1
GACCTAACCCATTCGACTCCGAAAAAAAGTTAAGAGGAGCGAGTGAGGTCATCCTAGGTC
>KM438187.1 - d1d1.2
GACCTAACCCATTCGACTCCGAAAAAAAGTTAAGAGGAGCGAGTGAGGTCATCCTAGGTCGGGATGAGGGGCAAACCCAGCTTTCAAACTAGAGTTCAGGTC
6 changes: 0 additions & 6 deletions output/KM4381891-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
>KM438189.1 - d1d1.0
GACCTAACCCATTCGACTCCGAAAAAAAGTCAATAGGAGAGGATGAGGTC
>KM438189.1 - d1d1.1
GACCTAACCCATTCGACTCCGAAAAAAAGTCAATAGGAGAGGATGAGGTCATCCTAGGTC
>KM438189.1 - d1d1.2
GACCTAACCCATTCGACTCCGAAAAAAAGTCAATAGGAGAGGATGAGGTCATCCTAGGTCGGGATGAGGGGCAAACCCAGCTTTCAAACTAGAGTTCAGGTC
2 changes: 0 additions & 2 deletions output/KU9258691-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
>KU925869.1 - d1d1
GACAAACCTGATCATGATGTC
2 changes: 0 additions & 2 deletions output/KY3798571-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
>KY379857.1 - d1d1
GACAAACCTAATCGTGATGTC
2 changes: 0 additions & 2 deletions output/KY3798681-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
>KY379868.1 - d1d1
GACAAACCTAATCGTGATGTC
6 changes: 0 additions & 6 deletions output/MF3515411-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
>MF351541.1 - d1d1.0
GACCTAACCCATTCGACTCCGAAAAAAAGTCAATAGGAGAGGATGAGGTC
>MF351541.1 - d1d1.1
GACCTAACCCATTCGACTCCGAAAAAAAGTCAATAGGAGAGGATGAGGTCATCCTAGGTC
>MF351541.1 - d1d1.2
GACCTAACCCATTCGACTCCGAAAAAAAGTCAATAGGAGAGGATGAGGTCATCCTAGGTCGGGATGAGGGGCAAACCCAGCTTTCAAACTAGAGTTCAGGTC
4 changes: 0 additions & 4 deletions output/MT4880841-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
>MT488084.1 - d1d1
GACCTACCCACTTTTACTTAAGGGCAACATGTTGTCGAACGAGTAAGAGTTGGTCATCCCAAGGTC
>MT488084.1 - V3
GTAGTCAAAGCGATATCTGTTTGAATGAATGAGTGTGTTTATTCGCATGAGTTTATTTGGATAGGTGTTGAAAGAAGACAAGAAGACACCAATGATTATTTTGTGGTCAAGCTACAAAGGGCTGATGGTGGATACCTAGGCACAC
6 changes: 0 additions & 6 deletions output/MT4881951-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,6 +0,0 @@
>MT488195.1 - d1d1.0
GACCTATTTGCCGTTGACCTCTTCTTAGTATTAAGGTC
>MT488195.1 - d1d1.1
GACCTATTTGCCGTTGACCTCTTCTTAGTATTAAGGTCACACAGGCAAGTCATCCTAGGTC
>MT488195.1 - V3
GTAGTTCTCAGTCATGAGTGAACAGTCAAGGGAGATTTAATGAAATCGCCTGGACTAGGAAACGAATGACTGGTGAAAAGACGTATCACAG
2 changes: 0 additions & 2 deletions output/ON6858191-motifs.fasta
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
>ON685819.1 - d1d1
GACCTACCCACTTTTACTTAAGGGCAACATGTTGTCGAACGAGTAAGAGTTGGTCATCCCAAGGTC
2 changes: 2 additions & 0 deletions output/d1d1-output.fasta
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
>KJ746516.1 - d1d1
GACAAACTGATCATGATGTC

0 comments on commit bd647d5

Please sign in to comment.