Skip to content

Commit

Permalink
[add] improve code in alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
ibigen committed Feb 5, 2022
1 parent c68d4f1 commit 7ae442a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 39 deletions.
15 changes: 10 additions & 5 deletions templates/project_sample/project_sample_show.html
Original file line number Diff line number Diff line change
Expand Up @@ -335,12 +335,17 @@ <h5 class="mb-0">
</button>
<div class="dropdown-menu">
{% if nextclade_link_covid %}
<a href="{{nextclade_link_covid}}" data-title="Upload your Consensus File in NextClade Annotation SARS-Cov 2" class="dropdown-item" ><span class="hidden-phone"> (SARS-Cov 2)</span></a>
<a href="{{nextclade_link_covid}}" data-title="Upload your Consensus File in NextClade Annotation SARS-CoV-2"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (SARS-CoV-2)</span></a>
{% else %}
<a href="{{nextclade_link_a_h3n2}}" data-title="Upload your Consensus File in NextClade Annotation A-H3N2" class="dropdown-item" ><span class="hidden-phone"> (A-H3N2)</span></a>
<a href="{{nextclade_link_a_h1n1}}" data-title="Upload your Consensus File in NextClade Annotation A-H1N1" class="dropdown-item" ><span class="hidden-phone"> (A-H1N1)</span></a>
<a href="{{nextclade_link_b_yamagata}}" data-title="Upload your Consensus File in NextClade Annotation B-Yamagata" class="dropdown-item" ><span class="hidden-phone"> (B-Yamagata)</span></a>
<a href="{{nextclade_link_b_victoria}}" data-title="Upload your Consensus File in NextClade Annotation B-Vitoria" class="dropdown-item" ><span class="hidden-phone"> (B-Vitoria)</span></a>
<a href="{{nextclade_link_a_h3n2}}" data-title="Upload your Consensus File in NextClade Annotation A-H3N2"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (A-H3N2)</span></a>
<a href="{{nextclade_link_a_h1n1}}" data-title="Upload your Consensus File in NextClade Annotation A-H1N1"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (A-H1N1)</span></a>
<a href="{{nextclade_link_b_yamagata}}" data-title="Upload your Consensus File in NextClade Annotation B-Yamagata"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (B-Yamagata)</span></a>
<a href="{{nextclade_link_b_victoria}}" data-title="Upload your Consensus File in NextClade Annotation B-Vitoria"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (B-Vitoria)</span></a>
{% endif %}
</div>
</div>
Expand Down
15 changes: 10 additions & 5 deletions templates/project_sample/project_sample_single_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,17 @@ <h5 class="mb-0">
</button>
<div class="dropdown-menu">
{% if nextclade_link_covid %}
<a href="{{nextclade_link_covid}}" data-title="Upload your Consensus File in NextClade Annotation SARS-Cov 2" class="dropdown-item" ><span class="hidden-phone"> (SARS-Cov 2)</span></a>
<a href="{{nextclade_link_covid}}" data-title="Upload your Consensus File in NextClade Annotation SARS-CoV-2"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (SARS-CoV-2)</span></a>
{% else %}
<a href="{{nextclade_link_a_h3n2}}" data-title="Upload your Consensus File in NextClade Annotation A-H3N2" class="dropdown-item" ><span class="hidden-phone"> (A-H3N2)</span></a>
<a href="{{nextclade_link_a_h1n1}}" data-title="Upload your Consensus File in NextClade Annotation A-H1N1" class="dropdown-item" ><span class="hidden-phone"> (A-H1N1)</span></a>
<a href="{{nextclade_link_b_yamagata}}" data-title="Upload your Consensus File in NextClade Annotation B-Yamagata" class="dropdown-item" ><span class="hidden-phone"> (B-Yamagata)</span></a>
<a href="{{nextclade_link_b_victoria}}" data-title="Upload your Consensus File in NextClade Annotation B-Vitoria" class="dropdown-item" ><span class="hidden-phone"> (B-Vitoria)</span></a>
<a href="{{nextclade_link_a_h3n2}}" data-title="Upload your Consensus File in NextClade Annotation A-H3N2"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (A-H3N2)</span></a>
<a href="{{nextclade_link_a_h1n1}}" data-title="Upload your Consensus File in NextClade Annotation A-H1N1"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (A-H1N1)</span></a>
<a href="{{nextclade_link_b_yamagata}}" data-title="Upload your Consensus File in NextClade Annotation B-Yamagata"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (B-Yamagata)</span></a>
<a href="{{nextclade_link_b_victoria}}" data-title="Upload your Consensus File in NextClade Annotation B-Vitoria"
class="dropdown-item" target="_blank"><span class="hidden-phone"> (B-Vitoria)</span></a>
{% endif %}
</div>
</div>
Expand Down
5 changes: 1 addition & 4 deletions utils/proteins.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,12 +289,11 @@ def save_protein_by_sequence_name_and_cds(self, record_dict_consensus, generic_e
return False

def genetic_element_from_sample(self, reference_fasta_file, record_dict_consensus, genetic_element,
coverage, limit_to_mask_consensus, out_dir):
coverage, limit_to_mask_consensus, temp_dir):
"""
get position where genes consensus from sample matches in the reference
"""
generic_consensus_element = GeneticElement()
temp_dir = self.utils.get_temp_dir()
with open(reference_fasta_file) as handle_ref:
record_dict_ref = SeqIO.to_dict(SeqIO.parse(handle_ref, "fasta"))
if (record_dict_ref is None): return generic_consensus_element
Expand Down Expand Up @@ -361,8 +360,6 @@ def genetic_element_from_sample(self, reference_fasta_file, record_dict_consensu
len(seq_other.replace('-', '')), Gene(
gene.name, cons_start, pos_con,
gene.strand, vect_feature_location))
### remove dir
self.utils.remove_dir(temp_dir)

return generic_consensus_element

27 changes: 13 additions & 14 deletions utils/software.py
Original file line number Diff line number Diff line change
Expand Up @@ -2281,24 +2281,23 @@ def align_two_sequences(self, ref_seq, consensus_seq, out_dir_temp = None):

## test if the output is in fasta
try:
self.utils.is_fasta(temp_file_name_out)
number_record = self.utils.is_fasta(temp_file_name_out)
if (number_record != 2): return "", ""
except IOError as e:
return "", ""

## read file
record_dict = SeqIO.index(temp_file_name_out, "fasta")
if (len(record_dict) != 2): return "", ""

## get both sequences
seq_ref = ""
seq_other = ""
for seq in record_dict:
if (seq == ref_seq_name): ## ref seq
seq_ref = str(record_dict[seq].seq).upper()
else:
seq_other = str(record_dict[seq].seq).upper()

if (out_dir_temp is None): self.utils.remove_dir(out_dir)
with open(temp_file_name_out) as handle:
## get both sequences
seq_ref = ""
seq_other = ""
for record_dict in SeqIO.parse(handle, "fasta"):
if (record_dict.id == ref_seq_name): ## ref seq
seq_ref = str(record_dict.seq).upper()
else:
seq_other = str(record_dict.seq).upper()

if (out_dir_temp is None): self.utils.remove_dir(out_dir)
return seq_ref, seq_other


Expand Down
20 changes: 9 additions & 11 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,16 @@ def is_fasta(self, sz_file_name):
Test Fata file
"""
if (not os.path.exists(sz_file_name)): raise IOError(_("Error: File doens't exist: " + sz_file_name))
handle = open(sz_file_name)
b_pass = False
for line in handle:
sz_temp = line.strip()
if (len(sz_temp) == 0): continue
if (sz_temp[0] == ">"):
b_pass = True
break
else:
handle.close()
raise IOError(_("Error: the file is not in FASTA format."))
handle.close()
with open(sz_file_name) as handle:
for line in handle:
sz_temp = line.strip()
if (len(sz_temp) == 0): continue
if (sz_temp[0] == ">"):
b_pass = True
break
else:
raise IOError(_("Error: the file is not in FASTA format."))
if (not b_pass): raise IOError(_("Error: file is not in FASTA format."))

record_dict = SeqIO.index(sz_file_name, "fasta")
Expand Down

0 comments on commit 7ae442a

Please sign in to comment.