-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Conversation
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)] |
There was a problem hiding this comment.
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:
- Convert for loop into list comprehension (
list-comprehension
)
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 |
There was a problem hiding this comment.
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:
- Merge else clause's nested if statement into elif [×2] (
merge-else-if-into-elif
) - Lift code into else after jump in control flow [×2] (
reintroduce-else
)
if self.root ==None: | ||
if self.root is None: |
There was a problem hiding this comment.
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:
- Use x is None rather than x == None (
none-compare
)
if node==None: | ||
if node is None: |
There was a problem hiding this comment.
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:
- Use x is None rather than x == None (
none-compare
)
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) |
There was a problem hiding this comment.
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:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
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: |
There was a problem hiding this comment.
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:
- Use x is None rather than x == None [×2] (
none-compare
)
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)) |
There was a problem hiding this comment.
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:
- Use str.join() instead of for loop (
use-join
) - Replace unused for index with underscore (
for-index-underscore
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
for ind in range(self.t): | ||
for _ in range(self.t): |
There was a problem hiding this comment.
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:
- Replace unused for index with underscore (
for-index-underscore
)
if len(o) > 0: | ||
if o: |
There was a problem hiding this comment.
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:
- Simplify sequence length comparison (
simplify-len-comparison
)
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] |
There was a problem hiding this comment.
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:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
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)] |
There was a problem hiding this comment.
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:
- Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
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) | ||
) |
There was a problem hiding this comment.
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:
- Replace unused for index with underscore (
for-index-underscore
) - Replace a for append loop with list extend (
for-append-to-extend
)
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)) |
There was a problem hiding this comment.
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:
- Use
with
when opening file to ensure closure [×2] (ensure-file-closed
)
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}" |
There was a problem hiding this comment.
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:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
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 |
There was a problem hiding this comment.
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:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
|
||
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: |
There was a problem hiding this comment.
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:
- Use x is None rather than x == None [×2] (
none-compare
)
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) | ||
) |
There was a problem hiding this comment.
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:
- Use str.join() instead of for loop (
use-join
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
while len(stack) > 0: | ||
while stack: |
There was a problem hiding this comment.
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:
- Simplify sequence length comparison (
simplify-len-comparison
)
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 | ||
|
There was a problem hiding this comment.
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:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
return append_text+"(M)" | ||
return f"{append_text}(M)" |
There was a problem hiding this comment.
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:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
nodes = set([0]) | ||
nodes = {0} |
There was a problem hiding this comment.
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:
- Unwrap a constant iterable constructor (
unwrap-iterable-construction
)
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] |
There was a problem hiding this comment.
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:
- Convert for loop into list comprehension (
list-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
elif r==0: | ||
graph.set(r,c,0,0) | ||
elif c==0: | ||
elif r == 0 or c == 0: |
There was a problem hiding this comment.
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:
- Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Remove redundant conditional (
remove-redundant-if
)
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}" |
There was a problem hiding this comment.
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:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
hmm = HMM(symbols, states, transitions, emissions) | ||
return hmm | ||
return HMM(symbols, states, transitions, emissions) |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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()}") |
There was a problem hiding this comment.
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:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
for edge in trie.edges[frm]: | ||
output.append(edge[1]) | ||
output.extend(edge[1] for edge in trie.edges[frm]) |
There was a problem hiding this comment.
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:
- Replace a for append loop with list extend (
for-append-to-extend
)
assert True No newline at end of file | ||
pass |
There was a problem hiding this comment.
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:
- Remove
assert True
statements (remove-assert-true
)
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() |
There was a problem hiding this comment.
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:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
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() |
There was a problem hiding this comment.
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:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
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: