Skip to content

Commit

Permalink
fix orientation prediction for non-canonical strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Mitrofanov committed Jul 12, 2023
1 parent c627b30 commit b8fdf46
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions components/components_non_array_computations.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,13 @@ def _compute_all_strands(self):
with open("CRISPR_arrays_for_strand.fa", "w") as f:
for array_index, array in enumerate(self.list_of_crisprs, 1):
consensus = array.consensus
f.write(f">CRISPR_{array_index}_consensus\n{consensus}\n")
consensus_fidex_alphabet = self.remove_non_canonical_char_from_string(consensus)
f.write(f">CRISPR_{array_index}_consensus\n{consensus_fidex_alphabet}\n")

if len(self.list_of_crisprs) == 2:
f.write(f">CRISPR_3_consensus\n{self.list_of_crisprs[-1].consensus}\n")
consensus = self.list_of_crisprs[-1].consensus
consensus_fidex_alphabet = self.remove_non_canonical_char_from_string(consensus)
f.write(f">CRISPR_3_consensus\n{consensus_fidex_alphabet}\n")

try:
os.mkdir("ResultsStrand")
Expand All @@ -133,7 +136,7 @@ def _compute_all_strands(self):
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
a, b = process.communicate()
#print(a, b)
os.remove("CRISPR_arrays_for_strand.fa")
#os.remove("CRISPR_arrays_for_strand.fa")

with open("ResultsStrand/CRISPRstrand_Summary.tsv", "r") as f:
lines = f.readlines()
Expand All @@ -148,6 +151,17 @@ def _compute_all_strands(self):
except Exception:
pass

@staticmethod
def remove_non_canonical_char_from_string(consensus_string):
canonical_chars = ["A", "T", "G", "C"]
new_consensus_string = ""
for char in consensus_string:
if char in canonical_chars:
new_consensus_string += char
else:
new_consensus_string += "N"
return new_consensus_string

def output(self):
return self.dict_strands

Expand Down

0 comments on commit b8fdf46

Please sign in to comment.