Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery Starbot ⭐ refactored A-F-V/Bioinformatics #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SourceryAI
Copy link

Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨

Here's your pull request refactoring your most popular Python repo.

If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch https://github.com/sourcery-ai-bot/Bioinformatics main
git merge --ff-only FETCH_HEAD
git reset HEAD^

o = []
for c in range(len(self.s2)+1):
o.append(self.pos(r,c))
o = [self.pos(r,c) for c in range(len(self.s2)+1)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Alignment_Graph.prnt refactored with the following changes:

Comment on lines +18 to +26
elif first:
if mid == self.start or self.comparer(self.emitter(mid-1)) != 0:
return mid
else:
if mid == self.end or self.comparer(self.emitter(mid+1)) != 0:
return mid
left = mid
right = mid
elif mid == self.end or self.comparer(self.emitter(mid+1)) != 0:
return mid
else:
left = mid
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BinarySearch.search refactored with the following changes:

if self.root ==None:
if self.root is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BinaryTree.__init__ refactored with the following changes:

if node==None:
if node is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BinaryTree.leaves refactored with the following changes:

Comment on lines -54 to +56
else:
ln,lw = self.left(node)
rn,rw = self.right(node)
return lw+rw+self.edgecost(ln)+self.edgecost(rn)
ln,lw = self.left(node)
rn,rw = self.right(node)
return lw+rw+self.edgecost(ln)+self.edgecost(rn)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BinaryTree.edgecost refactored with the following changes:

Comment on lines -23 to +28
if top==None:
if top is None:
graph.set(r,c,graph.pos(r,c-1)+indel,2)
else:
graph.set(r,c,top[c-1])
elif c==0:
if left==None:
if left is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fill_graph_needleman refactored with the following changes:

output = ""
for i in range(self.t):
output += random.choice(self.chars)
return output
return "".join(random.choice(self.chars) for _ in range(self.t))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sequence.random refactored with the following changes:

Comment on lines -55 to +52
for ind in range(self.t):
for _ in range(self.t):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sequence.objWithNum refactored with the following changes:

Comment on lines -90 to +87
if len(o) > 0:
if o:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function accumulate_diff refactored with the following changes:

if key == "END":
return self.graph[len(self.x)+1, "END"]
return self.graph[key]
return self.graph[len(self.x)+1, "END"] if key == "END" else self.graph[key]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ViterbiGraph.__getitem__ refactored with the following changes:

if (a,b) in blosum62:
return blosum62[(a,b)]
return blosum62[(b,a)]
return blosum62[(a,b)] if (a,b) in blosum62 else blosum62[(b,a)]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function blosum62score refactored with the following changes:

Comment on lines -107 to +114
for i in range(1,col+1):
for _ in range(1,col+1):
c2 = [c1[0]+indel]
for row in range(1,height+1):
c2.append(max(c2[row-1]+indel,c1[row]+indel,c1[row-1]+blosum62score(s1[row-1],s2[col-1])))
c2.extend(
max(
c2[row - 1] + indel,
c1[row] + indel,
c1[row - 1] + blosum62score(s1[row - 1], s2[col - 1]),
)
for row in range(1, height + 1)
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function prefix refactored with the following changes:

Comment on lines -150 to +159
f = open(filei,"r")
w1 = f.readline().rstrip('\n')
w2 = f.readline().rstrip('\n')
f.close()
with open(filei,"r") as f:
w1 = f.readline().rstrip('\n')
w2 = f.readline().rstrip('\n')
o = func(w1,w2)
f = open(filej,"w")
f.writelines(str(o))
f.close()
with open(filej,"w") as f:
f.writelines(str(o))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function rosalind refactored with the following changes:

Comment on lines -38 to +43
o1 = "-"+o1
o1 = f"-{o1}"
o2 = graph.s2[c-1]+o2
pointer = (r,c-1)
elif p==1:
o1 = graph.s1[r-1]+o1
o2 = "-"+o2
o2 = f"-{o2}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function trace_pointers_needleman refactored with the following changes:

def neighbour_joining(d_mat: DistanceMatrix, inner_node_next_label=None): # DO NOT USE heaping distance matrix
def neighbour_joining(d_mat: DistanceMatrix, inner_node_next_label=None): # DO NOT USE heaping distance matrix
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function neighbour_joining refactored with the following changes:

Comment on lines +22 to +25

searcher = BinarySearch(0, len(self.indices)-1, comparer, emitter=self.suffix)
frm, to = searcher.search(first=True), searcher.search(first=False)
if frm == None or to == None:
if frm is None or to is None:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SuffixArray.find_matching_pattern refactored with the following changes:

Comment on lines -42 to +44
word = ""
for i in range(len(path) - 1):
word += self.edge_values[(path[i], path[i + 1])]
return word
return "".join(
self.edge_values[(path[i], path[i + 1])] for i in range(len(path) - 1)
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trie.reconstruct_word refactored with the following changes:

Comment on lines -101 to +100
while len(stack) > 0:
while stack:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Trie.compress_non_branching_path refactored with the following changes:

Comment on lines -186 to +191
else:
best = pre_text
for next_node, text in self.edges[node]:
attempt = long_path(next_node, pre_text + text)
if len(attempt) > len(best):
best = attempt
return best
best = pre_text
for next_node, text in self.edges[node]:
attempt = long_path(next_node, pre_text + text)
if len(attempt) > len(best):
best = attempt
return best

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SuffixTree.get_longest_repeat_string refactored with the following changes:

Comment on lines -246 to +245
return append_text+"(M)"
return f"{append_text}(M)"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SuffixTree.shortest_non_substring refactored with the following changes:

nodes = set([0])
nodes = {0}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_trie refactored with the following changes:

matches = []
for i in range(len(text)):
if len(trie.prefix_match(text[i:])) != 0:
matches.append(i)
return matches
return [i for i in range(len(text)) if len(trie.prefix_match(text[i:])) != 0]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function match_text_to_patterns refactored with the following changes:

elif r==0:
graph.set(r,c,0,0)
elif c==0:
elif r == 0 or c == 0:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function fill_graph_smith refactored with the following changes:

Comment on lines -46 to +49
o1 = "-"+o1
o1 = f"-{o1}"
o2 = graph.s2[c-1]+o2
pointer = (r,c-1)
elif p==1:
o1 = graph.s1[r-1]+o1
o2 = "-"+o2
o2 = f"-{o2}"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function trace_pointers_smith refactored with the following changes:

hmm = HMM(symbols, states, transitions, emissions)
return hmm
return HMM(symbols, states, transitions, emissions)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function parse_hmm refactored with the following changes:

Comment on lines -7 to +14
f = open(i,"r")
n = int(f.readline())
txt = f.readlines()
tree = to_tree(string_to_adj_list(txt))
f2 = open(o,"w+")
m = len(tree.nodes[tree.leaves()[0]])
output = small_parsimony(tree,m)
f2.write(f"{output.edgecost()}\n{str(output).strip()}")
f.close()
with open(i,"r") as f:
n = int(f.readline())
txt = f.readlines()
tree = to_tree(string_to_adj_list(txt))
f2 = open(o,"w+")
m = len(tree.nodes[tree.leaves()[0]])
output = small_parsimony(tree,m)
f2.write(f"{output.edgecost()}\n{str(output).strip()}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function q7f refactored with the following changes:

for edge in trie.edges[frm]:
output.append(edge[1])
output.extend(edge[1] for edge in trie.edges[frm])
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function suffix_trie_rosalind refactored with the following changes:

Comment on lines 4 to 5
assert True No newline at end of file
pass
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_actions_working refactored with the following changes:

Comment on lines -5 to +6
f = open('bioinformatics/tests/data/ros_p_adj_list.txt','r')
raw_data = f.readlines()
f.close()
with open('bioinformatics/tests/data/ros_p_adj_list.txt','r') as f:
raw_data = f.readlines()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_binary_tree refactored with the following changes:

Comment on lines -5 to +6
f = open('bioinformatics/tests/data/ros_p_adj_list.txt','r')
raw_data = f.readlines()
f.close()
with open('bioinformatics/tests/data/ros_p_adj_list.txt','r') as f:
raw_data = f.readlines()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_working_translation_for_rosalind_adj refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant