Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
geomarceau committed Nov 20, 2023
2 parents 9fcabac + f1cb9ee commit 35b92ba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 72 deletions.
18 changes: 9 additions & 9 deletions aphylogeo/alignement.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,20 @@ def align(self) -> Alignment:
self.centroidSeq = self.sequences.pop(self.centroidKey)
self.aligned = self.alignSequencesWithPairwise()
if Params.fit_method == "1":
self.heuristicMSA = self.starAlignement()
heuristicMSA = self.starAlignement()
elif Params.fit_method == "2":
self.heuristicMSA = self.narrowFitPairwise()
heuristicMSA = self.narrowFitPairwise()

elif Params.alignment_method == "2":
self.heuristicMSA = self.muscleAlign()
heuristicMSA = self.muscleAlign()
elif Params.alignment_method == "3":
self.heuristicMSA = self.clustalAlign()
heuristicMSA = self.clustalAlign()
elif Params.alignment_method == "4":
self.heuristicMSA = self.mafftAlign()
heuristicMSA = self.mafftAlign()
else:
raise ValueError("Invalid alignment method")
[os.remove(file) for file in glob.glob("bin/tmp/*.fasta")] # Remove temp fasta files
self.windowed = self.slidingWindow()
self.windowed = self.slidingWindow(heuristicMSA)
self.msa = self.makeMSA()
self.alignment = Alignment(Params.alignment_method, self.msa)
return self.alignment
Expand Down Expand Up @@ -707,7 +707,7 @@ def insertDash(self, dict, pos, keyList):
dict[k] = s
return dict

def slidingWindow(self, optimized=True):
def slidingWindow(self, heuristicMSA, optimized=True):
"""
Method that slices all the sequences in a dictionary to a specific window (substring)
Expand All @@ -734,9 +734,9 @@ def slidingWindow(self, optimized=True):
step = Params.window_size

windowed_alignment = dict()
seq_len = max([len(h) for h in self.heuristicMSA.values()])
seq_len = max([len(h) for h in heuristicMSA.values()])

paddedMSA = {key: str(val).ljust(seq_len, "-") for key, val in self.heuristicMSA.items()}
paddedMSA = {key: str(val).ljust(seq_len, "-") for key, val in heuristicMSA.items()}

if optimized:
for i in range(0, seq_len, step):
Expand Down
52 changes: 0 additions & 52 deletions aphylogeo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,58 +178,6 @@ def euclideanDist(tree1, tree2):
return ed


# G.M. Commented tree section out because it was not used
# def drawTreesmake(trees, p):
# """
# Function that will draw the trees for each climatic variable.
# The DistanceTreeConstructor object is transformed to Newick format and
# loaded as a toytree MulTitree object. Some stylings are applied and the
# resulting trees are drawed into a .pdf in the viz/ dir.

# Args:
# trees (Dictionnary of DistanceTreeConstructor object with climatic
# variable for keys)
# p (Params object)

# """
# treesNewick = {}
# toytrees = []


# for k, v in trees.items():
# treesNewick[k] = v.format("newick")
# ttree = toytree.tree(treesNewick[k], tree_format=1)
# toytrees.append(ttree)
# mtree = toytree.mtree(toytrees)

# # Setting up the stylings for nodes
# for tree in mtree.treelist:
# tree.style.edge_align_style = {"stroke": "black", "stroke-width": 1}
# for node in tree.treenode.traverse():
# if node.is_leaf():
# node.add_feature("color", toytree.colors[7])
# else:
# node.add_feature("color", toytree.colors[1])
# colors = tree.get_node_values("color", show_root=1, show_tips=1)

# # Draw the climatic trees
# canvas, axes, mark = mtree.draw(
# nrows=round(len(mtree) / 5),
# ncols=len(mtree),
# height=400,
# width=1000,
# node_sizes=8,
# node_colors=colors,
# tip_labels_align=True,
# )

# for i in range(len(mtree)):
# randColor = "#%03x" % random.randint(0, 0xFFF)
# axes[i].text(0, mtree.ntips, p.names[i + 1], style={"fill": randColor, "font-size": "10px", "font-weight": "bold"})

# toyplot.pdf.render(canvas, "../viz/climactic_trees.pdf")


def createTree(dm):
"""
Create a dna tree from content coming from a fasta file.
Expand Down
2 changes: 1 addition & 1 deletion tests/test_climatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def climaticTreesSetup():
climaticTrees (dict): A dictionary containing the climatic trees.
"""
p = Params(os.path.join(os.path.dirname(__file__), "params_very_small.yaml"))
return utils.climaticPipeline(pd.read_csv(p.file_name), p.names)
return utils.climaticPipeline(pd.read_csv(p.file_name))


def test_climaticPipeline():
Expand Down
20 changes: 10 additions & 10 deletions tests/test_genetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

current_file = os.path.dirname(__file__)


class TestGenetic:
def setup_class(self):
"""
Expand All @@ -37,7 +36,9 @@ def setup_class(self):
params_very_small.bootstrapAmount,
params_very_small.alignment_method,
params_very_small.reference_gene_file,
params_very_small.distance_method,
params_very_small.fit_method,
params_very_small.rate_similarity,
params_very_small.method_similarity
)
very_small.align()
self.alignementSetup = [very_small] # , small]
Expand All @@ -50,10 +51,9 @@ def test_centroidKey(self):

print("Begin test_centroidKey...")

for alignement, p in zip(self.alignementSetup, self.paramSetup):
test_case = p.reference_gene_filename[0:-6]
for alignement in self.alignementSetup:
actual_centroid = alignement.centroidKey
filename = Path(current_file + "/testFiles/getSequenceCentroid/" + test_case)
filename = current_file + "/testFiles/getSequenceCentroid/seq very small"

with open(filename, "r") as expected_file:
expected_centroid = expected_file.read()
Expand All @@ -66,7 +66,7 @@ def test_aligned(self):

print("Begin test_aligned...")

for alignement, p in zip(self.alignementSetup, self.paramSetup):
for alignement in self.alignementSetup:
aligned = alignement.aligned

for key in aligned.keys():
Expand All @@ -80,8 +80,8 @@ def test_heuristicMSA(self):

print("Begin test_heuristicMSA...")

for alignement, p in zip(self.alignementSetup, self.paramSetup):
starAlignement = alignement.heuristicMSA
for alignement in self.alignementSetup:
starAlignement = alignement.starAlignement()
expected = AlignSequences.fileToDict(current_file + "/testFiles/starAlignement/seq very small", ".fasta")
assert starAlignement == expected

Expand All @@ -92,7 +92,7 @@ def test_windowed(self):

print("Begin test_windowed...")

for alignement, p in zip(self.alignementSetup, self.paramSetup):
for alignement in self.alignementSetup:
windowed = alignement.windowed

for key in windowed.keys():
Expand All @@ -106,7 +106,7 @@ def test_msaSet(self):

print("Begin test_msaSet...")

for alignement, p in zip(self.alignementSetup, self.paramSetup):
for alignement in self.alignementSetup:
msa = alignement.msa

for key in msa.keys():
Expand Down

0 comments on commit 35b92ba

Please sign in to comment.