mirror of
http://43.156.76.180:8026/YuuMJ/EukPhylo.git
synced 2025-12-28 05:30:30 +08:00
OG6/G/A, Sim_filter by taxa, and Sim_removed_seqs
This commit is contained in:
parent
bacb094028
commit
22bd67d2fa
@ -15,6 +15,11 @@ def run(params):
|
|||||||
except (FileNotFoundError, TypeError) as e:
|
except (FileNotFoundError, TypeError) as e:
|
||||||
Logger.Error('Unable to read taxon list file. Please make sure that the path is correct and that the file is formatted correctly.\n\n' + str(e))
|
Logger.Error('Unable to read taxon list file. Please make sure that the path is correct and that the file is formatted correctly.\n\n' + str(e))
|
||||||
|
|
||||||
|
try:
|
||||||
|
sim_taxa = list(dict.fromkeys([line.strip() for line in open(params.sim_taxa)]))
|
||||||
|
except (FileNotFoundError, TypeError) as e:
|
||||||
|
Logger.Error('Unable to read similarity taxa list file. Please make sure that the path is correct and that the file is formatted correctly.\n\n' + str(e))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
blacklist_seqs = list(dict.fromkeys([line.strip() for line in open(params.blacklist)]))
|
blacklist_seqs = list(dict.fromkeys([line.strip() for line in open(params.blacklist)]))
|
||||||
except (FileNotFoundError, TypeError) as e:
|
except (FileNotFoundError, TypeError) as e:
|
||||||
@ -31,19 +36,21 @@ def run(params):
|
|||||||
|
|
||||||
os.mkdir(params.output + '/Output/Intermediate/SF_Diamond')
|
os.mkdir(params.output + '/Output/Intermediate/SF_Diamond')
|
||||||
|
|
||||||
|
removed_file = open(params.output + '/Output/Pre-Guidance/SimFilter_removed.txt', 'w')
|
||||||
|
|
||||||
for og in ogs:
|
for og in ogs:
|
||||||
Logger.Message('Processing ' + og)
|
Logger.Message('Processing ' + og)
|
||||||
with open(params.output + '/Output/Pre-Guidance/' + og + '_preguidance.faa', 'w') as preguidance_file:
|
with open(params.output + '/Output/Pre-Guidance/' + og + '_preguidance.faa', 'w') as preguidance_file:
|
||||||
for taxon_file in aa_files:
|
for taxon_file in aa_files:
|
||||||
recs = []
|
recs = []
|
||||||
for rec in sorted([rec for rec in SeqIO.parse(params.data + '/' + taxon_file, 'fasta') if rec.id[-10:] == og and rec.id not in blacklist_seqs], key=lambda x: -len(x.seq)):
|
for rec in sorted([rec for rec in SeqIO.parse(params.data + '/' + taxon_file, 'fasta') if rec.id[-10:] == og and rec.id not in blacklist_seqs and params.og_identifier in rec.id], key=lambda x: -len(x.seq)):
|
||||||
if(rec.id == rec.description):
|
if(rec.id == rec.description):
|
||||||
recs.append(rec)
|
recs.append(rec)
|
||||||
else:
|
else:
|
||||||
Logger.Warning('\tThe sequence ID ' + rec.description + ' is invalid. Please make sure that sequence IDs contain no spaces, tabs, etc. This sequence is being excluded.')
|
Logger.Warning('\tThe sequence ID ' + rec.description + ' is invalid. Please make sure that sequence IDs contain no spaces, tabs, etc. This sequence is being excluded.')
|
||||||
|
|
||||||
masters = []; removed = 0; flag = 0; cycle = 0
|
masters = []; removed = 0; flag = 0; cycle = 0
|
||||||
if params.similarity_filter:
|
if params.similarity_filter and taxon_file[:10] in sim_taxa:
|
||||||
if len(recs) > 1:
|
if len(recs) > 1:
|
||||||
while flag == 0:
|
while flag == 0:
|
||||||
master_file_name = params.output + '/Output/Intermediate/SF_Diamond/' + og + '_' + taxon_file[:10] + '_master_' + str(cycle)
|
master_file_name = params.output + '/Output/Intermediate/SF_Diamond/' + og + '_' + taxon_file[:10] + '_master_' + str(cycle)
|
||||||
@ -75,11 +82,16 @@ def run(params):
|
|||||||
recs = [rec for rec in recs[1:] if rec.id not in recs_to_remove]
|
recs = [rec for rec in recs[1:] if rec.id not in recs_to_remove]
|
||||||
cycle += 1
|
cycle += 1
|
||||||
|
|
||||||
|
for item in recs_to_remove:
|
||||||
|
removed_file.write(f"{item}\n")
|
||||||
|
|
||||||
Logger.Message('\t' + str(removed) + ' sequence(s) removed by the similarity filter (' + str(cycle + 1) + ' iterations) from ' + taxon_file[:10])
|
Logger.Message('\t' + str(removed) + ' sequence(s) removed by the similarity filter (' + str(cycle + 1) + ' iterations) from ' + taxon_file[:10])
|
||||||
|
|
||||||
for rec in recs + masters:
|
for rec in recs + masters:
|
||||||
preguidance_file.write('>' + rec.id + '\n' + str(rec.seq) + '\n\n')
|
preguidance_file.write('>' + rec.id + '\n' + str(rec.seq) + '\n\n')
|
||||||
|
|
||||||
|
removed_file.close()
|
||||||
|
|
||||||
if(not params.keep_temp):
|
if(not params.keep_temp):
|
||||||
os.system('rm -r ' + params.output + '/Output/Intermediate/SF_Diamond')
|
os.system('rm -r ' + params.output + '/Output/Intermediate/SF_Diamond')
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user