Skip to content

Commit

Permalink
revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
kyclark committed Feb 4, 2021
1 parent 3e85e4b commit 30afd42
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 6 deletions.
18 changes: 14 additions & 4 deletions 01_dna/tests/dna_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
import platform
from subprocess import getstatusoutput, getoutput
from subprocess import getstatusoutput

PRG = './dna.py'
RUN = f'python {PRG}' if platform.system() == 'Windows' else PRG
Expand All @@ -20,13 +20,23 @@ def test_exists() -> None:

# --------------------------------------------------
def test_usage() -> None:
""" Prints usage with no args or for help """
""" Prints usage """

for arg in ['', '-h', '--help']:
out = getoutput(f'{RUN} {arg}')
for arg in ['-h', '--help']:
rv, out = getstatusoutput(f'{RUN} {arg}')
assert rv == 0
assert out.lower().startswith('usage:')


# --------------------------------------------------
def test_dies_no_args() -> None:
""" Dies with no arguments """

rv, out = getstatusoutput(RUN)
assert rv != 0
assert out.lower().startswith('usage:')


# --------------------------------------------------
def test_arg() -> None:
""" Uses command-line arg """
Expand Down
3 changes: 3 additions & 0 deletions 05_gc/solution1_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
""" Compute GC content """

import argparse
import sys
from typing import NamedTuple, TextIO, List, Tuple
from Bio import SeqIO

Expand All @@ -22,6 +23,8 @@ def get_args() -> Args:
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='?',
default=sys.stdin,
help='Input sequence file')

args = parser.parse_args()
Expand Down
3 changes: 3 additions & 0 deletions 05_gc/solution2_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
""" Compute GC content """

import argparse
import sys
from typing import NamedTuple, TextIO, List
from Bio import SeqIO

Expand All @@ -28,6 +29,8 @@ def get_args() -> Args:
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='?',
default=sys.stdin,
help='Input sequence file')

args = parser.parse_args()
Expand Down
3 changes: 3 additions & 0 deletions 05_gc/solution3_max_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
""" Compute GC content """

import argparse
import sys
from typing import NamedTuple, TextIO
from Bio import SeqIO

Expand All @@ -28,6 +29,8 @@ def get_args() -> Args:
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='?',
default=sys.stdin,
help='Input sequence file')

args = parser.parse_args()
Expand Down
3 changes: 3 additions & 0 deletions 05_gc/solution4_list_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
""" Compute GC content """

import argparse
import sys
from typing import NamedTuple, TextIO
from Bio import SeqIO

Expand All @@ -28,6 +29,8 @@ def get_args() -> Args:
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='?',
default=sys.stdin,
help='Input sequence file')

args = parser.parse_args()
Expand Down
3 changes: 3 additions & 0 deletions 05_gc/solution5_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
""" Compute GC content """

import argparse
import sys
from typing import NamedTuple, TextIO
from Bio import SeqIO

Expand All @@ -28,6 +29,8 @@ def get_args() -> Args:
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='?',
default=sys.stdin,
help='Input sequence file')

args = parser.parse_args()
Expand Down
3 changes: 3 additions & 0 deletions 05_gc/solution6_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
""" Compute GC content """

import argparse
import sys
from typing import NamedTuple, TextIO
from Bio import SeqIO

Expand All @@ -28,6 +29,8 @@ def get_args() -> Args:
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='?',
default=sys.stdin,
help='Input sequence file')

args = parser.parse_args()
Expand Down
3 changes: 3 additions & 0 deletions 05_gc/solution7_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import argparse
import re
import sys
from typing import NamedTuple, TextIO
from Bio import SeqIO

Expand All @@ -29,6 +30,8 @@ def get_args() -> Args:
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='?',
default=sys.stdin,
help='Input sequence file')

args = parser.parse_args()
Expand Down
3 changes: 3 additions & 0 deletions 05_gc/solution8_list_comp_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import argparse
import re
import sys
from typing import NamedTuple, TextIO
from Bio import SeqIO
from Bio.Seq import Seq
Expand Down Expand Up @@ -31,6 +32,8 @@ def get_args() -> Args:
parser.add_argument('file',
metavar='FILE',
type=argparse.FileType('rt'),
nargs='?',
default=sys.stdin,
help='Input sequence file')

args = parser.parse_args()
Expand Down
9 changes: 9 additions & 0 deletions 05_gc/tests/cgc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ def test_good_input2() -> None:
assert out == 'Rosalind_5723 52.806415'


# --------------------------------------------------
def test_stdin() -> None:
""" Works on STDIN """

rv, out = getstatusoutput(f'cat {SAMPLE1} | {RUN}')
assert rv == 0
assert out == 'Rosalind_0808 60.919540'


# --------------------------------------------------
def random_string() -> str:
""" Generate a random string """
Expand Down
6 changes: 4 additions & 2 deletions 18_fastx_sampler/sampler_dir_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import random
import gzip
from pathlib import Path
from Bio import SeqIO
from typing import List, NamedTuple, Optional

Expand All @@ -27,7 +28,8 @@ def get_args() -> Args:
description='Probabalistically subset FASTA files',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

parser.add_argument('dir',
parser.add_argument('-d',
'--dir',
metavar='DIR',
type=str,
nargs='+',
Expand Down Expand Up @@ -80,7 +82,7 @@ def get_args() -> Args:
files = []
for dirname in args.dir:
if os.path.isdir(dirname):
filenames.extend(list(Path(dirname).rglob('*')))
files.extend(list(Path(dirname).rglob('*')))

if not files:
parser.error('Found no files')
Expand Down

0 comments on commit 30afd42

Please sign in to comment.