[med-svn] [python-pymummer] 01/02: Imported Upstream version 0.6.1

Afif Elghraoui afif-guest at moszumanska.debian.org
Fri Nov 13 07:22:17 UTC 2015


This is an automated email from the git hooks/post-receive script.

afif-guest pushed a commit to branch master
in repository python-pymummer.

commit 0b264e1a24bfd20a8273a5a033bed4b454a0b870
Author: Afif Elghraoui <afif at ghraoui.name>
Date:   Thu Nov 12 22:38:01 2015 -0800

    Imported Upstream version 0.6.1
---
 .gitignore                                         |  54 ++
 .travis.yml                                        |  17 +
 AUTHORS                                            |   2 +
 LICENSE                                            | 675 +++++++++++++++++++++
 README.md                                          |  81 +++
 install_dependencies.sh                            |  69 +++
 pymummer/__init__.py                               |  11 +
 pymummer/alignment.py                              | 136 +++++
 pymummer/coords_file.py                            |  47 ++
 pymummer/nucmer.py                                 | 132 ++++
 pymummer/snp.py                                    |  38 ++
 pymummer/snp_file.py                               |  24 +
 pymummer/syscall.py                                |  30 +
 pymummer/tests/alignment_test.py                   | 131 ++++
 pymummer/tests/coords_file_test.py                 |  51 ++
 .../coords_file_test_convert_to_msp_crunch.coords  |   7 +
 ...ile_test_convert_to_msp_crunch.no_offset.crunch |   3 +
 .../coords_file_test_convert_to_msp_crunch.qry.fa  |  24 +
 ...ords_file_test_convert_to_msp_crunch.qry.fa.fai |   3 +
 .../coords_file_test_convert_to_msp_crunch.ref.fa  |  27 +
 ...ords_file_test_convert_to_msp_crunch.ref.fa.fai |   3 +
 ...e_test_convert_to_msp_crunch.with_offset.crunch |   3 +
 .../tests/data/coords_file_test_no_header.coords   |   3 +
 .../tests/data/coords_file_test_with_header.coords |   7 +
 pymummer/tests/data/nucmer_test_out.coords         |   1 +
 pymummer/tests/data/nucmer_test_out.coords.snps    |   2 +
 pymummer/tests/data/nucmer_test_qry.fa             |  15 +
 pymummer/tests/data/nucmer_test_ref.fa             |  18 +
 .../tests/data/nucmer_test_write_script_no_snps.sh |   3 +
 .../data/nucmer_test_write_script_with_snps.sh     |   4 +
 .../tests/data/snp_file_test_get_all_variants.snps |   8 +
 pymummer/tests/data/snp_file_test_no_header.snps   |   3 +
 pymummer/tests/data/snp_file_test_with_header.snps |   7 +
 pymummer/tests/nucmer_test.py                      |  97 +++
 pymummer/tests/snp_file_test.py                    |  58 ++
 pymummer/tests/snp_test.py                         |  17 +
 pymummer/tests/syscall_test.py                     |  16 +
 pymummer/tests/variant_test.py                     | 103 ++++
 pymummer/variant.py                                |  82 +++
 setup.py                                           |  45 ++
 40 files changed, 2057 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..db4561e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,54 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.cache
+nosetests.xml
+coverage.xml
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..b33c035
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,17 @@
+language: python
+addons:
+  apt:
+    packages:
+    - g++
+    - python-dev
+cache:
+  directories:
+  - "build"
+  - "$HOME/.cache/pip"
+python:
+  - "3.3"
+  - "3.4"
+sudo: false
+install:
+  - "source ./install_dependencies.sh"
+script: "python setup.py test"
diff --git a/AUTHORS b/AUTHORS
new file mode 100644
index 0000000..dcb15cd
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,2 @@
+Martin Hunt (path-help at sanger.ac.uk)
+Nishadi De Silva (path-help at sanger.ac.uk)
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..6b156fe
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,675 @@
+GNU GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+  The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works.  By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users.  We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors.  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+  To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights.  Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received.  You must make sure that they, too, receive
+or can get the source code.  And you must show them these terms so they
+know their rights.
+
+  Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+  For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software.  For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+  Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so.  This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software.  The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable.  Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products.  If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+  Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary.  To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                       TERMS AND CONDITIONS
+
+  0. Definitions.
+
+  "This License" refers to version 3 of the GNU General Public License.
+
+  "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+  "The Program" refers to any copyrightable work licensed under this
+License.  Each licensee is addressed as "you".  "Licensees" and
+"recipients" may be individuals or organizations.
+
+  To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy.  The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+  A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+  To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy.  Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+  To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies.  Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+  An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License.  If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+  1. Source Code.
+
+  The "source code" for a work means the preferred form of the work
+for making modifications to it.  "Object code" means any non-source
+form of a work.
+
+  A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+  The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form.  A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+  The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities.  However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work.  For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+  The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+  The Corresponding Source for a work in source code form is that
+same work.
+
+  2. Basic Permissions.
+
+  All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met.  This License explicitly affirms your unlimited
+permission to run the unmodified Program.  The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work.  This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+  You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force.  You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright.  Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+  Conveying under any other circumstances is permitted solely under
+the conditions stated below.  Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+  3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+  No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+  When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+  4. Conveying Verbatim Copies.
+
+  You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+  You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+  5. Conveying Modified Source Versions.
+
+  You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+    a) The work must carry prominent notices stating that you modified
+    it, and giving a relevant date.
+
+    b) The work must carry prominent notices stating that it is
+    released under this License and any conditions added under section
+    7.  This requirement modifies the requirement in section 4 to
+    "keep intact all notices".
+
+    c) You must license the entire work, as a whole, under this
+    License to anyone who comes into possession of a copy.  This
+    License will therefore apply, along with any applicable section 7
+    additional terms, to the whole of the work, and all its parts,
+    regardless of how they are packaged.  This License gives no
+    permission to license the work in any other way, but it does not
+    invalidate such permission if you have separately received it.
+
+    d) If the work has interactive user interfaces, each must display
+    Appropriate Legal Notices; however, if the Program has interactive
+    interfaces that do not display Appropriate Legal Notices, your
+    work need not make them do so.
+
+  A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit.  Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+  6. Conveying Non-Source Forms.
+
+  You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+    a) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by the
+    Corresponding Source fixed on a durable physical medium
+    customarily used for software interchange.
+
+    b) Convey the object code in, or embodied in, a physical product
+    (including a physical distribution medium), accompanied by a
+    written offer, valid for at least three years and valid for as
+    long as you offer spare parts or customer support for that product
+    model, to give anyone who possesses the object code either (1) a
+    copy of the Corresponding Source for all the software in the
+    product that is covered by this License, on a durable physical
+    medium customarily used for software interchange, for a price no
+    more than your reasonable cost of physically performing this
+    conveying of source, or (2) access to copy the
+    Corresponding Source from a network server at no charge.
+
+    c) Convey individual copies of the object code with a copy of the
+    written offer to provide the Corresponding Source.  This
+    alternative is allowed only occasionally and noncommercially, and
+    only if you received the object code with such an offer, in accord
+    with subsection 6b.
+
+    d) Convey the object code by offering access from a designated
+    place (gratis or for a charge), and offer equivalent access to the
+    Corresponding Source in the same way through the same place at no
+    further charge.  You need not require recipients to copy the
+    Corresponding Source along with the object code.  If the place to
+    copy the object code is a network server, the Corresponding Source
+    may be on a different server (operated by you or a third party)
+    that supports equivalent copying facilities, provided you maintain
+    clear directions next to the object code saying where to find the
+    Corresponding Source.  Regardless of what server hosts the
+    Corresponding Source, you remain obligated to ensure that it is
+    available for as long as needed to satisfy these requirements.
+
+    e) Convey the object code using peer-to-peer transmission, provided
+    you inform other peers where the object code and Corresponding
+    Source of the work are being offered to the general public at no
+    charge under subsection 6d.
+
+  A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+  A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling.  In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage.  For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product.  A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+  "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source.  The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+  If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information.  But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+  The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed.  Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+  Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+  7. Additional Terms.
+
+  "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law.  If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+  When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it.  (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.)  You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+  Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+    a) Disclaiming warranty or limiting liability differently from the
+    terms of sections 15 and 16 of this License; or
+
+    b) Requiring preservation of specified reasonable legal notices or
+    author attributions in that material or in the Appropriate Legal
+    Notices displayed by works containing it; or
+
+    c) Prohibiting misrepresentation of the origin of that material, or
+    requiring that modified versions of such material be marked in
+    reasonable ways as different from the original version; or
+
+    d) Limiting the use for publicity purposes of names of licensors or
+    authors of the material; or
+
+    e) Declining to grant rights under trademark law for use of some
+    trade names, trademarks, or service marks; or
+
+    f) Requiring indemnification of licensors and authors of that
+    material by anyone who conveys the material (or modified versions of
+    it) with contractual assumptions of liability to the recipient, for
+    any liability that these contractual assumptions directly impose on
+    those licensors and authors.
+
+  All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10.  If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term.  If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+  If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+  Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+  8. Termination.
+
+  You may not propagate or modify a covered work except as expressly
+provided under this License.  Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+  However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+  Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+  Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License.  If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+  9. Acceptance Not Required for Having Copies.
+
+  You are not required to accept this License in order to receive or
+run a copy of the Program.  Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance.  However,
+nothing other than this License grants you permission to propagate or
+modify any covered work.  These actions infringe copyright if you do
+not accept this License.  Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+  10. Automatic Licensing of Downstream Recipients.
+
+  Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License.  You are not responsible
+for enforcing compliance by third parties with this License.
+
+  An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations.  If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+  You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License.  For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+  11. Patents.
+
+  A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based.  The
+work thus licensed is called the contributor's "contributor version".
+
+  A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version.  For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+  Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+  In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement).  To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+  If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients.  "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+  If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+  A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License.  You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+  Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+  12. No Surrender of Others' Freedom.
+
+  If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all.  For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+  13. Use with the GNU Affero General Public License.
+
+  Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work.  The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+  14. Revised Versions of this License.
+
+  The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+  Each version is given a distinguishing version number.  If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation.  If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+  If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+  Later license versions may give you additional or different
+permissions.  However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+  15. Disclaimer of Warranty.
+
+  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+  16. Limitation of Liability.
+
+  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+  17. Interpretation of Sections 15 and 16.
+
+  If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    {one line to give the program's name and a brief idea of what it does.}
+    Copyright (C) {year}  {name of author}
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+Also add information on how to contact you by electronic and paper mail.
+
+  If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+    {project}  Copyright (C) {year}  {fullname}
+    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+  You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+<http://www.gnu.org/licenses/>.
+
+  The GNU General Public License does not permit incorporating your program
+into proprietary programs.  If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.  But first, please read
+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5bd7dce
--- /dev/null
+++ b/README.md
@@ -0,0 +1,81 @@
+pymummer
+========
+
+Python3 wrapper for running MUMmer and parsing the output. 
+
+[![Build Status](https://travis-ci.org/sanger-pathogens/pymummer.svg?branch=master)](https://travis-ci.org/sanger-pathogens/pymummer)
+
+Installation
+------------
+
+###Homebrew/LinuxBrew###
+```
+brew tap homebrew/python
+brew install pymummer
+```
+
+##Pip
+###Pre-requisites###
+
+The MUMmer package must be installed.
+Instructions to install MUMmer can be found [here](http://mummer.sourceforge.net/manual/#installation)
+		
+###Installation###
+
+Install with
+
+    pip3 install pymummer
+
+
+Usage (for developers)
+----------------------
+
+Example showing how pymummer can be used to run nucmer on a fasta file and parse the output file to produce a set of alignment objects:
+
+	from pymummer import coords_file, alignment, nucmer
+	...
+	runner = nucmer.Runner(reference_file, query_file, results_file) 
+	runner.run()
+	file_reader = coords_file.reader(results_file)
+	alignments = [coord for coord in file_reader if not coord.is_self_hit()] #Remove self hits
+	...
+
+###pymummer nucmer class###
+
+Wraps the `nucmer`, `delta-filter`, `show-coords` and `show-snps` commands. 
+
+Arguments:
+
+__ref__			reference file  
+__query__			query file  
+__outfile__		output file  
+__min\_id__		min\_id for delta-filter command (default None)  
+__min\_length__	min\_length for delta-filter command (default None)  
+__breaklen__		breaklen for nucmer command (nucmer's default is 200)   
+__coords\_header__	print header in show-coords output (default True)  
+__maxmatch__		maxmatch for nucmer (default False)  
+__show\_snps__		run show-snps (default False)  
+__snps\_header__ 	print header in show-snps output (default True)  
+
+###pymummer promer class###
+
+[TODO]
+
+###pymummer coords_file class###
+
+Parses the nucmer output and populate an alignment object for each hit in the output
+
+  
+###pymummer alignment class###
+
+Check attributes of a hit, swap the reference and query, check if it's a self hit and so on
+
+Contact
+-------
+
+Authors: Martin Hunt, Nishadi De Silva
+
+Affiliation: Wellcome Trust Sanger Institute, Hinxton, UK
+
+Email: path-help at sanger.ac.uk
+      
diff --git a/install_dependencies.sh b/install_dependencies.sh
new file mode 100644
index 0000000..35a464b
--- /dev/null
+++ b/install_dependencies.sh
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+set -x
+set -e
+
+start_dir=$(pwd)
+
+MUMMER_VERSION="3.23"
+
+MUMMER_DOWNLOAD_URL="http://sourceforge.net/projects/mummer/files/mummer/${MUMMER_VERSION}/MUMmer${MUMMER_VERSION}.tar.gz/download"
+
+# Make an install location
+if [ ! -d 'build' ]; then
+  mkdir build
+fi
+cd build
+build_dir=$(pwd)
+
+# DOWNLOAD ALL THE THINGS
+download () {
+  url=$1
+  download_location=$2
+
+  if [ -e $download_location ]; then
+    echo "Skipping download of $url, $download_location already exists"
+  else
+    echo "Downloading $url to $download_location"
+    wget $url -O $download_location
+  fi
+}
+
+download $MUMMER_DOWNLOAD_URL "mummer-${MUMMER_VERSION}.tgz"
+
+# Build all the things
+cd $build_dir
+
+## Mummer
+mummer_dir=$(pwd)/MUMmer${MUMMER_VERSION}
+if [ ! -d $mummer_dir ]; then
+  tar xzf mummer-${MUMMER_VERSION}.tgz
+fi
+cd $mummer_dir
+if [ -e "${mummer_dir}/mummer" ]; then
+  echo "Already built Mummer; skipping build"
+else
+  make check
+  make
+  cd ./src/tigr 
+  make
+fi
+
+cd $build_dir
+
+# Setup environment variables
+update_path () {
+  new_dir=$1
+  export PATH=${PATH:-$new_dir}
+  if [[ ! "$PATH" =~ (^|:)"${new_dir}"(:|$) ]]; then
+    export PATH=${new_dir}:${PATH}
+  fi
+}
+
+update_path ${mummer_dir}
+update_path ${mummer_dir}/src/tigr
+
+cd $start_dir
+
+set +x
+set +e
diff --git a/pymummer/__init__.py b/pymummer/__init__.py
new file mode 100644
index 0000000..fe82375
--- /dev/null
+++ b/pymummer/__init__.py
@@ -0,0 +1,11 @@
+__all__ = [
+    'alignment',
+    'coords_file',
+    'nucmer',
+    'snp',
+    'snp_file',
+    'syscall',
+    'variant',
+]
+
+from pymummer import *
diff --git a/pymummer/alignment.py b/pymummer/alignment.py
new file mode 100644
index 0000000..1e73250
--- /dev/null
+++ b/pymummer/alignment.py
@@ -0,0 +1,136 @@
+import pyfastaq
+
+class Error (Exception): pass
+
+class Alignment:
+    def __init__(self, line):
+        '''Constructs Alignment object from a line of show-coords -dTlro'''
+        # nucmer:
+        # [S1]  [E1]    [S2]    [E2]    [LEN 1] [LEN 2] [% IDY] [LEN R] [LEN Q] [FRM]   [TAGS]
+        #1162    25768   24536   4   24607   24533   99.32   640851  24536   1   -1  ref qry   [CONTAINS]
+
+        # promer:
+        #[S1]    [E1]    [S2]    [E2]    [LEN 1] [LEN 2] [% IDY] [% SIM] [% STP] [LEN R] [LEN Q] [FRM]   [TAGS]
+        # 1   1398    4891054 4892445 1398    1392    89.55   93.18   0.21    1398    5349013 1   1   ref qry    [CONTAINED]
+
+        fields = line.rstrip().split('\t')
+
+        try:
+            self.ref_start = int(fields[0]) - 1
+            self.ref_end = int(fields[1]) - 1
+            self.qry_start = int(fields[2]) - 1
+            self.qry_end = int(fields[3]) - 1
+            self.hit_length_ref = int(fields[4])
+            self.hit_length_qry = int(fields[5])
+            self.percent_identity = float(fields[6])
+
+            if len(fields) >= 15:  # promer has more fields
+                self.ref_length = int(fields[9])
+                self.qry_length = int(fields[10])
+                self.frame = int(fields[11])
+                self.ref_name = fields[13]
+                self.qry_name = fields[14]
+            else:
+                self.ref_length = int(fields[7])
+                self.qry_length = int(fields[8])
+                self.frame = int(fields[9])
+                self.ref_name = fields[11]
+                self.qry_name = fields[12]
+        except:
+            raise Error('Error reading this nucmer line:\n' + line)
+
+
+    def __eq__(self, other):
+        return type(other) is type(self) and self.__dict__ == other.__dict__
+
+
+    def __hash__(self):
+        return hash((self.ref_start, self.ref_end, self.qry_start, self.qry_end, self.hit_length_ref, self.hit_length_qry, self.percent_identity, self.ref_length, self.qry_length, self.frame, self.ref_name, self.qry_name))
+
+
+    def _swap(self):
+        '''Swaps the alignment so that the reference becomes the query and vice-versa. Swaps their names, coordinates etc. The frame is not changed'''
+        self.ref_start, self.qry_start = self.qry_start, self.ref_start
+        self.ref_end, self.qry_end = self.qry_end, self.ref_end
+        self.hit_length_ref, self.hit_length_qry = self.hit_length_qry, self.hit_length_ref
+        self.ref_length, self.qry_length = self.qry_length, self.ref_length
+        self.ref_name, self.qry_name = self.qry_name, self.ref_name
+
+
+    def qry_coords(self):
+        '''Returns a pyfastaq.intervals.Interval object of the start and end coordinates in the query sequence'''
+        return pyfastaq.intervals.Interval(min(self.qry_start, self.qry_end), max(self.qry_start, self.qry_end))
+
+
+    def ref_coords(self):
+        '''Returns a pyfastaq.intervals.Interval object of the start and end coordinates in the reference sequence'''
+        return pyfastaq.intervals.Interval(min(self.ref_start, self.ref_end), max(self.ref_start, self.ref_end))
+
+
+    def on_same_strand(self):
+        '''Returns true iff the direction of the alignment is the same in the reference and the query'''
+        return (self.ref_start < self.ref_end) == (self.qry_start < self.qry_end)
+
+
+    def is_self_hit(self):
+        '''Returns true iff the alignment is of a sequence to itself: names and all coordinates are the same and 100 percent identity'''
+        return self.ref_name == self.qry_name \
+                and self.ref_start == self.qry_start \
+                and self.ref_end == self.qry_end \
+                and self.percent_identity == 100
+
+
+    def reverse_query(self):
+        '''Changes the coordinates as if the query sequence has been reverse complemented'''
+        self.qry_start = self.qry_length - self.qry_start - 1
+        self.qry_end = self.qry_length - self.qry_end - 1
+
+
+    def reverse_reference(self):
+        '''Changes the coordinates as if the reference sequence has been reverse complemented'''
+        self.ref_start = self.ref_length - self.ref_start - 1
+        self.ref_end = self.ref_length - self.ref_end - 1
+
+
+    def __str__(self):
+        '''Returns a tab delimited string containing the values of this alignment object'''
+        return '\t'.join(str(x) for x in
+            [self.ref_start + 1,
+            self.ref_end + 1,
+            self.qry_start + 1,
+            self.qry_end + 1,
+            self.hit_length_ref,
+            self.hit_length_qry,
+            '{0:.2f}'.format(self.percent_identity),
+            self.ref_length,
+            self.qry_length,
+            self.frame,
+            self.ref_name,
+            self.qry_name])
+
+
+    def to_msp_crunch(self):
+        '''Returns the alignment as a line in MSPcrunch format. The columns are space-separated and are:
+           1. score
+           2. percent identity
+           3. match start in the query sequence
+           4. match end in the query sequence
+           5. query sequence name
+           6. subject sequence start
+           7. subject sequence end
+           8. subject sequence name'''
+
+        # we don't know the alignment score. Estimate it. This approximates 1 for a match.
+        aln_score = int(self.percent_identity * 0.005 * (self.hit_length_ref + self.hit_length_qry))
+
+        return ' '.join(str(x) for x in [
+                aln_score,
+                '{0:.2f}'.format(self.percent_identity),
+                self.qry_start + 1,
+                self.qry_end + 1,
+                self.qry_name,
+                self.ref_start + 1,
+                self.ref_end + 1,
+                self.ref_name
+        ])
+
diff --git a/pymummer/coords_file.py b/pymummer/coords_file.py
new file mode 100644
index 0000000..27b09c9
--- /dev/null
+++ b/pymummer/coords_file.py
@@ -0,0 +1,47 @@
+import pyfastaq
+from pymummer import alignment
+
+class Error (Exception): pass
+
+def reader(fname):
+    '''Helper function to open the results file (coords file) and create alignment objects with the values in it'''
+    f = pyfastaq.utils.open_file_read(fname)
+
+    for line in f:
+        if line.startswith('[') or (not '\t' in line):
+            continue
+
+        yield alignment.Alignment(line)
+
+    pyfastaq.utils.close(f)
+
+
+def convert_to_msp_crunch(infile, outfile, ref_fai=None, qry_fai=None):
+    '''Converts a coords file to a file in MSPcrunch format (for use with ACT, most likely).
+       ACT ignores sequence names in the crunch file, and just looks at the numbers.
+       To make a compatible file, the coords all must be shifted appropriately, which
+       can be done by providing both the ref_fai and qry_fai options.
+       Both or neither of these must be used, otherwise an error will be thrown.'''
+    fai_files = {ref_fai, qry_fai}
+    if None in fai_files and len(fai_files) != 1:
+       print(fai_files)
+       raise Error('Error in convert_to_msp_crunch. Must use both of ref_fai and qry_fai, or neither of them')
+
+    if ref_fai is not None:
+        assert qry_fai is not None
+        ref_offsets = pyfastaq.tasks.length_offsets_from_fai(ref_fai)
+        qry_offsets = pyfastaq.tasks.length_offsets_from_fai(qry_fai)
+    
+    file_reader = reader(infile)
+    f_out = pyfastaq.utils.open_file_write(outfile)
+
+    for aln in file_reader:
+        if ref_fai is not None:
+           aln.ref_start += ref_offsets[aln.ref_name] 
+           aln.ref_end += ref_offsets[aln.ref_name] 
+           aln.qry_start += qry_offsets[aln.qry_name] 
+           aln.qry_end += qry_offsets[aln.qry_name] 
+
+        print(aln.to_msp_crunch(), file=f_out)
+
+    pyfastaq.utils.close(f_out)
diff --git a/pymummer/nucmer.py b/pymummer/nucmer.py
new file mode 100644
index 0000000..a802ab0
--- /dev/null
+++ b/pymummer/nucmer.py
@@ -0,0 +1,132 @@
+import os
+import tempfile
+import shutil
+import pyfastaq
+from pymummer import syscall
+
+class Error (Exception): pass
+
+
+class Runner:
+    '''Handy reference for all the arguments needed for nucmer, delta-filter, show-coords, show-snps'''
+    def __init__(
+      self,
+      ref,
+      query,
+      outfile,
+      min_id=None,
+      min_length=None,
+      breaklen=None,
+      coords_header=True,
+      diagdiff=None,
+      maxmatch=False,
+      simplify=True,
+      show_snps=False,
+      snps_header=True,
+      verbose=False,
+      promer=False,
+   ):
+        self.qry = query
+        self.ref = ref
+        self.outfile = outfile
+        self.min_id = min_id
+        self.min_length = min_length
+        self.breaklen = breaklen
+        self.diagdiff = diagdiff
+        self.coords_header = coords_header
+        self.maxmatch = maxmatch
+        self.simplify = simplify
+        self.show_snps = show_snps
+        self.snps_header = snps_header
+        self.verbose = verbose
+        self.use_promer = promer
+    
+
+
+    def _nucmer_command(self, ref, qry, outprefix):
+        '''Construct the nucmer command'''
+        if self.use_promer:
+            command = 'promer'
+        else:
+            command = 'nucmer'
+  
+        command += ' -p ' + outprefix
+
+        if self.breaklen is not None:
+            command += ' -b ' + str(self.breaklen)
+
+        if self.diagdiff is not None and not self.use_promer:
+            command += ' -D ' + str(self.diagdiff)
+
+        if self.maxmatch:
+            command += ' --maxmatch'
+            
+        if not self.simplify and not self.use_promer:
+        	command += ' --nosimplify'
+
+        return command + ' ' + ref + ' ' + qry
+
+
+
+    def _delta_filter_command(self, infile, outfile):
+        '''Construct delta-filter command'''
+        command = 'delta-filter'
+
+        if self.min_id is not None:
+            command += ' -i ' + str(self.min_id)
+
+        if self.min_length is not None:
+            command += ' -l ' + str(self.min_length)
+
+        return command + ' ' + infile + ' > ' + outfile
+        
+
+    def _show_coords_command(self, infile, outfile):
+        '''Construct show-coords command'''
+        command = 'show-coords -dTlro'
+
+        if not self.coords_header:
+            command += ' -H'
+
+        return command + ' ' + infile + ' > ' + outfile
+
+
+    def _show_snps_command(self, infile, outfile):
+        command = 'show-snps -TClr'
+
+        if not self.snps_header:
+            command += ' -H'
+
+        return command + ' ' + infile + ' > ' + outfile
+
+
+    def _write_script(self, script_name, ref, qry, outfile):
+        '''Write commands into a bash script'''
+        f = pyfastaq.utils.open_file_write(script_name)
+        print(self._nucmer_command(ref, qry, 'p'), file=f)
+        print(self._delta_filter_command('p.delta', 'p.delta.filter'), file=f)
+        print(self._show_coords_command('p.delta.filter', outfile), file=f)
+        if self.show_snps:
+            print(self._show_snps_command('p.delta.filter', outfile + '.snps'), file=f)
+        pyfastaq.utils.close(f)
+    
+
+    def run(self):
+        '''
+        Change to a temp directory
+        Run bash script containing commands
+        Place results in specified output file
+        Clean up temp directory
+        '''
+        qry = os.path.abspath(self.qry)
+        ref = os.path.abspath(self.ref)
+        outfile = os.path.abspath(self.outfile)
+        tmpdir = tempfile.mkdtemp(prefix='tmp.run_nucmer.', dir=os.getcwd())
+        original_dir = os.getcwd()
+        os.chdir(tmpdir)
+        script = 'run_nucmer.sh'
+        self._write_script(script, ref, qry, outfile) 
+        syscall.run('bash ' + script, verbose=self.verbose)
+        os.chdir(original_dir)
+        shutil.rmtree(tmpdir)
+
diff --git a/pymummer/snp.py b/pymummer/snp.py
new file mode 100644
index 0000000..eafbd01
--- /dev/null
+++ b/pymummer/snp.py
@@ -0,0 +1,38 @@
+class Error (Exception): pass
+
+
+class Snp:
+    def __init__(self, line):
+        #[P1] [SUB] [SUB]  [P2] [BUFF] [DIST] [LEN R] [LEN Q] [FRM]   [TAGS]
+        #187  A     C      269  187    187    654     853     1       1   ref_name  qry_name
+        try:
+            l = line.rstrip().split('\t')
+            self.ref_pos = int(l[0]) - 1
+            self.ref_base = l[1]
+            self.qry_base = l[2]
+            self.qry_pos = int(l[3]) - 1
+            self.ref_length = int(l[6])
+            self.qry_length = int(l[7])
+            self.ref_name = l[10]
+            self.qry_name = l[11]
+        except:
+            raise Error('Error constructing pymummer.snp.Snp from mummer show-snps output at this line:\n' + line)
+
+
+    def __eq__(self, other):
+        return type(other) is type(self) and self.__dict__ == other.__dict__
+
+
+    def __str__(self):
+        return '\t'.join([str(x) for x in [
+            self.ref_pos + 1,
+            self.ref_base,
+            self.qry_base,
+            self.qry_pos + 1,
+            self.ref_length,
+            self.qry_length,
+            self.ref_name,
+            self.qry_name
+        ]])
+
+
diff --git a/pymummer/snp_file.py b/pymummer/snp_file.py
new file mode 100644
index 0000000..9386f5c
--- /dev/null
+++ b/pymummer/snp_file.py
@@ -0,0 +1,24 @@
+import pyfastaq
+from pymummer import snp, variant
+
+def reader(fname):
+    f = pyfastaq.utils.open_file_read(fname)
+
+    for line in f:
+        if line.startswith('[') or (not '\t' in line):
+            continue
+
+        yield snp.Snp(line)
+
+    pyfastaq.utils.close(f)
+
+
+def get_all_variants(fname):
+    variants = []
+    fr = reader(fname)
+    for nucmer_snp in fr:
+        if len(variants) == 0 or not variants[-1].update_indel(nucmer_snp):
+            variants.append(variant.Variant(nucmer_snp))
+
+    return variants
+
diff --git a/pymummer/syscall.py b/pymummer/syscall.py
new file mode 100644
index 0000000..4764653
--- /dev/null
+++ b/pymummer/syscall.py
@@ -0,0 +1,30 @@
+import os
+import sys
+import subprocess
+
+class Error (Exception): pass
+
+
+def decode(x):
+    try:
+        s = x.decode()
+    except:
+        return x
+    return s
+
+
+def run(cmd, verbose=False):
+    if verbose:
+        print('Running command:', cmd, flush=True)
+    try:
+        output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT)
+    except subprocess.CalledProcessError as error:
+        print('The following command failed with exit code', error.returncode, file=sys.stderr)
+        print(cmd, file=sys.stderr)
+        print('\nThe output was:\n', file=sys.stderr)
+        print(error.output.decode(), file=sys.stderr)
+        raise Error('Error running command:', cmd)
+            
+    if verbose:
+        print(decode(output))
+
diff --git a/pymummer/tests/alignment_test.py b/pymummer/tests/alignment_test.py
new file mode 100644
index 0000000..0574f22
--- /dev/null
+++ b/pymummer/tests/alignment_test.py
@@ -0,0 +1,131 @@
+import unittest
+import os
+import pyfastaq
+from pymummer import alignment
+
+modules_dir = os.path.dirname(os.path.abspath(alignment.__file__))
+data_dir = os.path.join(modules_dir, 'tests', 'data')
+
+class TestNucmer(unittest.TestCase):
+    def test_init_nucmer(self):
+        '''test __init__ nucmer'''
+        line = '\t'.join(['1', '100', '2', '200', '101', '202', '42.42', '123', '456', '-1', '0', 'ref', 'qry', '[FOO]'])
+        a = alignment.Alignment(line)
+        self.assertEqual(a.ref_start, 0)
+        self.assertEqual(a.ref_end, 99)
+        self.assertEqual(a.qry_start, 1)
+        self.assertEqual(a.qry_end, 199)
+        self.assertEqual(a.hit_length_ref, 101)
+        self.assertEqual(a.hit_length_qry, 202)
+        self.assertEqual(a.percent_identity, 42.42)
+        self.assertEqual(a.ref_length, 123)
+        self.assertEqual(a.qry_length, 456)
+        self.assertEqual(a.frame, -1)
+        self.assertEqual(a.ref_name, 'ref')
+        self.assertEqual(a.qry_name, 'qry')
+
+
+    def test_init_promer(self):
+        '''test __init__ promer'''
+        line = '\t'.join(['1', '1398', '4891054', '4892445', '1398', '1392', '89.55', '93.18', '0.21', '1398', '5349013', '1', '1', 'ref', 'qry', '[CONTAINED]'])
+
+        a = alignment.Alignment(line)
+        self.assertEqual(a.ref_start, 0)
+        self.assertEqual(a.ref_end, 1397)
+        self.assertEqual(a.qry_start, 4891053)
+        self.assertEqual(a.qry_end, 4892444)
+        self.assertEqual(a.hit_length_ref, 1398)
+        self.assertEqual(a.hit_length_qry, 1392)
+        self.assertEqual(a.percent_identity, 89.55)
+        self.assertEqual(a.ref_length, 1398)
+        self.assertEqual(a.qry_length, 5349013)
+        self.assertEqual(a.frame, 1)
+        self.assertEqual(a.ref_name, 'ref')
+        self.assertEqual(a.qry_name, 'qry')
+
+
+    def test_swap(self):
+        ''' test swap'''
+        l_in = ['1', '100', '2', '200', '101', '202', '42.42', '123', '456', '-1', '0', 'ref', 'qry']
+        l_out = ['2', '200', '1', '100', '202', '101', '42.42', '456', '123', '-1', '0', 'qry', 'ref']
+        a_in = alignment.Alignment('\t'.join(l_in))
+        a_in._swap()
+        self.assertEqual(a_in, alignment.Alignment('\t'.join(l_out)))
+        a_in._swap()
+        self.assertEqual(a_in, alignment.Alignment('\t'.join(l_in)))
+
+
+    def test_qry_coords(self):
+        '''Test qry_coords'''
+        hits = ['\t'.join(['1', '100', '1', '100', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'qry']),
+                '\t'.join(['1', '101', '100', '1', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'qry'])
+        ]
+        for h in hits:
+            a = alignment.Alignment(h)
+            self.assertEqual(pyfastaq.intervals.Interval(0,99), a.qry_coords())
+
+
+    def test_ref_coords(self):
+        '''Test ref_coords'''
+        hits = ['\t'.join(['1', '100', '1', '100', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref']),
+                '\t'.join(['100', '1', '100', '1', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref'])
+        ]
+        for h in hits:
+            a = alignment.Alignment(h)
+            self.assertEqual(pyfastaq.intervals.Interval(0,99), a.ref_coords())
+
+
+    def test_on_same_strand(self):
+        '''test on_same_strand'''
+        self.assertTrue(alignment.Alignment('\t'.join(['1', '100', '1', '100', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref'])).on_same_strand())
+        self.assertTrue(alignment.Alignment('\t'.join(['100', '1', '100', '1', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref'])).on_same_strand())
+        self.assertFalse(alignment.Alignment('\t'.join(['1', '100', '100', '1', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref'])).on_same_strand())
+        self.assertFalse(alignment.Alignment('\t'.join(['100', '1', '1', '100', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref'])).on_same_strand())
+
+
+    def test_is_self_hit(self):
+        '''Test is_self_hit'''
+        tests = [('\t'.join(['1', '100', '1', '100', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref']), True),
+            ('\t'.join(['1', '101', '1', '100', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref']), False),
+            ('\t'.join(['2', '100', '1', '100', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref']), False),
+            ('\t'.join(['1', '100', '1', '100', '100', '100', '100.00', '1000', '1000', '1', '1', 'ref', 'ref2']), False),
+            ('\t'.join(['1', '100', '1', '100', '100', '100', '99.9', '1000', '1000', '1', '1', 'ref', 'ref']), False),
+        ]
+
+        for t in tests:
+            a = alignment.Alignment(t[0])
+            self.assertEqual(a.is_self_hit(), t[1])
+
+
+    def test_reverse_reference(self):
+        '''Test reverse_reference'''
+        aln = alignment.Alignment('\t'.join(['100', '142', '1', '42', '43', '42', '100.00', '150', '100', '1', '1', 'ref', 'qry']))
+        expected = alignment.Alignment('\t'.join(['51', '9', '1', '42', '43', '42', '100.00', '150', '100', '1', '1', 'ref', 'qry']))
+        aln.reverse_reference()
+        self.assertEqual(expected, aln)
+
+
+    def test_reverse_query(self):
+        '''Test reverse_query'''
+        aln = alignment.Alignment('\t'.join(['100', '142', '1', '42', '43', '42', '100.00', '150', '100', '1', '1', 'ref', 'qry']))
+        expected = alignment.Alignment('\t'.join(['100', '142', '100', '59', '43', '42', '100.00', '150', '100', '1', '1', 'ref', 'qry']))
+        aln.reverse_query()
+        self.assertEqual(expected, aln)
+
+
+    def test_str(self):
+        '''Test __str__'''
+        l_in = ['1', '100', '2', '200', '101', '202', '42.42', '123', '456', '-1', '0', 'ref', 'qry']
+        # the 10th column (counting from zero) is ignored and so not output by __str__
+        l_out = l_in[:10] + l_in[11:]
+        a = alignment.Alignment('\t'.join(l_in))
+        self.assertEqual(str(a), '\t'.join(l_out))
+
+
+    def test_to_msp_crunch(self):
+        '''Test to_msp_crunch'''
+        l_in = ['100', '110', '1', '10', '10', '11', '80.00', '123', '456', '-1', '0', 'ref', 'qry']
+        a = alignment.Alignment('\t'.join(l_in))
+        expected = '8 80.00 1 10 qry 100 110 ref'
+        self.assertEqual(expected, a.to_msp_crunch())
+
diff --git a/pymummer/tests/coords_file_test.py b/pymummer/tests/coords_file_test.py
new file mode 100644
index 0000000..b3ad26a
--- /dev/null
+++ b/pymummer/tests/coords_file_test.py
@@ -0,0 +1,51 @@
+import unittest
+import os
+import filecmp
+from pymummer import coords_file, alignment
+
+modules_dir = os.path.dirname(os.path.abspath(coords_file.__file__))
+data_dir = os.path.join(modules_dir, 'tests', 'data')
+
+class TestCoordsFile(unittest.TestCase):
+    def test_coords_file(self):
+        '''test coords_file'''
+        expected = [
+            '\t'.join(['61', '900', '1', '840', '840', '840', '99.76', '1000', '840', '1', '1', 'test_ref1', 'test_qry1', '[CONTAINS]']),
+            '\t'.join(['62', '901', '2', '841', '841', '850', '99.66', '999', '839', '1', '1', 'test_ref2', 'test_qry2', '[CONTAINS]']),
+            '\t'.join(['63', '902', '3', '842', '842', '860', '99.56', '998', '838', '1', '1', 'test_ref3', 'test_qry3', '[CONTAINS]'])
+        ]
+        expected = [alignment.Alignment(x) for x in expected]
+
+        infiles = [os.path.join(data_dir, 'coords_file_test_with_header.coords'), os.path.join(data_dir, 'coords_file_test_no_header.coords')]
+
+        for fname in infiles:
+            fr = coords_file.reader(fname)
+            alignments = [x for x in fr]
+            self.assertEqual(alignments, expected)
+
+
+    def test_convert_to_msp_crunch_no_offset(self):
+        '''Test convert_to_msp_crunch with no offsets'''
+        infile = os.path.join(data_dir, 'coords_file_test_convert_to_msp_crunch.coords')
+        expected = os.path.join(data_dir, 'coords_file_test_convert_to_msp_crunch.no_offset.crunch')
+        tmpfile = 'tmp.test_convert_to_msp_crunch_no_offset.crunch'
+        coords_file.convert_to_msp_crunch(infile, tmpfile)
+        self.assertTrue(filecmp.cmp(expected, tmpfile, shallow=False))
+        os.unlink(tmpfile)
+
+
+    def test_convert_to_msp_crunch_with_offset(self):
+        '''Test convert_to_msp_crunch with offsets'''
+        infile = os.path.join(data_dir, 'coords_file_test_convert_to_msp_crunch.coords')
+        ref_fai = os.path.join(data_dir, 'coords_file_test_convert_to_msp_crunch.ref.fa.fai')
+        qry_fai = os.path.join(data_dir, 'coords_file_test_convert_to_msp_crunch.qry.fa.fai')
+        expected = os.path.join(data_dir, 'coords_file_test_convert_to_msp_crunch.with_offset.crunch')
+        tmpfile = 'tmp.test_convert_to_msp_crunch_with_offset.crunch'
+
+        with self.assertRaises(coords_file.Error):
+            coords_file.convert_to_msp_crunch(infile, tmpfile, ref_fai=ref_fai)
+            coords_file.convert_to_msp_crunch(infile, tmpfile, qry_fai=qry_fai)
+
+        coords_file.convert_to_msp_crunch(infile, tmpfile, ref_fai=ref_fai, qry_fai=qry_fai)
+        self.assertTrue(filecmp.cmp(expected, tmpfile, shallow=False))
+        os.unlink(tmpfile)
diff --git a/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.coords b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.coords
new file mode 100644
index 0000000..9e44934
--- /dev/null
+++ b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.coords
@@ -0,0 +1,7 @@
+/Users/mh12/sanger-pathogens/pymummer/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.ref.fa /Users/mh12/sanger-pathogens/pymummer/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.qry.fa
+NUCMER
+
+[S1]	[E1]	[S2]	[E2]	[LEN 1]	[LEN 2]	[% IDY]	[LEN R]	[LEN Q]	[FRM]	[TAGS]
+1	420	1	420	420	420	99.76	420	420	1	1	ref1	qry1	[IDENTITY]
+1	480	1	479	480	479	99.58	480	479	1	1	ref2	qry2	[IDENTITY]
+61	420	1	360	360	360	99.44	500	360	1	1	ref3	qry3	[CONTAINS]
diff --git a/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.no_offset.crunch b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.no_offset.crunch
new file mode 100644
index 0000000..9b1eff9
--- /dev/null
+++ b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.no_offset.crunch
@@ -0,0 +1,3 @@
+418 99.76 1 420 qry1 1 420 ref1
+477 99.58 1 479 qry2 1 480 ref2
+357 99.44 1 360 qry3 61 420 ref3
diff --git a/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.qry.fa b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.qry.fa
new file mode 100644
index 0000000..c9ffa23
--- /dev/null
+++ b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.qry.fa
@@ -0,0 +1,24 @@
+>qry1
+AACTTTCATACTGTAGTTATTGGCATCGTTGTAAAATTGCTCACCACGTCGCTCGTTCAT
+GATAATCTAAAGATCGCTAACGATTACTACCGGCAGCGGTTTATACGGACCAATCGTTGG
+TTCATTTTAATGTAGACCCAGAAATCGACTGCATTTCTGCAGCCCGGCCCGACGTGTTGA
+ACGGATGATCTTAGACAGAACGTCCTTGGGTCTATATCCGGCCACATATTTATTGGGCAG
+GGGAGTCAATTGGGGGCGTACCGAAATATCGTCTTTACGAGCGTCGGTGACGCACATGAC
+ATGGTCGACCCATAGCCTCAGCTTCTAGACGGTTGCACCAGCGCAAGACAAAACTCTCAA
+TTTTGTCTGGGTACCGAGATTGCGGAACCGGGGATATTGTAGAGCGGTGCACACGGCCTT
+>qry2
+CTAGCGCAAGACCGACTCTGATTCATGGAGACAGGGCCAGACAGGGAAACGAGATTGAGC
+GATGCTGTCATTTTCGTAACGAGGATTGGTCGGGGACCGAGATCGTACACGTCTCCGAGC
+CCCCACAGTCGAGTACAAATGGCTTAATTTACTGACTTCTTCCTGTTACCGGCATGGTAT
+GCTGAGCCTGGCCCGCTCACTATTGGATATAGCCTGTGCGCTGGCGTACCGCTGTTCTAC
+CGGTTCCTCTTGAGGGTCAAAGGCCGGCTACCATCGTTAACTTATTAGCTTAGAGTAATG
+TAGGTTACGTGACGCTGGCCGGTTAGCGTTTCGAAGGATCGCAGGACTATAGTCAAAACT
+CGTGGACTTCTACCAGAACTATCGATGTTCACGATGACTACGTTCCTTCCGAATATTACA
+GTAAGGGATAGTCATGCCGGTTTAACATCATCTGTGTGTACGCAATGCAGTTTGGCACA
+>qry3
+AGGTGCGACAGGATCTAACACCTGTACAGTAAGAAAGGGGCATATGATCGACCCCGGTTG
+CTCGTATGATAATCCCATTATTGTTATCTGAGGATCGTTATGCGGCAGTTCTAGTCCGAT
+AAAAGTTAGGTGAGTTGTGTTGGTAATCCTTCTCTAGGAGGCCTGGCGACTCCACTGAGC
+CCAGCGATGGGAGAGCTGGTCCCCCCAATATCGTGACTGAATTGGTAAGGTAGATATCTC
+CCAGATAGCCGCATACCGTCTGGCACCGTCGACCGAAAGAAATGTTCGCCTTGGCATGCT
+CAGATTGCATCTATACTTACTTGTATAGAACTGCCCGCGCCACCCAGAAGACAAACTAAT
diff --git a/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.qry.fa.fai b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.qry.fa.fai
new file mode 100644
index 0000000..2b20707
--- /dev/null
+++ b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.qry.fa.fai
@@ -0,0 +1,3 @@
+qry1	420	6	60	61
+qry2	479	439	60	61
+qry3	360	932	60	61
diff --git a/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.ref.fa b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.ref.fa
new file mode 100644
index 0000000..2f0afca
--- /dev/null
+++ b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.ref.fa
@@ -0,0 +1,27 @@
+>ref1
+AACTTTCATACTGTAGTTATTGGCATCGTTGTAAAATTGCTCACCACGTCGCTCGTTCAT
+GATAATCTAAAGATCGCTAACGATTACTACCGGCAGCGGTTTATACGGACCAATCGTTGG
+TTCATTTTAATGTAGACCCAGAAATCGACTGCATTTCTGCAGCCCGGCCCGACGTGTTGA
+ACGGATGATCTTAGACAGAACGTCCTTGGGTCTATATCCGGCCACATATTTATTGGGCAG
+GGGTGTCAATTGGGGGCGTACCGAAATATCGTCTTTACGAGCGTCGGTGACGCACATGAC
+ATGGTCGACCCATAGCCTCAGCTTCTAGACGGTTGCACCAGCGCAAGACAAAACTCTCAA
+TTTTGTCTGGGTACCGAGATTGCGGAACCGGGGATATTGTAGAGCGGTGCACACGGCCTT
+>ref2
+CTAGCGCAAGACCGACTCTGATTCATGGAGACAGGGCCAGACAGGGAAACGAGATTGAGC
+GATGCTGTCATTTTCGTAACGAGGATTGGTCGGGGACCGAGATCGTACACGTCTCCGAGC
+CCCCACAGTCGAGTACAAATGGCTTAATTTACTGACTTCTTCCTGTTACCGGCATGGTAT
+GCTGAGCCTGGCCCGCTCACTATTGGATATAGCCTGTGCGCTGGCGTACCGCTGTTCTAC
+CGGTACCTCTTGAGGGTCAAAGGCCGGCTACCATCGTTAACTTATTAGCTTAGAGTAATG
+TAGGTTACGTGACGCTGGCCGGTTAGCGTTTCGAAGGATCGCAGGACTATAGTCAAAACT
+CGTGGACTTCTACCAGAACTATCGATGTTCACGATGACTACGTTCCTTCCGAATATTACA
+GTATAGGGATAGTCATGCCGGTTTAACATCATCTGTGTGTACGCAATGCAGTTTGGCACA
+>ref3
+ATTCAACGGGTAGGGTCATCAGATTTTTAGTACGAACGAACAATTCCCCATTCAATTCCG
+AGGTGCGACAGGATCTAACACCTGTACAGTAAGAAAGGGGCATATGATCGACCCCGGTTG
+CTCGTATGATAATCCCATTATTGTTATCTGAGGATCGTTATGCGGCAGTTCTAGTCCGAT
+CCAAGTTAGGTGAGTTGTGTTGGTAATCCTTCTCTAGGAGGCCTGGCGACTCCACTGAGC
+CCAGCGATGGGAGAGCTGGTCCCCCCAATATCGTGACTGAATTGGTAAGGTAGATATCTC
+CCAGATAGCCGCATACCGTCTGGCACCGTCGACCGAAAGAAATGTTCGCCTTGGCATGCT
+CAGATTGCATCTATACTTACTTGTATAGAACTGCCCGCGCCACCCAGAAGACAAACTAAT
+TTATTGTCGCTCAAACCTGTTTAGTTAATTCACCTTTGTAACCAGCTTACCCTCAATTGC
+GTATGTAACTCCTTGGCTGC
diff --git a/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.ref.fa.fai b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.ref.fa.fai
new file mode 100644
index 0000000..da15e5d
--- /dev/null
+++ b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.ref.fa.fai
@@ -0,0 +1,3 @@
+ref1	420	6	60	61
+ref2	480	439	60	61
+ref3	500	933	60	61
diff --git a/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.with_offset.crunch b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.with_offset.crunch
new file mode 100644
index 0000000..a0a6bd8
--- /dev/null
+++ b/pymummer/tests/data/coords_file_test_convert_to_msp_crunch.with_offset.crunch
@@ -0,0 +1,3 @@
+418 99.76 1 420 qry1 1 420 ref1
+477 99.58 421 899 qry2 421 900 ref2
+357 99.44 900 1259 qry3 961 1320 ref3
diff --git a/pymummer/tests/data/coords_file_test_no_header.coords b/pymummer/tests/data/coords_file_test_no_header.coords
new file mode 100644
index 0000000..aa09fe2
--- /dev/null
+++ b/pymummer/tests/data/coords_file_test_no_header.coords
@@ -0,0 +1,3 @@
+61	900	1	840	840	840	99.76	1000	840	1	1	test_ref1	test_qry1	[CONTAINS]
+62	901	2	841	841	850	99.66	999	839	1	1	test_ref2	test_qry2	[CONTAINS]
+63	902	3	842	842	860	99.56	998	838	1	1	test_ref3	test_qry3	[CONTAINS]
diff --git a/pymummer/tests/data/coords_file_test_with_header.coords b/pymummer/tests/data/coords_file_test_with_header.coords
new file mode 100644
index 0000000..f3b61dd
--- /dev/null
+++ b/pymummer/tests/data/coords_file_test_with_header.coords
@@ -0,0 +1,7 @@
+/path/to/ref.fa /path/to/query.fa
+NUCMER
+
+[S1]	[E1]	[S2]	[E2]	[LEN 1]	[LEN 2]	[% IDY]	[LEN R]	[LEN Q]	[FRM]	[TAGS]
+61	900	1	840	840	840	99.76	1000	840	1	1	test_ref1	test_qry1	[CONTAINS]
+62	901	2	841	841	850	99.66	999	839	1	1	test_ref2	test_qry2	[CONTAINS]
+63	902	3	842	842	860	99.56	998	838	1	1	test_ref3	test_qry3	[CONTAINS]
diff --git a/pymummer/tests/data/nucmer_test_out.coords b/pymummer/tests/data/nucmer_test_out.coords
new file mode 100644
index 0000000..1c38468
--- /dev/null
+++ b/pymummer/tests/data/nucmer_test_out.coords
@@ -0,0 +1 @@
+61	900	1	840	840	840	99.76	1000	840	1	1	test_ref	test_qry	[CONTAINS]
diff --git a/pymummer/tests/data/nucmer_test_out.coords.snps b/pymummer/tests/data/nucmer_test_out.coords.snps
new file mode 100644
index 0000000..bc36e4e
--- /dev/null
+++ b/pymummer/tests/data/nucmer_test_out.coords.snps
@@ -0,0 +1,2 @@
+436	C	.	375	2	375	1000	840	1	1	test_ref	test_qry
+438	.	G	378	2	378	1000	840	1	1	test_ref	test_qry
diff --git a/pymummer/tests/data/nucmer_test_qry.fa b/pymummer/tests/data/nucmer_test_qry.fa
new file mode 100644
index 0000000..294ad9a
--- /dev/null
+++ b/pymummer/tests/data/nucmer_test_qry.fa
@@ -0,0 +1,15 @@
+>test_qry
+GTAATCAAATAATCCACCGGATGAGGTATTTTCTCATCGGGGTGACTCTAACCACATCGT
+GTTTCTTCCTGAAGGCTCTAAGATGTCATGAGAACTCTTACTGTCTAGCTGAGGGGCTTG
+TGCACAACACTAGGATTGTGTCTTATGCTCTATTGGACAGCGAAAACTGCTGAAATTAAC
+GGGCCGTAACATACTATATTCTTCAAACCGAATTAACGTTCAGCCCCCGCTTGATTGCGA
+AATTAACTGGAATGCAACACCTTGCACTGGCCGTCCTGCGGTGGTGACCCTTTGAGGTAA
+ACACGTCGTCGACGCATTACAGTTGGGAGAAGCACACTCATGTTTCTAATAAAGCGCTCA
+CAGACGCGACCACTATAGCTCTAAAATACATCCCTCTAAGGTTCCATCTAGAAAGTGGCC
+CCCGCGACCGTCTACCGTGGTGGATGCAGGGAGTCACCTACGCGTCTTTTCGTGCTACCT
+AGGCATTTTTGCACTACCTAACTCCGTATTAAGGCCTTCGGAGAGGGCCGTCCCACTTCA
+ATGTGTGTGGTGGACTGTCCTCATGGGAAAAGCAAGTGTTTGACCGGTTGACACTAGTCC
+CGTTTATCTTCATGGGCGGGAGCGCGCATTCGTGACGGGGACACTTCTCGCCGTTTAGCC
+GGTGAGCTTATTAGGCCGATGGCGGGCCACCCTGATACGGGGGCCTATATGTCCACGAAT
+ATCAATTTCTGTATAACATTGGGCGCAGAAAACAGACTGGTCCAAATAAGATGAATCTAT
+AGCCCAGTGTGTTGCCTAAACGCTGAGCGAATAATTGGTCGCGCTCGGCGAGACCAGGGA
diff --git a/pymummer/tests/data/nucmer_test_ref.fa b/pymummer/tests/data/nucmer_test_ref.fa
new file mode 100644
index 0000000..0c0c558
--- /dev/null
+++ b/pymummer/tests/data/nucmer_test_ref.fa
@@ -0,0 +1,18 @@
+>test_ref
+TCAAGATCGTGCCCCGTTGATATCGCTGTTGCACAGGACTTTCTCCACCCTGATACCGCA
+GTAATCAAATAATCCACCGGATGAGGTATTTTCTCATCGGGGTGACTCTAACCACATCGT
+GTTTCTTCCTGAAGGCTCTAAGATGTCATGAGAACTCTTACTGTCTAGCTGAGGGGCTTG
+TGCACAACACTAGGATTGTGTCTTATGCTCTATTGGACAGCGAAAACTGCTGAAATTAAC
+GGGCCGTAACATACTATATTCTTCAAACCGAATTAACGTTCAGCCCCCGCTTGATTGCGA
+AATTAACTGGAATGCAACACCTTGCACTGGCCGTCCTGCGGTGGTGACCCTTTGAGGTAA
+ACACGTCGTCGACGCATTACAGTTGGGAGAAGCACACTCATGTTTCTAATAAAGCGCTCA
+CAGACGCGACCACTACTACTCTAAAATACATCCCTCTAAGGTTCCATCTAGAAAGTGGCC
+CCCGCGACCGTCTACCGTGGTGGATGCAGGGAGTCACCTACGCGTCTTTTCGTGCTACCT
+AGGCATTTTTGCACTACCTAACTCCGTATTAAGGCCTTCGGAGAGGGCCGTCCCACTTCA
+ATGTGTGTGGTGGACTGTCCTCATGGGAAAAGCAAGTGTTTGACCGGTTGACACTAGTCC
+CGTTTATCTTCATGGGCGGGAGCGCGCATTCGTGACGGGGACACTTCTCGCCGTTTAGCC
+GGTGAGCTTATTAGGCCGATGGCGGGCCACCCTGATACGGGGGCCTATATGTCCACGAAT
+ATCAATTTCTGTATAACATTGGGCGCAGAAAACAGACTGGTCCAAATAAGATGAATCTAT
+AGCCCAGTGTGTTGCCTAAACGCTGAGCGAATAATTGGTCGCGCTCGGCGAGACCAGGGA
+TTCTGGCAAGATCCTAACTCGGCCGTCAATGATGTTAAATCAACTCGGTGTGGCCCCAGC
+TTCGACACCAAAAGTTGTGATCACTACATAGCGTATCTCG
diff --git a/pymummer/tests/data/nucmer_test_write_script_no_snps.sh b/pymummer/tests/data/nucmer_test_write_script_no_snps.sh
new file mode 100644
index 0000000..a0a09a9
--- /dev/null
+++ b/pymummer/tests/data/nucmer_test_write_script_no_snps.sh
@@ -0,0 +1,3 @@
+nucmer -p p ref qry
+delta-filter p.delta > p.delta.filter
+show-coords -dTlro p.delta.filter > outfile
diff --git a/pymummer/tests/data/nucmer_test_write_script_with_snps.sh b/pymummer/tests/data/nucmer_test_write_script_with_snps.sh
new file mode 100644
index 0000000..d624808
--- /dev/null
+++ b/pymummer/tests/data/nucmer_test_write_script_with_snps.sh
@@ -0,0 +1,4 @@
+nucmer -p p ref qry
+delta-filter p.delta > p.delta.filter
+show-coords -dTlro p.delta.filter > outfile
+show-snps -TClr p.delta.filter > outfile.snps
diff --git a/pymummer/tests/data/snp_file_test_get_all_variants.snps b/pymummer/tests/data/snp_file_test_get_all_variants.snps
new file mode 100644
index 0000000..e2a84a6
--- /dev/null
+++ b/pymummer/tests/data/snp_file_test_get_all_variants.snps
@@ -0,0 +1,8 @@
+125	T	.	124	1	124	500	497	1	1	ref1	qry1
+126	A	.	124	1	124	500	497	1	1	ref1	qry1
+127	C	.	124	1	124	500	497	1	1	ref1	qry1
+386	C	T	383	115	115	500	497	1	1	ref1	qry1
+479	.	G	480	0	22	500	504	1	1	ref2	qry2
+479	.	A	481	0	22	500	504	1	1	ref2	qry2
+479	.	T	482	0	22	500	504	1	1	ref2	qry2
+479	.	A	483	0	22	500	504	1	1	ref2	qry2
diff --git a/pymummer/tests/data/snp_file_test_no_header.snps b/pymummer/tests/data/snp_file_test_no_header.snps
new file mode 100644
index 0000000..833c64f
--- /dev/null
+++ b/pymummer/tests/data/snp_file_test_no_header.snps
@@ -0,0 +1,3 @@
+133	G	.	122	1	122	500	489	1	1	ref	qry
+143	.	C	131	1	132	500	489	1	1	ref	qry
+253	T	A	242	120	242	500	489	1	1	ref	qry
diff --git a/pymummer/tests/data/snp_file_test_with_header.snps b/pymummer/tests/data/snp_file_test_with_header.snps
new file mode 100644
index 0000000..ad93e37
--- /dev/null
+++ b/pymummer/tests/data/snp_file_test_with_header.snps
@@ -0,0 +1,7 @@
+/path/to/ref.fa /path/to/qry.fa
+NUCMER
+
+[P1]	[SUB]	[SUB]	[P2]	[BUFF]	[DIST]	[LEN R]	[LEN Q]	[FRM]	[TAGS]
+133	G	.	122	1	122	500	489	1	1	ref	qry
+143	.	C	131	1	132	500	489	1	1	ref	qry
+253	T	A	242	120	242	500	489	1	1	ref	qry
diff --git a/pymummer/tests/nucmer_test.py b/pymummer/tests/nucmer_test.py
new file mode 100644
index 0000000..8962a55
--- /dev/null
+++ b/pymummer/tests/nucmer_test.py
@@ -0,0 +1,97 @@
+import unittest
+import os
+import filecmp
+from pymummer import nucmer
+
+modules_dir = os.path.dirname(os.path.abspath(nucmer.__file__))
+data_dir = os.path.join(modules_dir, 'tests', 'data')
+
+
+class TestRunner(unittest.TestCase):
+    def test_nucmer_command(self):
+        '''test _nucmer_command'''
+        tests = [
+            [nucmer.Runner('ref', 'qry', 'outfile'), 'nucmer -p pre ref qry'],
+            [nucmer.Runner('ref', 'qry', 'outfile', breaklen=42), 'nucmer -p pre -b 42 ref qry'],
+            [nucmer.Runner('ref', 'qry', 'outfile', diagdiff=11), 'nucmer -p pre -D 11 ref qry'],
+            [nucmer.Runner('ref', 'qry', 'outfile', diagdiff=11, promer=True), 'promer -p pre ref qry'],
+            [nucmer.Runner('ref', 'qry', 'outfile', maxmatch=True), 'nucmer -p pre --maxmatch ref qry'],
+            [nucmer.Runner('ref', 'qry', 'outfile', simplify=False), 'nucmer -p pre --nosimplify ref qry'],
+            [nucmer.Runner('ref', 'qry', 'outfile', promer=True), 'promer -p pre ref qry'],
+            [nucmer.Runner('ref', 'qry', 'outfile', promer=True, breaklen=42), 'promer -p pre -b 42 ref qry'],
+            [nucmer.Runner('ref', 'qry', 'outfile', promer=True, maxmatch=True), 'promer -p pre --maxmatch ref qry'],
+            [nucmer.Runner('ref', 'qry', 'outfile', promer=True, simplify=False), 'promer -p pre ref qry']
+        ]
+
+        for l in tests:
+            self.assertEqual(l[0]._nucmer_command('ref', 'qry', 'pre'), l[1])
+
+
+    def test_delta_filter_command(self):
+        '''test _delta_filter_command'''
+        tests = [
+            [nucmer.Runner('ref', 'qry', 'outfile'), 'delta-filter infile > outfile'],
+            [nucmer.Runner('ref', 'qry', 'outfile', min_id=42), 'delta-filter -i 42 infile > outfile'],
+            [nucmer.Runner('ref', 'qry', 'outfile', min_length=43), 'delta-filter -l 43 infile > outfile'],
+        ]
+
+        for l in tests:
+            self.assertEqual(l[0]._delta_filter_command('infile', 'outfile'), l[1])
+        
+
+    def test_show_coords_command(self):
+        '''test _show_coords_command'''
+        tests = [
+            [nucmer.Runner('ref', 'qry', 'outfile', coords_header=False), 'show-coords -dTlro -H infile > outfile'],
+            [nucmer.Runner('ref', 'qry', 'outfile'), 'show-coords -dTlro infile > outfile']
+        ]
+
+        for l in tests:
+            self.assertEqual(l[0]._show_coords_command('infile', 'outfile'), l[1])
+
+
+    def test_show_snps_command(self):
+        '''test _show_snps_command'''
+        tests = [
+            [nucmer.Runner('ref', 'qry', 'outfile', snps_header=False), 'show-snps -TClr -H infile > outfile'],
+            [nucmer.Runner('ref', 'qry', 'outfile'), 'show-snps -TClr infile > outfile']
+        ]
+
+        for l in tests:
+            self.assertEqual(l[0]._show_snps_command('infile', 'outfile'), l[1])
+
+
+    def test_write_script_no_snps(self):
+       '''test _write_script no snps'''
+       tmp_script = 'tmp.script.sh'
+       r = nucmer.Runner('ref', 'qry', 'outfile')
+       r._write_script(tmp_script, 'ref', 'qry', 'outfile')
+       expected = os.path.join(data_dir, 'nucmer_test_write_script_no_snps.sh')
+       self.assertTrue(filecmp.cmp(expected, tmp_script, shallow=False))
+       os.unlink(tmp_script)
+
+
+    def test_write_script_with_snps(self):
+       '''test _write_script with snps'''
+       tmp_script = 'tmp.script.sh'
+       r = nucmer.Runner('ref', 'qry', 'outfile', show_snps='outfile.snps')
+       r._write_script(tmp_script, 'ref', 'qry', 'outfile')
+       expected = os.path.join(data_dir, 'nucmer_test_write_script_with_snps.sh')
+       self.assertTrue(filecmp.cmp(expected, tmp_script, shallow=False))
+       os.unlink(tmp_script)
+
+
+    def test_run_nucmer(self):
+        '''test run_nucmer'''
+        qry = os.path.join(data_dir, 'nucmer_test_qry.fa')
+        ref = os.path.join(data_dir, 'nucmer_test_ref.fa')
+        tmp_out = 'tmp.nucmer.out'
+        runner = nucmer.Runner(ref, qry, tmp_out, coords_header=False, show_snps=True, snps_header=False)
+        runner.run()
+        expected = os.path.join(data_dir, 'nucmer_test_out.coords')
+        self.assertTrue(filecmp.cmp(tmp_out, expected, shallow=False))
+        self.assertTrue(filecmp.cmp(tmp_out + '.snps', expected + '.snps', shallow=False))
+        os.unlink(tmp_out)
+        os.unlink(tmp_out + '.snps')
+        
+
diff --git a/pymummer/tests/snp_file_test.py b/pymummer/tests/snp_file_test.py
new file mode 100644
index 0000000..03a5035
--- /dev/null
+++ b/pymummer/tests/snp_file_test.py
@@ -0,0 +1,58 @@
+import unittest
+import os
+from pymummer import snp_file, snp, variant
+
+modules_dir = os.path.dirname(os.path.abspath(snp_file.__file__))
+data_dir = os.path.join(modules_dir, 'tests', 'data')
+
+class TestUtils(unittest.TestCase):
+    def test_snp_file(self):
+        '''test coords_file'''
+        expected = [
+            '\t'.join(['133', 'G', '.', '122', '1', '122', '500', '489', '1', '1', 'ref', 'qry']),
+            '\t'.join(['143', '.', 'C', '131', '1', '132', '500', '489', '1', '1', 'ref', 'qry']),
+            '\t'.join(['253', 'T', 'A', '242', '120', '242', '500', '489', '1', '1', 'ref', 'qry'])
+        ]
+
+        expected = [snp.Snp(x) for x in expected]
+
+        infiles = [os.path.join(data_dir, 'snp_file_test_with_header.snps'), os.path.join(data_dir, 'snp_file_test_no_header.snps')]
+
+        for fname in infiles:
+            fr = snp_file.reader(fname)
+            snps = [x for x in fr]
+            self.assertEqual(snps, expected)
+
+
+    def test_get_all_variants(self):
+        '''Test load all variants from file'''
+        deletion_snps = [
+            '\t'.join(['125', 'T', '.', '124', '1', '124', '500', '497', '1', '1', 'ref1', 'qry1']),
+            '\t'.join(['126', 'A', '.', '124', '1', '124', '500', '497', '1', '1', 'ref1', 'qry1']),
+            '\t'.join(['127', 'C', '.', '124', '1', '124', '500', '497', '1', '1', 'ref1', 'qry1']),
+        ]
+        deletion_snps = [snp.Snp(x) for x in deletion_snps]
+        deletion_variant = variant.Variant(deletion_snps[0])
+        deletion_variant.update_indel(deletion_snps[1])
+        deletion_variant.update_indel(deletion_snps[2])
+
+        just_a_snp = '\t'.join(['386', 'C', 'T', '383', '115', '115', '500', '497', '1', '1', 'ref1', 'qry1'])
+        snp_variant = variant.Variant(snp.Snp(just_a_snp))
+
+        insertion_snps = [
+            '\t'.join(['479', '.', 'G', '480', '0', '22', '500', '504', '1', '1', 'ref2', 'qry2']),
+            '\t'.join(['479', '.', 'A', '481', '0', '22', '500', '504', '1', '1', 'ref2', 'qry2']),
+            '\t'.join(['479', '.', 'T', '482', '0', '22', '500', '504', '1', '1', 'ref2', 'qry2']),
+            '\t'.join(['479', '.', 'A', '483', '0', '22', '500', '504', '1', '1', 'ref2', 'qry2']),
+        ]
+        insertion_snps = [snp.Snp(x) for x in insertion_snps]
+        insertion_variant = variant.Variant(insertion_snps[0])
+        for i in range(1, len(insertion_snps)):
+            insertion_variant.update_indel(insertion_snps[i])
+
+
+        variants_from_file = snp_file.get_all_variants(os.path.join(data_dir, 'snp_file_test_get_all_variants.snps'))
+        self.assertEqual(len(variants_from_file), 3)
+        self.assertEqual(variants_from_file[0], deletion_variant)
+        self.assertEqual(variants_from_file[1], snp_variant)
+        self.assertEqual(variants_from_file[2], insertion_variant)
diff --git a/pymummer/tests/snp_test.py b/pymummer/tests/snp_test.py
new file mode 100644
index 0000000..8f15553
--- /dev/null
+++ b/pymummer/tests/snp_test.py
@@ -0,0 +1,17 @@
+import unittest
+import os
+from pymummer import snp
+
+
+modules_dir = os.path.dirname(os.path.abspath(snp.__file__))
+data_dir = os.path.join(modules_dir, 'tests', 'data')
+
+
+class TestSnp(unittest.TestCase):
+    def test_str(self):
+        '''Test __str__'''
+        l_in = ['187', 'A', 'C', '269', '187', '187', '654', '853', '1', '1', 'ref_name', 'qry_name']
+        # only use columns 0-3, 6-7, 10-11
+        l_out = l_in[:4] + l_in[6:8] + l_in[10:]
+        s = snp.Snp('\t'.join(l_in))
+        self.assertEqual(str(s), '\t'.join(l_out))
diff --git a/pymummer/tests/syscall_test.py b/pymummer/tests/syscall_test.py
new file mode 100644
index 0000000..586fa70
--- /dev/null
+++ b/pymummer/tests/syscall_test.py
@@ -0,0 +1,16 @@
+import unittest
+import os
+from pymummer import syscall
+
+
+class TestSyscall(unittest.TestCase):
+    def test_run_fail(self):
+        '''Test that run raises error when command fails'''
+        with self.assertRaises(syscall.Error):
+            syscall.run('notacommandandthrowerror')
+
+
+    def test_run_ok(self):
+        '''Test run is ok on command that works'''
+        syscall.run('ls')
+
diff --git a/pymummer/tests/variant_test.py b/pymummer/tests/variant_test.py
new file mode 100644
index 0000000..6b5904f
--- /dev/null
+++ b/pymummer/tests/variant_test.py
@@ -0,0 +1,103 @@
+import unittest
+import copy
+import os
+from pymummer import variant, snp
+
+modules_dir = os.path.dirname(os.path.abspath(variant.__file__))
+data_dir = os.path.join(modules_dir, 'tests', 'data')
+
+
+class TestVariant(unittest.TestCase):
+    def test_init(self):
+        '''Test init gets correct variant type'''
+        lines = [
+            ['42', 'T', 'A', '42', '42', '42', '1000', '1000', '1', '1', 'ref', 'ref'],
+            ['242', 'G', '.', '241', '1', '241', '1000', '1000', '1', '1', 'ref', 'ref'],
+            ['300', '.', 'G', '298', '0', '298', '1000', '1000', '1', '1', 'ref', 'ref']
+        ]
+
+        variants = [variant.Variant(snp.Snp('\t'.join(x))) for x in lines]
+        expected = [variant.SNP, variant.DEL, variant.INS]
+        for i in range(len(lines)):
+            self.assertEqual(variants[i].var_type, expected[i])
+
+
+    def test_update_indel_no_change(self):
+        '''Test update_indel does nothing in the right cases'''
+        initial_vars = [
+            snp.Snp('\t'.join(['42', 'A', 'C', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', 'A', 'C', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+        ]
+
+        to_add = [
+            snp.Snp('\t'.join(['142', 'A', '.', '1000', 'x', 'x', '2000', '3000', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['142', '.', 'A', '1000', 'x', 'x', '2000', '3000', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['43', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref2', 'qry'])),
+            snp.Snp('\t'.join(['43', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry2'])),
+            snp.Snp('\t'.join(['44', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['43', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['43', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref2', 'qry'])),
+            snp.Snp('\t'.join(['43', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry2'])),
+            snp.Snp('\t'.join(['44', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+            snp.Snp('\t'.join(['42', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])),
+        ]
+
+        assert len(initial_vars) == len(to_add)
+
+        for i in range(len(initial_vars)):
+            var = variant.Variant(initial_vars[i])
+            var_original = copy.copy(var)
+            self.assertFalse(var.update_indel(to_add[i]))
+            self.assertEqual(var, var_original)
+
+    def test_update_indel_insertion(self):
+        '''Test update_indel extends insertions correctly'''
+        insertion = variant.Variant(snp.Snp('\t'.join(['42', '.', 'A', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])))
+        to_add = snp.Snp('\t'.join(['42', '.', 'C', '101', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry']))
+        expected = copy.copy(insertion)
+        # coords stored zero-based, so subtract 1 from the real expected coords
+        expected.ref_start = 41
+        expected.ref_end = 41
+        expected.ref_length = 300
+        expected.ref_name = 'ref'
+        expected.ref_base = '.'
+        expected.qry_start = 99
+        expected.qry_end = 100
+        expected.qry_length = 400
+        expected.qry_name = 'qry'
+        expected.qry_base = 'AC'
+        self.assertTrue(insertion.update_indel(to_add))
+        self.assertEqual(expected, insertion)
+
+
+    def test_update_indel_deletion(self):
+        '''Test update_indel extends deletions correctly'''
+        deletion = variant.Variant(snp.Snp('\t'.join(['42', 'A', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry'])))
+        to_add = snp.Snp('\t'.join(['43', 'C', '.', '100', 'x', 'x', '300', '400', 'x', 'x', 'ref', 'qry']))
+        expected = copy.copy(deletion)
+        # coords stored zero-based, so subtract 1 from the real expected coords
+        expected.ref_start = 41
+        expected.ref_end = 42
+        expected.ref_length = 300
+        expected.ref_name = 'ref'
+        expected.ref_base = 'AC'
+        expected.qry_start = 99
+        expected.qry_end = 99
+        expected.qry_length = 400
+        expected.qry_name = 'qry'
+        expected.qry_base = '.'
+        self.assertTrue(deletion.update_indel(to_add))
+        self.assertEqual(expected, deletion)
+
diff --git a/pymummer/variant.py b/pymummer/variant.py
new file mode 100644
index 0000000..de0a223
--- /dev/null
+++ b/pymummer/variant.py
@@ -0,0 +1,82 @@
+class Error (Exception): pass
+
+SNP = 1
+DEL = 2
+INS = 3
+
+var_types = {
+    1: 'SNP',
+    2: 'DEL',
+    3: 'INS',
+}
+
+
+class Variant:
+    def __init__(self, snp):
+        '''Create a Variant object from a pymummer.snp.Snp object'''
+        if snp.ref_base == '.':
+            self.var_type = INS
+            self.qry_base = snp.qry_base
+            self.ref_base = '.'
+        elif snp.qry_base == '.':
+            self.var_type = DEL
+            self.qry_base = '.'
+            self.ref_base = snp.ref_base
+        elif '.' not in [snp.ref_base, snp.qry_base]:
+            self.var_type = SNP
+            self.ref_base = snp.ref_base
+            self.qry_base = snp.qry_base
+        else:
+            raise Error('Error constructing Variant from pymummer.snp.Snp:' + str(snp))
+
+        self.ref_start = snp.ref_pos
+        self.ref_end = snp.ref_pos
+        self.ref_length = snp.ref_length
+        self.ref_name = snp.ref_name
+        self.qry_start = snp.qry_pos
+        self.qry_end = snp.qry_pos
+        self.qry_length = snp.qry_length
+        self.qry_name = snp.qry_name
+
+
+    def __eq__(self, other):
+        return type(other) is type(self) and self.__dict__ == other.__dict__
+
+
+    def __str__(self):
+        return '\t'.join([
+            str(self.ref_start + 1),
+            str(self.ref_end + 1),
+            str(self.ref_length),
+            str(self.ref_name),
+            self.ref_base,
+            str(self.qry_start + 1),
+            str(self.qry_end + 1),
+            str(self.qry_length),
+            str(self.qry_name),
+            self.qry_base
+        ])
+
+    def update_indel(self, nucmer_snp):
+        '''Indels are reported over multiple lines, 1 base insertion or deletion per line. This method extends the current variant by 1 base if it's an indel and adjacent to the new SNP and returns True. If the current variant is a SNP, does nothing and returns False'''
+        new_variant = Variant(nucmer_snp)
+        if self.var_type not in [INS, DEL] \
+          or self.var_type != new_variant.var_type \
+          or self.qry_name != new_variant.qry_name \
+          or self.ref_name != new_variant.ref_name:
+            return False
+        if self.var_type == INS \
+          and self.ref_start == new_variant.ref_start \
+          and self.qry_end + 1 == new_variant.qry_start:
+            self.qry_base += new_variant.qry_base
+            self.qry_end += 1
+            return True
+        if self.var_type == DEL \
+          and self.qry_start == new_variant.qry_start \
+          and self.ref_end + 1 == new_variant.ref_start:
+            self.ref_base += new_variant.ref_base
+            self.ref_end += 1
+            return True
+
+        return False
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..36dcac8
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,45 @@
+import os
+import glob
+import shutil
+import sys
+from setuptools import setup, find_packages
+
+
+required_progs = ['nucmer', 'show-coords', 'show-snps', 'delta-filter']
+found_all_progs = True
+print('Checking MUMmer programs found in path:')
+
+for program in required_progs:
+    if shutil.which(program) is None:
+        found_all_progs = False
+        found = '   NOT FOUND'
+    else:
+        found = '          OK'
+
+    print(found, program, sep='\t')
+
+
+if not found_all_progs:
+    print('Cannot install because some programs from the MUMer package not found.', file=sys.stderr)
+    sys.exit(1)
+
+
+setup(
+    name='pymummer',
+    version='0.6.1',
+    description='Wrapper for MUMmer',
+    packages = find_packages(),
+    author='Martin Hunt, Nishadi De Silva',
+    author_email='path-help at sanger.ac.uk',
+    url='https://github.com/sanger-pathogens/pymummer',
+    test_suite='nose.collector',
+    install_requires=['pyfastaq >= 3.10.0'],
+    tests_require=['nose >= 1.3'],
+    license='GPLv3',
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Topic :: Scientific/Engineering :: Bio-Informatics',
+        'Programming Language :: Python :: 3 :: Only',
+        'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
+    ],
+)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-pymummer.git



More information about the debian-med-commit mailing list