Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kyclark committed Jan 28, 2021
1 parent b8d45dc commit d2587ba
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 10 deletions.
2 changes: 2 additions & 0 deletions 09_grph/solution1.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ def main() -> None:
filemode='w',
level=logging.DEBUG if args.debug else logging.CRITICAL)

logging.debug('input file = "%s"', args.file.name)

start, end = defaultdict(list), defaultdict(list)
for rec in SeqIO.parse(args.file, 'fasta'):
if kmers := find_kmers(str(rec.seq), args.k):
Expand Down
2 changes: 2 additions & 0 deletions 09_grph/solution2_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ def main() -> None:
filemode='w',
level=logging.DEBUG if args.debug else logging.CRITICAL)

logging.debug('input file = "%s"', args.file.name)

start, end = defaultdict(list), defaultdict(list)
for rec in SeqIO.parse(args.file, 'fasta'):
if kmers := find_kmers(str(rec.seq), args.k):
Expand Down
2 changes: 1 addition & 1 deletion 10_lcsm/solution2_binary_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def binary_search(f: Callable, low: int, high: int) -> int:
if hi and lo:
return high

if not hi and lo:
if lo and not hi:
return binary_search(f, low, mid)

if hi and not lo:
Expand Down
1 change: 1 addition & 0 deletions 11_mprt/solution2_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def test_find_motif() -> None:
assert find_motif('ANXTX') == [1]
assert find_motif('NNTSYS') == [0, 1]
assert find_motif('XNNTSYS') == [1, 2]
assert find_motif('XNNTSYSXNNTSYS') == [1, 2, 8, 9]


# --------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion 13_revp/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def test_snd() -> None:
# --------------------------------------------------
def find_kmers(seq: str, k: int) -> List[str]:
""" Find k-mers in string """

n = len(seq) - k + 1
return [] if n < 1 else [seq[i:i + k] for i in range(n)]

Expand Down
56 changes: 56 additions & 0 deletions 13_revp/solution2_operator_eq_if.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/env python3
""" Locating Restriction Sites """

import argparse
import operator
import sys
from typing import NamedTuple, TextIO
from Bio import SeqIO, Seq
from common import find_kmers


class Args(NamedTuple):
""" Command-line arguments """
file: TextIO


# --------------------------------------------------
def get_args() -> Args:
""" Get command-line arguments """

parser = argparse.ArgumentParser(
description='Locating Restriction Sites',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument('file',
help='Input FASTA file',
metavar='FILE',
type=argparse.FileType('rt'))

args = parser.parse_args()

return Args(args.file)


# --------------------------------------------------
def main() -> None:
""" Make a jazz noise here """

args = get_args()
if seqs := [str(rec.seq) for rec in SeqIO.parse(args.file, 'fasta')]:
seq = seqs[0]

for k in range(4, 13):
kmers = find_kmers(seq, k)
revc = list(map(Seq.reverse_complement, kmers))

for pos, pair in enumerate(zip(kmers, revc)):
if operator.eq(*pair):
print(pos + 1, k)
else:
sys.exit(f'"{args.file.name}" contains no sequences.')


# --------------------------------------------------
if __name__ == '__main__':
main()
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ def main() -> None:
if seqs := [str(rec.seq) for rec in SeqIO.parse(args.file, 'fasta')]:
seq = seqs[0]

# for k in range(4, 13):
# kmers = find_kmers(seq, k)
# revc = list(map(Seq.reverse_complement, kmers))

# for pos, pair in enumerate(zip(kmers, revc)):
# if operator.eq(*pair):
# print(pos + 1, k)

for k in range(4, 13):
kmers = find_kmers(seq, k)
revc = map(Seq.reverse_complement, kmers)
Expand Down

0 comments on commit d2587ba

Please sign in to comment.