Commit 1fa761af authored by Laros's avatar Laros
Browse files

Added a test function which tests a list of barcodes.

Fixed a dependency.

Renamed the makebc command to make.
parent 82e8f875
...@@ -22,7 +22,7 @@ Licensed under the MIT license, see the LICENSE file. ...@@ -22,7 +22,7 @@ Licensed under the MIT license, see the LICENSE file.
RELEASE = False RELEASE = False
__version_info__ = ('0', '1', 'dev') __version_info__ = ('0', '3', 'dev')
__version__ = '.'.join(__version_info__) __version__ = '.'.join(__version_info__)
......
...@@ -137,6 +137,21 @@ def barcode(length, max_stretch, min_dist): ...@@ -137,6 +137,21 @@ def barcode(length, max_stretch, min_dist):
min_dist) min_dist)
#barcode #barcode
def testBarcodes(barcodes, min_dist):
"""
Test a set of barcodes.
@arg barcodes: List of barcodes.
@type barcodes: list[str]
@arg min_dist: Minimum distance between the barcodes.
@type min_dist: int
@returns: The number of barcodes that violate the distance constraint.
@rtype: int
"""
return len(barcodes) - len(filterDistance(barcodes, min_dist))
#testBarcodes
def main(): def main():
""" """
Main entry point. Main entry point.
...@@ -144,6 +159,12 @@ def main(): ...@@ -144,6 +159,12 @@ def main():
output_parser = argparse.ArgumentParser(add_help=False) output_parser = argparse.ArgumentParser(add_help=False)
output_parser.add_argument("OUTPUT", type=argparse.FileType('w'), output_parser.add_argument("OUTPUT", type=argparse.FileType('w'),
help="output file") help="output file")
input_parser = argparse.ArgumentParser(add_help=False)
input_parser.add_argument("INPUT", type=argparse.FileType('r'),
help="input file")
distance_parser = argparse.ArgumentParser(add_help=False)
distance_parser.add_argument("-d", dest="distance", type=int, default=3,
help="minimum distance between the barcodes")
usage = __doc__.split("\n\n\n") usage = __doc__.split("\n\n\n")
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
...@@ -151,20 +172,25 @@ def main(): ...@@ -151,20 +172,25 @@ def main():
description=usage[0], epilog=usage[1]) description=usage[0], epilog=usage[1])
subparsers = parser.add_subparsers(dest="subcommand") subparsers = parser.add_subparsers(dest="subcommand")
parser_makebc = subparsers.add_parser("makebc", parser_make = subparsers.add_parser("make", parents=[output_parser,
parents=[output_parser], description=docSplit(barcode)) distance_parser], description=docSplit(barcode))
parser_makebc.add_argument("-l", dest="length", type=int, default=8, parser_make.add_argument("-l", dest="length", type=int, default=8,
help="lenght of the barcodes") help="lenght of the barcodes")
parser_makebc.add_argument("-s", dest="stretch", type=int, default=2, parser_make.add_argument("-s", dest="stretch", type=int, default=2,
help="maximum mononucleotide stretch length") help="maximum mononucleotide stretch length")
parser_makebc.add_argument("-d", dest="distance", type=int, default=3,
help="minimum distance between the barcodes") parser_test = subparsers.add_parser("test", parents=[input_parser,
distance_parser], description=docSplit(testBarcodes))
args = parser.parse_args() args = parser.parse_args()
if args.subcommand == "makebc": if args.subcommand == "make":
args.OUTPUT.write("\n".join(barcode(args.length, args.stretch, args.OUTPUT.write("\n".join(barcode(args.length, args.stretch,
args.distance))) args.distance)))
if args.subcommand == "test":
print "%s barcodes violate the distance contraint." % testBarcodes(
map(lambda x: x.strip(), args.INPUT.readlines()), args.distance)
#main #main
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -5,7 +5,7 @@ if sys.version_info < (2, 6): ...@@ -5,7 +5,7 @@ if sys.version_info < (2, 6):
raise Exception('barcode requires Python 2.6 or higher.') raise Exception('barcode requires Python 2.6 or higher.')
# Todo: How does this play with pip freeze requirement files? # Todo: How does this play with pip freeze requirement files?
requires = ['Levenshtein'] requires = ['python-Levenshtein']
# Python 2.6 does not include the argparse module. # Python 2.6 does not include the argparse module.
try: try:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment