changeset 2:ac1ecf12863a draft default tip

Uploaded
author bitlab
date Thu, 13 Dec 2018 08:57:14 -0500
parents 35af401890c0
children
files IMSAME/IMSAME.xml IMSAME/LICENSE IMSAME/bin/IMSAME IMSAME/bin/all_vs_all_metagenomes_IMSAME.sh IMSAME/bin/combine IMSAME/bin/revComp IMSAME/src/IMSAME.c IMSAME/src/Makefile IMSAME/src/alignmentFunctions.c IMSAME/src/alignmentFunctions.h IMSAME/src/combine_reads.c IMSAME/src/commonFunctions.c IMSAME/src/commonFunctions.h IMSAME/src/covident.c IMSAME/src/reverseComplement.c IMSAME/src/structs.h
diffstat 16 files changed, 4177 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/IMSAME.xml	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,15 @@
+<tool id="IMSAME" name="IMSAME">
+   <description>A Pairwise Incremental Multi-Staged Alignment Method for Metagenomes Comparison</description>
+   <inputs>
+      <param name="query" type="data" format="fasta" label="Query metagenome" help="Query sequence file in fasta format" />
+      <param name="db" type="data" format="fasta" label="Reference metagenome" help="Reference sequence file in fasta format" />
+      <param name="evalue" type="text" size="30" value="10e-10" label="Evalue" help="Evalue for filtering HSPs" />
+      <param name="coverage" type="float" value="0.5" label="Coverage" help="Minimum coverage to accept an alignment" />
+      <param name="identity" type="float" value="0.5" label="Identity" help="Minimum identity to accept an alignment" />
+      <param name="kmer" type="integer" value="12" label="Word size" help="Word size for heuristicly exploring the search space" />
+   </inputs>
+   <command>/home/galaxy-bitlab/galaxy/tools/IMSAME/bin/IMSAME -query $query -db $db -evalue $evalue -coverage $coverage -identity $identity -kmer $kmer -out $output --full</command>
+  <outputs>
+      <data name="output" type="txt" label="Output alignments"/>
+  </outputs>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/LICENSE	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,674 @@
+                    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>.
Binary file IMSAME/bin/IMSAME has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/bin/all_vs_all_metagenomes_IMSAME.sh	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+DIR=$1
+COV=$2
+SIM=$3
+THR=$4
+EXT=$5
+OUT=$6
+
+
+BINDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+array=()
+x=0
+
+echo "WARNING: FULL COMPARISON IS ENABLED"
+
+if [ $# != 6 ]; then
+	echo "***ERROR*** Use: $0 metagenomes_directory coverage similarity threads file_extension outpath"
+	exit -1
+fi
+
+for elem in $(ls -d $DIR/*.$EXT | awk -F "/" '{print $NF}' | awk -F ".$EXT" '{print $1}')
+do
+	array[$x]=$elem
+	x=`expr $x + 1`
+	#echo "X: $elem"
+done
+
+for ((i=0 ; i < ${#array[@]} ; i++))
+do
+	for ((j=i ; j < ${#array[@]} ; j++))
+	do
+		if [ $i != $j ]; then
+			seqX=${array[$i]}
+			seqY=${array[$j]}
+			#echo "----------${seqX}-${seqY}-----------"
+			if [[ ! -f $6/${seqX}-${seqY}.align ]];	then #if the file does not exist
+
+				
+				${BINDIR}/IMSAME -query $DIR/${seqX}.$EXT -db $DIR/${seqY}.$EXT -n_threads $THR --full -coverage $COV -identity $SIM -out $6/${seqX}-${seqY}.align
+				grep "(" $6/${seqX}-${seqY}.align | awk '{print $4, $5, $6}' | sed 's/%//g' > $6/${seqX}-${seqY}.align.filtered
+
+				${BINDIR}/covident $6/${seqX}-${seqY}.align.filtered $6/${seqX}-${seqY}.align.filtered.mat
+
+			fi
+			
+			
+
+			
+			
+			if [[ ! -f $6/${seqX}-${seqY}.r.align ]];	then #if the reversed alignment does not exist
+				# Compute reverse complement
+				${BINDIR}/revComp $DIR/${seqY}.$EXT $DIR/${seqY}.r.${EXT}
+				${BINDIR}/IMSAME -query $DIR/${seqX}.$EXT -db $DIR/${seqY}.r.$EXT -n_threads $THR --full -coverage $COV -identity $SIM -out $6/${seqX}-${seqY}.r.align
+				grep "(" $6/${seqX}-${seqY}.r.align | awk '{print $4, $5, $6}' | sed 's/%//g' > $6/${seqX}-${seqY}.r.align.filtered
+				
+				${BINDIR}/covident $6/${seqX}-${seqY}.r.align.filtered $6/${seqX}-${seqY}.align.filtered.mat
+			
+			fi
+			
+			
+			
+		fi
+		rm $DIR/${seqY}.r.${EXT}
+	done
+
+done
Binary file IMSAME/bin/combine has changed
Binary file IMSAME/bin/revComp has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/IMSAME.c	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,760 @@
+/*********
+
+File        IMSAME.c
+Author      EPW <estebanpw@uma.es>
+Description Computes an incremental alignment on reads versus reads using n threads
+
+USAGE       Usage is described by calling ./IMSAME --help
+
+
+
+**********/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <ctype.h>
+#include <pthread.h>
+#include "structs.h"
+#include "alignmentFunctions.h"
+#include "commonFunctions.h"
+
+#define MAX(x, y) (((x) > (y)) ? (x) : (y))
+#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
+#define STARTING_SEQS 1000
+#define PIECE_OF_DB_REALLOC 3200000 //half a gigabyte if divided by 8 bytes
+
+
+uint64_t custom_kmer = 12; // Defined as external in structs.h
+
+void init_args(int argc, char ** av, FILE ** query, FILE ** database, FILE ** out_database, uint64_t  * n_threads, long double * minevalue, long double * mincoverage, int * igap, int * egap, long double * minidentity, long double * window, unsigned char * full_comp, uint64_t * custom_kmer, unsigned char * hits_only, uint64_t * n_parts);
+
+int VERBOSE_ACTIVE = 0;
+
+int main(int argc, char ** av){
+
+
+    
+
+
+    clock_t begin, end;
+    
+    int error; //To tell if threads could not be launched
+    uint64_t i,j;
+
+    //query to read kmers from, database to find seeds
+    FILE * query = NULL, * database = NULL, * out_database = NULL;
+    long double minevalue = 1/powl(10, 10); //Default 1 * 10^-10
+    
+    long double mincoverage = 0.5, minidentity = 0.5, window = 0.15; //Default
+    int igap = -5, egap = -2;
+    unsigned char full_comp = FALSE;
+    unsigned char hits_only = FALSE;
+
+    uint64_t n_threads = 4;
+    uint64_t n_parts = 3; // Default is 3
+
+    init_args(argc, av, &query, &database, &out_database, &n_threads, &minevalue, &mincoverage, &igap, &egap, &minidentity, &window, &full_comp, &custom_kmer, &hits_only, &n_parts);
+    
+    //uint64_t reads_per_thread;
+    uint64_t sum_accepted_reads = 0;
+
+    begin = clock();
+
+    fprintf(stdout, "[INFO] Init. quick table\n");
+
+    pthread_t * threads = (pthread_t *) malloc(n_threads * sizeof(pthread_t));
+    if(threads == NULL) terror("Could not create threads");
+
+    pthread_t * loading_threads = (pthread_t *) malloc(FIXED_LOADING_THREADS * sizeof(pthread_t));
+    if(loading_threads == NULL) terror("Could not create loading threads");
+
+
+    HashTableArgs * hta = (HashTableArgs *) malloc(n_threads*sizeof(HashTableArgs));
+    if(hta == NULL) terror("Could not allocate arguments for hash table");
+    
+    pthread_mutex_t lock; //The mutex to lock the queue
+    if (pthread_mutex_init(&lock, NULL) != 0) terror("Could not init mutex");
+
+    // To be used if only computing hits
+    uint64_t ** hits_table = NULL;
+
+    unsigned char ** my_x = (unsigned char **) malloc(n_threads * sizeof(unsigned char*));
+    unsigned char ** my_y = (unsigned char **) malloc(n_threads * sizeof(unsigned char*));
+
+    unsigned char ** marker_taggs = NULL; // To be used with full comparison
+
+    struct positioned_cell ** mc = (struct positioned_cell **) malloc(n_threads * sizeof(struct positioned_cell *));
+    struct cell *** table = (struct cell ***) malloc(n_threads * sizeof(struct cell **));
+    if(table == NULL) terror("Could not allocate NW table");
+    char ** reconstruct_X = (char **) malloc(n_threads * sizeof(char *));
+    char ** reconstruct_Y = (char **) malloc(n_threads * sizeof(char *));
+    if(reconstruct_Y == NULL || reconstruct_X == NULL) terror("Could not allocate output alignment sequences");
+    char ** writing_buffer_alignment = (char **) malloc(n_threads * sizeof(char*));
+    for(i=0;i<n_threads;i++){
+	
+    	table[i] = (struct cell **) malloc(MAX_READ_SIZE * sizeof(struct cell *));
+	    for(j=0;j<MAX_READ_SIZE;j++){
+            table[i][j] = (struct cell *) malloc((1+MAX_WINDOW_SIZE)*sizeof(struct cell));
+		    if(table[i][j] == NULL) terror("Could not allocate memory for second loop of table");
+            // Delete this 
+            /*
+            uint64_t r;
+            for(r=0;r<MAX_WINDOW_SIZE+1;r++){
+                table[i][j][r].score = INT64_MIN;
+                table[i][j][r].xfrom = 10000000000;
+                table[i][j][r].yfrom = 10000000000;
+            }
+            */
+	    }
+    	mc[i] = (struct positioned_cell *) malloc(MAX_READ_SIZE * sizeof(struct positioned_cell));
+    	my_x[i] = (unsigned char *) malloc(2*MAX_READ_SIZE * sizeof(unsigned char));
+    	my_y[i] = (unsigned char *) malloc(2*MAX_READ_SIZE * sizeof(unsigned char));
+    	reconstruct_X[i] = (char *) malloc(2*MAX_READ_SIZE * sizeof(char));
+    	reconstruct_Y[i] = (char *) malloc(2*MAX_READ_SIZE * sizeof(char));
+	    writing_buffer_alignment[i] = (char *) malloc(6*MAX_READ_SIZE*sizeof(char)); //6 times because of 2 times the length of the max of the read, and that happens 3 times (seqX,align,Y)
+	    if(table[i] == NULL || mc[i] == NULL || my_x[i] == NULL || my_y[i] == NULL || reconstruct_X[i] == NULL || reconstruct_Y[i] == NULL || writing_buffer_alignment[i] == NULL) terror("Could not allocate buffer for alignment output");
+    }
+
+
+
+    end = clock();
+    fprintf(stdout, "[INFO] Initialization took %e seconds.\n", (double)(end-begin)/CLOCKS_PER_SEC);
+
+    //Variables to account for positions
+    //Print info
+    fprintf(stdout, "[INFO] Loading database.\n");
+    //Variables to read kmers
+    char c = 'N'; //Char to read character
+    //Current length of array and variables for the buffer
+    uint64_t idx = 0, r = 0;
+    
+    //Vector to read in batches
+    char * temp_seq_buffer = NULL;
+    if ((temp_seq_buffer = calloc(READBUF, sizeof(char))) == NULL) {
+        terror("Could not allocate memory for read buffer");
+    }
+    //Vector to store database seq
+    unsigned char ** seq_vector_database = (unsigned char **) malloc(FIXED_LOADING_THREADS*sizeof(unsigned char *));
+    if(seq_vector_database == NULL) terror("Could not allocate memory for database vector");
+    uint64_t ** database_positions = (uint64_t **) malloc(FIXED_LOADING_THREADS*sizeof(uint64_t));
+    if(database_positions == NULL) terror("Could not allocate database sequences positions");
+
+    //Mempool_l * mp = (Mempool_l *) malloc(MAX_MEM_POOLS*sizeof(Mempool_l));
+    //if(mp == NULL) terror("Could not allocate vectors for memory pools");
+    //Mempool_l mp[FIXED_LOADING_THREADS][MAX_MEM_POOLS];
+
+    
+    Mempool_l ** mp = (Mempool_l **) malloc(FIXED_LOADING_THREADS*sizeof(Mempool_l *));
+    if(mp == NULL) terror("Could not allocate memory pools");
+    for(i=0; i<FIXED_LOADING_THREADS; i++){
+        mp[i] = (Mempool_l *) malloc(MAX_MEM_POOLS*sizeof(Mempool_l));
+        if(mp[i] == NULL) terror("Could not allocate individual memory pools");
+    }
+
+    Mempool_AVL ** mp_AVL = (Mempool_AVL **) malloc(FIXED_LOADING_THREADS*sizeof(Mempool_AVL *));
+    if(mp_AVL == NULL) terror("Could not allocate memory AVL pools");
+    for(i=0; i<FIXED_LOADING_THREADS; i++){
+        mp_AVL[i] = (Mempool_AVL *) malloc(MAX_MEM_POOLS*sizeof(Mempool_AVL));
+        if(mp_AVL[i] == NULL) terror("Could not allocate individual memory AVL pools");
+    }
+    
+
+    AVLContainer * ct_A = (AVLContainer *) calloc(1, sizeof(AVLContainer));
+    if(ct_A == NULL) terror("Could not allocate container A");
+    AVLContainer * ct_B = (AVLContainer *) calloc(1, sizeof(AVLContainer));
+    if(ct_B == NULL)    terror("Could not allocate container B");
+    AVLContainer * ct_C = (AVLContainer *) calloc(1, sizeof(AVLContainer));
+    if(ct_C == NULL) terror("Could not allocate container C");
+    AVLContainer * ct_D = (AVLContainer *) calloc(1, sizeof(AVLContainer));
+    if(ct_D == NULL) terror("Could not allocate container D");
+
+
+    SeqInfo data_database[FIXED_LOADING_THREADS];
+    uint64_t full_db_n_seqs = 0;
+    
+    
+    unsigned char curr_kmer[custom_kmer];
+    unsigned char aux_kmer[custom_kmer+1];
+    curr_kmer[0] = '\0';
+    uint64_t word_size = 0;
+
+    
+    SeqInfo data_query;
+    
+    //To force reading from the buffer
+    idx = READBUF + 1;
+    
+    //Vector to store query seq
+    unsigned char * seq_vector_query = (unsigned char *) malloc(READBUF*sizeof(unsigned char));
+    if(seq_vector_query == NULL) terror("Could not allocate memory for query vector");
+    uint64_t n_realloc_query = 1, pos_in_query = 0, n_seqs_query_realloc = 1;
+    uint64_t * query_positions = (uint64_t *) malloc(INITSEQS*sizeof(uint64_t));
+    if(query_positions == NULL) terror("Could not allocate query sequences positions");
+    
+    
+    
+    // Read number of sequences and load into RAM
+    begin = clock();
+    fseek(database, 0L, SEEK_END);
+    uint64_t db_temp_size = ftell(database);
+    char * load_buffer = (char *) malloc(db_temp_size * sizeof(char));
+    if(load_buffer == NULL) terror("Could not allocate intermediate buffer for threads sequence array");
+    fseek(database, 0L, SEEK_SET);
+
+    if(db_temp_size != fread(load_buffer, sizeof(char), db_temp_size, database)) terror("Could not read full sequence");
+
+    LoadingDBArgs args_DB_load[FIXED_LOADING_THREADS];
+
+
+    args_DB_load[0].data_database = &data_database[0];
+    args_DB_load[1].data_database = &data_database[1];
+    args_DB_load[2].data_database = &data_database[2];
+    args_DB_load[3].data_database = &data_database[3];
+
+    args_DB_load[0].ct = ct_A;
+    args_DB_load[1].ct = ct_B;
+    args_DB_load[2].ct = ct_C;
+    args_DB_load[3].ct = ct_D;
+    for(i=0; i<FIXED_LOADING_THREADS; i++){
+        args_DB_load[i].read_to = 0;
+        args_DB_load[i].read_from = 0;
+    }
+
+    //uint64_t a_fourth = db_temp_size / 4;
+    
+
+    //get_num_seqs_and_length(load_buffer, &full_db_n_seqs, &db_temp_size, args_DB_load);
+
+    end = clock();
+    fprintf(stdout, "[INFO] Loading into RAM took %e seconds.\n", (double)(end-begin)/CLOCKS_PER_SEC);
+    begin = clock();
+    
+    /*
+    char * temp_seq_buffer;
+    SeqInfo * data_database;
+    uint64_t t_len;
+    uint64_t word_size;
+    uint64_t read_from;
+    uint64_t read_to;
+    char thread_id;
+    Mempool_l * mp;
+    uint64_t n_pools_used;
+    */
+
+    // Launch threads to process database
+
+    args_DB_load[0].thread_id = 'A';
+    args_DB_load[1].thread_id = 'B';
+    args_DB_load[2].thread_id = 'C';
+    args_DB_load[3].thread_id = 'D';
+    
+
+    for(i=0; i<FIXED_LOADING_THREADS; i++){
+
+        //seq_vector_database[i] = (unsigned char *) malloc((args_DB_load[i].read_to - args_DB_load[i].read_from)*sizeof(unsigned char));
+        seq_vector_database[i] = (unsigned char *) malloc((READBUF)*sizeof(unsigned char));
+        //database_positions[i] = (uint64_t *) malloc((1+data_database[i].n_seqs)*sizeof(uint64_t));
+        database_positions[i] = (uint64_t *) malloc((INITSEQS)*sizeof(uint64_t));
+        if(seq_vector_database[i] == NULL || database_positions[i] == NULL) terror("Could not allocate memory for individual database vectors");
+        data_database[i].sequences = seq_vector_database[i];
+        
+        
+        //To hold all information related to database
+        args_DB_load[i].n_pools_used = 0;
+        args_DB_load[i].n_pools_used_AVL = 0;
+
+        init_mem_pool_llpos(&mp[i][args_DB_load[i].n_pools_used]);
+        init_mem_pool_AVL(&mp_AVL[i][args_DB_load[i].n_pools_used_AVL]);
+
+        data_database[i].start_pos = database_positions[i];
+        
+        args_DB_load[i].n_allocs = 1;
+        args_DB_load[i].read_from = i * (db_temp_size / 4);
+        args_DB_load[i].read_to = (i+1) * (db_temp_size / 4);
+        args_DB_load[i].temp_seq_buffer = load_buffer;
+        args_DB_load[i].t_len = db_temp_size;
+        args_DB_load[i].word_size = custom_kmer;
+        args_DB_load[i].mp = mp[i];
+        args_DB_load[i].mp_AVL = mp_AVL[i];
+        
+        if( 0 != (error = pthread_create(&loading_threads[i], NULL, load_input, (void *) (&args_DB_load[i])) )){
+            fprintf(stdout, "[@loading] Thread %"PRIu64" returned %d:", i, error); terror("Could not launch");
+        }
+    }
+    
+    //Wait for threads to finish
+    for(i=0;i<FIXED_LOADING_THREADS;i++){
+        pthread_join(loading_threads[i], NULL);
+    }
+
+    // Deallocate memory not needed anymore
+    free(load_buffer);
+    free(loading_threads);
+
+    
+    
+    //fprintf(stdout, "[INFO] WARNING!!!!!!!!! USING NON OVERLAPPING MERS, WHICH IS NOT INCLUDED AS OPTION!!!! DISABLE\n");
+
+    
+
+    
+
+    //data_database.total_len = pos_in_database;
+    //printf("tables have %"PRIu64" %"PRIu64", %"PRIu64" %"PRIu64"\n", data_database[0].total_len, data_database[1].total_len, data_database[2].total_len, data_database[3].total_len);
+    uint64_t full_db_len = data_database[0].total_len + data_database[1].total_len + data_database[2].total_len + data_database[3].total_len;
+    full_db_n_seqs = args_DB_load[0].contained_reads + args_DB_load[1].contained_reads + args_DB_load[2].contained_reads + args_DB_load[3].contained_reads;
+
+    end = clock();
+    fprintf(stdout, "[INFO] Database loaded and of length %"PRIu64" (%"PRIu64" sequences). Hash table building took %e seconds\n", full_db_len, full_db_n_seqs, (double)(end-begin)/CLOCKS_PER_SEC);
+    //close database
+    fclose(database);
+
+    // Allocate marker tags to avoid repeting computation
+    
+    marker_taggs = (unsigned char **) malloc(n_threads * sizeof(unsigned char *));
+    if(marker_taggs == NULL) terror("Could not allocate marker taggs");
+    for(i=0;i<n_threads;i++){
+        marker_taggs[i] = (unsigned char *) malloc(full_db_n_seqs);
+        if(marker_taggs[i] == NULL) terror("Could not allocate second loop of marker taggs");
+    }
+    if(hits_only == TRUE){
+        hits_table = (uint64_t **) calloc(n_threads, sizeof(uint64_t *));
+        if(hits_table == NULL) terror("Could not allocate hits table");
+        uint64_t z;
+        for(z=0;z<n_threads;z++){
+            hits_table[z] = (uint64_t *) calloc(full_db_n_seqs, sizeof(uint64_t));
+            if(hits_table[z] == NULL) terror("Could not allocate sub table of hits");
+        }
+    }
+
+    
+    begin = clock();
+
+    
+
+    //To force reading from the buffer
+    idx = READBUF + 1;
+
+    
+    data_query.sequences = seq_vector_query;
+    data_query.start_pos = query_positions;
+    data_query.total_len = 0;
+    data_query.n_seqs = 0;
+    
+    
+    //Print info
+    fprintf(stdout, "[INFO] Loading query.\n");   
+
+    
+    c = buffered_fgetc(temp_seq_buffer, &idx, &r, query);
+    while((!feof(query) || (feof(query) && idx < r))){
+
+        if(c == '>'){
+            data_query.start_pos[data_query.n_seqs++] = pos_in_query;
+            word_size = 0;
+            
+            if(pos_in_query == READBUF*n_realloc_query){
+                n_realloc_query++; data_query.sequences = (unsigned char *) realloc(data_query.sequences, READBUF*n_realloc_query*sizeof(unsigned char));
+                if(data_query.sequences == NULL) terror("Could not reallocate temporary query");
+            }
+
+            if(data_query.n_seqs == INITSEQS*n_seqs_query_realloc){
+                n_seqs_query_realloc++; data_query.start_pos =  (uint64_t *) realloc(data_query.start_pos, INITSEQS*n_seqs_query_realloc*sizeof(uint64_t));
+            }
+
+
+            while(c != '\n'){ c = buffered_fgetc(temp_seq_buffer, &idx, &r, query); } //Skip ID
+                
+
+            while(c != '>' && (!feof(query) || (feof(query) && idx < r))){ //Until next id
+                c = buffered_fgetc(temp_seq_buffer, &idx, &r, query);
+                c = toupper(c);
+                if(c == 'A' || c == 'C' || c == 'G' || c == 'T'){
+                    data_query.sequences[pos_in_query++] = (unsigned char) c;
+                    curr_kmer[word_size++] = (unsigned char) c;
+                    
+                    if(word_size == custom_kmer){
+                        memcpy(aux_kmer, curr_kmer, custom_kmer);
+                        aux_kmer[custom_kmer] = '\0';
+                        
+                        memcpy(aux_kmer, &curr_kmer[1], custom_kmer-1);
+                        memcpy(curr_kmer, aux_kmer, custom_kmer-1);
+                        word_size--;
+                    }
+            
+                    if(pos_in_query == READBUF*n_realloc_query){ 
+                        n_realloc_query++; data_query.sequences = (unsigned char *) realloc(data_query.sequences, READBUF*n_realloc_query*sizeof(unsigned char));
+                        if(data_query.sequences == NULL) terror("Could not reallocate temporary query");
+                    }
+                }else{
+                    if(c != '\n' && c != '\r' && c != '>'){
+                        word_size = 0;
+                        data_query.sequences[pos_in_query++] = (unsigned char) 'N'; //Convert to N
+                        if(pos_in_query == READBUF*n_realloc_query){ 
+                            n_realloc_query++; data_query.sequences = (unsigned char *) realloc(data_query.sequences, READBUF*n_realloc_query*sizeof(unsigned char));
+                            if(data_query.sequences == NULL) terror("Could not reallocate temporary query");
+                        }
+                    }
+                }
+            }
+        }else{
+            c = buffered_fgetc(temp_seq_buffer, &idx, &r, query);    
+        }
+        
+    }
+
+    
+    
+    end = clock();
+
+    
+    data_query.total_len = pos_in_query;
+
+    fprintf(stdout, "[INFO] Query loaded and of length %"PRIu64". Took %e seconds\n", data_query.total_len, (double)(end-begin)/CLOCKS_PER_SEC);
+
+    begin = clock();
+        
+    Head queue_head;
+    Queue * first_task = generate_queue(&queue_head, data_query.n_seqs, n_threads, n_parts);
+
+    /*
+    Queue * traverse = queue_head.head;
+    while(traverse != NULL){
+        printf("current_piece: %"PRIu64"-%"PRIu64"\n", traverse->r1, traverse->r2);
+        traverse = traverse->next;
+    }
+    getchar();
+    */
+    
+
+
+    //reads_per_thread = (uint64_t) (floorl((long double) data_query.n_seqs / (long double) n_threads));
+    
+    fprintf(stdout, "[INFO] Computing alignments.\n");
+
+    
+
+    /*
+    uint64_t z;
+    for(z=0; z<POOL_SIZE; z++){
+        aux = mp[0].base + z;
+        fprintf(stdout, "%p\n", aux);
+        fflush(stdout);
+    }
+    */
+
+    // Make the full db
+    uint64_t contained_reads[FIXED_LOADING_THREADS] = {0,0,0,0};
+    uint64_t base_coordinates[FIXED_LOADING_THREADS] = {0,0,0,0};
+    //contained_reads[0] = 0;
+    //base_coordinates[0] = 0;
+    for(i=1;i<FIXED_LOADING_THREADS;i++){
+        contained_reads[i] = args_DB_load[i-1].contained_reads + contained_reads[i-1];
+        base_coordinates[i] = args_DB_load[i-1].base_coordinates + base_coordinates[i-1];
+    }
+
+    /*
+    for(i = 0; i < 4 ; i++){
+        printf("total len: %"PRIu64"\n", data_database[i].total_len);
+        
+    }
+    getchar();
+    */
+    /*
+    for(i = 0; i < 4 ; i++){
+        
+        printf("c:%"PRIu64" - b:%"PRIu64"\n", contained_reads[i], base_coordinates[i]);
+    }
+    getchar();
+    */
+    
+
+
+
+    SeqInfo final_db;
+    final_db.sequences = (unsigned char *) malloc(full_db_len * sizeof(unsigned char));
+    if(final_db.sequences == NULL) terror ("Could not allocate final database sequences");
+    memcpy(&final_db.sequences[0], &data_database[0].sequences[0], data_database[0].total_len);
+    memcpy(&final_db.sequences[data_database[0].total_len], &data_database[1].sequences[0], data_database[1].total_len);
+    memcpy(&final_db.sequences[data_database[0].total_len+data_database[1].total_len], &data_database[2].sequences[0], data_database[2].total_len);
+    memcpy(&final_db.sequences[data_database[0].total_len+data_database[1].total_len+data_database[2].total_len], &data_database[3].sequences[0], data_database[3].total_len);
+    final_db.start_pos = (uint64_t *) malloc(full_db_n_seqs * sizeof(uint64_t));
+    if(final_db.start_pos == NULL) terror("Could not allocate final db starting positions");
+    // Copy them with offset
+    i=0;
+    while(i<data_database[0].n_seqs){ final_db.start_pos[i] = data_database[0].start_pos[i]; ++i; }
+    j=0;
+    //printf("switch\n");
+    while(j<data_database[1].n_seqs){ final_db.start_pos[i] = data_database[1].start_pos[j] + data_database[0].total_len; ++i; ++j; }
+    j=0;
+    //printf("switch\n");
+    while(j<data_database[2].n_seqs){ final_db.start_pos[i] = data_database[2].start_pos[j] + data_database[1].total_len + data_database[0].total_len; ++i; ++j; }
+    j=0;
+    //printf("switch\n");
+    while(j<data_database[3].n_seqs){ final_db.start_pos[i] = data_database[3].start_pos[j] + data_database[2].total_len + data_database[1].total_len + data_database[0].total_len; ++i; ++j; }
+    
+    final_db.total_len = full_db_len;
+    final_db.n_seqs = full_db_n_seqs;
+    
+    for(i=0;i<FIXED_LOADING_THREADS;i++){
+        free(data_database[i].sequences);
+        free(data_database[i].start_pos);
+    }
+    
+
+    // Debug
+    /*
+    uint64_t max = 0;
+    for(i=0; i<full_db_n_seqs-2; i++){
+        //printf("%"PRIu64" - %"PRIu64" res in \n", final_db.start_pos[i], final_db.start_pos[i+1]);
+        //printf("%"PRIu64"\n", final_db.start_pos[i+2] - final_db.start_pos[i+1]);
+        if(final_db.start_pos[i+2] - final_db.start_pos[i+1] > max) max = final_db.start_pos[i+2] - final_db.start_pos[i+1];
+        //getchar();
+    }
+    printf("%"PRIu64"\n", max);
+    */
+    
+    
+    
+
+
+    for(i=0;i<n_threads;i++){
+        hta[i].id = i;
+        hta[i].database = &final_db;
+        hta[i].query = &data_query;
+        
+        //hta[i].from = i * reads_per_thread;
+        //hta[i].to = (i + 1) * reads_per_thread;
+        hta[i].container_a = ct_A;
+        hta[i].container_b = ct_B;
+        hta[i].container_c = ct_C;
+        hta[i].container_d = ct_D;
+        hta[i].contained_reads = contained_reads;
+        hta[i].base_coordinates = base_coordinates;
+        hta[i].accepted_query_reads = 0;
+        hta[i].min_e_value = minevalue;
+        hta[i].min_coverage = mincoverage;
+        hta[i].min_identity = minidentity;
+        hta[i].out = out_database;
+        hta[i].igap = igap;
+        hta[i].egap = egap;
+        hta[i].window = window;
+        hta[i].mc = mc[i];
+        hta[i].table = table[i];
+        hta[i].reconstruct_X = reconstruct_X[i];
+        hta[i].reconstruct_Y = reconstruct_Y[i];
+        hta[i].writing_buffer_alignment = writing_buffer_alignment[i];
+        hta[i].my_x = my_x[i];
+        hta[i].my_y = my_y[i];
+        hta[i].queue_head = &queue_head;
+        hta[i].lock = &lock;
+        hta[i].full_comp = full_comp;
+        hta[i].markers = marker_taggs[i];
+        if(hits_only) hta[i].hits = hits_table[i]; else hta[i].hits = NULL;
+        
+
+        //if(i==n_threads-1) hta[i].to = data_query.n_seqs;
+
+        if( 0 != (error = pthread_create(&threads[i], NULL, computeAlignmentsByThread, (void *) (&hta[i])) )){
+            fprintf(stdout, "Thread %"PRIu64" returned %d:", i, error); terror("Could not launch");
+        }
+    }
+    
+    //Wait for threads to finish
+    for(i=0;i<n_threads;i++){
+        pthread_join(threads[i], NULL);
+    }
+
+    
+    for(i=0;i<n_threads;i++){
+        sum_accepted_reads += hta[i].accepted_query_reads;
+    }
+    // Accumulate hits just in case
+    if(hits_only == TRUE){
+        for(i=0;i<full_db_n_seqs;i++){
+            for(j=1;j<n_threads;j++){
+                hta[0].hits[i] += hta[j].hits[i];
+            }
+            if(out_database != NULL){
+                
+                if(i == final_db.n_seqs - 1){
+                    fprintf(out_database, "%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n", i, hta[0].hits[i], full_db_len - final_db.start_pos[i]);
+                }else{
+                    fprintf(out_database, "%"PRIu64"\t%"PRIu64"\t%"PRIu64"\n", i, hta[0].hits[i], final_db.start_pos[i+1] - final_db.start_pos[i]);
+                }
+            }
+        }
+    }
+    
+    
+    end = clock();
+    fprintf(stdout, "[INFO] Alignments computed in %e seconds.\n", (double)(end-begin)/CLOCKS_PER_SEC);
+    fprintf(stdout, "[INFO] %"PRIu64" reads (%"PRIu64") from the query were found in the database (%"PRIu64") at a minimum e-value of %Le and minimum coverage of %d%%.\n", sum_accepted_reads, data_query.n_seqs, final_db.n_seqs, (long double)minevalue, (int) (100*mincoverage));
+    fprintf(stdout, "[INFO] The Jaccard-index is: %Le\n", (long double)sum_accepted_reads/((final_db.n_seqs+data_query.n_seqs)-sum_accepted_reads));
+    fprintf(stdout, "[INFO] Deallocating heap memory.\n");
+
+    fclose(query);
+    
+    if(out_database != NULL) fclose(out_database);
+    free(temp_seq_buffer);
+    
+
+    if(hits_only == TRUE){
+        // Write hits here
+        for(i=0;i<n_threads;i++){
+            free(hits_table[i]);
+        }
+        free(hits_table);
+    }
+
+    free(final_db.sequences);
+    free(final_db.start_pos);
+    free(data_query.sequences);
+    free(data_query.start_pos);
+    free(ct_A->root);
+    free(ct_B->root);
+    free(ct_C->root);
+    free(ct_D->root);
+    //free(ct);
+    free(threads);
+    free(hta);
+
+    
+    
+    for(i=0;i<n_threads;i++){
+        
+        for(j=0;j<MAX_READ_SIZE;j++){
+            free(table[i][j]);
+        }
+        
+        free(table[i]);
+        
+        free(mc[i]);
+        free(reconstruct_X[i]);
+        free(reconstruct_Y[i]);
+        free(my_x[i]);
+        free(my_y[i]);
+        free(writing_buffer_alignment[i]);
+
+        free(marker_taggs[i]);
+        
+    }
+    free(marker_taggs);
+
+    
+    free(table);
+    free(mc);
+    free(reconstruct_X);
+    free(reconstruct_Y);
+    free(my_y);
+    free(my_x);
+    free(writing_buffer_alignment);
+
+    pthread_mutex_destroy(&lock);
+
+    
+
+    for(i=0; i<FIXED_LOADING_THREADS; i++){
+        for(j=0;j<=args_DB_load[i].n_pools_used;j++){
+            free(mp[i][j].base);
+        }
+        free(mp[i]);
+    }
+    for(i=0; i<FIXED_LOADING_THREADS; i++){
+        for(j=0;j<=args_DB_load[i].n_pools_used_AVL;j++){
+            free(mp_AVL[i][j].base);
+        }
+        free(mp_AVL[i]);
+    }
+    free(mp);
+    free(mp_AVL);
+    free(seq_vector_database);
+    free(database_positions);
+    
+    //Deallocate queue (its allocated as an array)
+    free(first_task);
+
+    //free(mp);
+    
+    return 0;
+}
+
+void init_args(int argc, char ** av, FILE ** query, FILE ** database, FILE ** out_database, uint64_t  * n_threads, long double * minevalue, long double * mincoverage, int * igap, int * egap, long double * minidentity, long double * window, unsigned char * full_comp, uint64_t * custom_kmer, unsigned char * hits_only, uint64_t * n_parts){
+
+    int pNum = 0;
+    while(pNum < argc){
+        if(strcmp(av[pNum], "--verbose") == 0) VERBOSE_ACTIVE = 1;
+        if(strcmp(av[pNum], "--help") == 0){
+            fprintf(stdout, "USAGE:\n");
+            fprintf(stdout, "           IMSAME -query [query] -db [database]\n");
+            fprintf(stdout, "OPTIONAL:\n");
+            fprintf(stdout, "           -n_threads  [Integer:   0<n_threads] (default 4)\n");
+            fprintf(stdout, "           -evalue     [Double:    0<=pval<1] (default: 1 * 10^-10)\n");
+            fprintf(stdout, "           -coverage   [Double:    0<coverage<=1 (default: 0.5)\n");
+            fprintf(stdout, "           -identity   [Double:    0<identity<=1 (default: 0.5)\n");
+            fprintf(stdout, "           -igap       [Integer:   (default: 5)\n");
+            fprintf(stdout, "           -egap       [Integer:   (default: 2)\n");
+            fprintf(stdout, "           -window     [Double:    0<window<=0.5 (default: 0.15)\n");
+            fprintf(stdout, "           -kmer       [Integer:   k>1 (default 12)]\n");
+	        fprintf(stdout, "		-n_parts    [Integer:	n>0 (default 3)]\n");
+            fprintf(stdout, "           -out        [File path]\n");
+            fprintf(stdout, "           --full      Does not stop at first match and reports all equalities\n");
+            fprintf(stdout, "           --verbose   Turns verbose on\n");
+            fprintf(stdout, "           --help      Shows help for program usage\n");
+            fprintf(stdout, "           --hits      Compute only the non-overlapping hits\n");
+            exit(1);
+        }
+        if(strcmp(av[pNum], "--full") == 0) *full_comp = TRUE;
+        if(strcmp(av[pNum], "--hits") == 0) *hits_only = TRUE;
+	if(strcmp(av[pNum], "-n_parts") == 0) *n_parts = (uint64_t) atoi(av[pNum+1]);
+        if(strcmp(av[pNum], "-query") == 0){
+            *query = fopen64(av[pNum+1], "rt");
+            if(query==NULL) terror("Could not open query file");
+        }
+        if(strcmp(av[pNum], "-db") == 0){
+            *database = fopen64(av[pNum+1], "rt");
+            if(database==NULL) terror("Could not open database file");
+        }
+        if(strcmp(av[pNum], "-out") == 0){
+            *out_database = fopen64(av[pNum+1], "wt");
+            if(out_database==NULL) terror("Could not open output database file");
+        }
+        if(strcmp(av[pNum], "-evalue") == 0){
+            *minevalue = (long double) atof(av[pNum+1]);
+            if(*minevalue < 0) terror("Min-e-value must be larger than zero");
+        }
+        if(strcmp(av[pNum], "-window") == 0){
+            *window = (long double) atof(av[pNum+1]);
+            if(*window <= 0 || *window > 0.5) terror("Window percentage size must lie between 0<window<=0.5");
+        }
+        if(strcmp(av[pNum], "-coverage") == 0){
+            *mincoverage = (long double) atof(av[pNum+1]);
+            if(*mincoverage <= 0) terror("Min-coverage must be larger than zero");
+        }
+        if(strcmp(av[pNum], "-identity") == 0){
+            *minidentity = (long double) atof(av[pNum+1]);
+            if(*minidentity <= 0) terror("Min-identity must be larger than zero");
+        }
+        if(strcmp(av[pNum], "-igap") == 0){
+            *igap = - (atoi(av[pNum+1]));
+        }
+        if(strcmp(av[pNum], "-egap") == 0){
+            *egap = - (atoi(av[pNum+1]));
+        }
+        if(strcmp(av[pNum], "-n_threads") == 0){
+            *n_threads = (uint64_t) atoi(av[pNum+1]);
+            if(*n_threads < 0) terror("Number of threads must be larger than zero");
+        }
+        if(strcmp(av[pNum], "-kmer") == 0){
+            *custom_kmer = (uint64_t) atoi(av[pNum+1]);
+            if(*custom_kmer < 2) terror("K-mer size must be larger than 1");
+        }
+        pNum++;
+    }
+    
+    if(*query==NULL || *database==NULL) terror("A query and database is required");
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/Makefile	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,23 @@
+CC=gcc
+CXX=g++
+CFLAGS=-O3 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -Wall #-DVERBOSE
+BIN=../bin
+
+all: IMSAME revcomp combine covident
+
+
+
+IMSAME: IMSAME.c
+	$(CC) $(CFLAGS) alignmentFunctions.c -lpthread -lm commonFunctions.c -msse -lm IMSAME.c -lpthread -lm -o $(BIN)/IMSAME
+	
+revcomp: reverseComplement.c
+	$(CC) $(CFLAGS) commonFunctions.c -lm  reverseComplement.c -o $(BIN)/revComp
+	
+combine: combine_reads.c
+	$(CC) $(CFLAGS) commonFunctions.c -lm combine_reads.c -o $(BIN)/combine
+
+covident: covident.c
+	$(CC) $(CFLAGS) covident.c -o $(BIN)/combine
+
+clean:
+	rm -rf $(BIN)/IMSAME $(BIN)/revComp $(BIN)/combine
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/alignmentFunctions.c	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,1718 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <pthread.h>
+#include <inttypes.h>
+#include <math.h>
+#include <float.h>
+#include "structs.h"
+#include "alignmentFunctions.h"
+#include "commonFunctions.h"
+#define MAX(x, y) (((x) > (y)) ? (x) : (y))
+#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
+
+int64_t compare_letters(unsigned char a, unsigned char b){
+    if(a != (unsigned char) 'N' && a != (unsigned char) '>') return (a == b) ? POINT : -POINT;
+    return -POINT;
+}
+
+llpos * getNewLocationllpos(Mempool_l * mp, uint64_t * n_pools_used){
+
+    if(mp[*n_pools_used].current == POOL_SIZE){
+        *n_pools_used += 1;
+        if(*n_pools_used == MAX_MEM_POOLS) terror("Reached max pools");
+        init_mem_pool_llpos(&mp[*n_pools_used]);
+        
+    }
+
+    llpos * new_pos = mp[*n_pools_used].base + mp[*n_pools_used].current;
+    mp[*n_pools_used].current++;
+
+    
+    return new_pos;
+}
+
+void init_mem_pool_llpos(Mempool_l * mp){
+    mp->base = (llpos *) calloc(POOL_SIZE, sizeof(llpos));
+    if(mp->base == NULL) terror("Could not request memory pool");
+    mp->current = 0;
+}
+
+
+void * load_input(void * a){
+
+    LoadingDBArgs * ldbargs = (LoadingDBArgs *) a;
+    
+    // Requires
+    /*
+    char * temp_seq_buffer;
+    SeqInfo * data_database; 1 per thread
+    uint64_t t_len;
+    uint64_t word_size;
+    uint64_t read_from;
+    uint64_t read_to;
+    char thread_id;
+    */
+
+    uint64_t c_pos;
+    
+    unsigned char curr_kmer[custom_kmer];
+    unsigned char aux_kmer[custom_kmer+1];
+    curr_kmer[0] = '\0';
+    uint64_t word_size = 0, pos_in_database = 0;
+    unsigned char char_converter[91];
+    uint64_t curr_seq = 0;
+    char_converter[(unsigned char)'A'] = 0;
+    char_converter[(unsigned char)'C'] = 1;
+    char_converter[(unsigned char)'G'] = 2;
+    char_converter[(unsigned char)'T'] = 3;
+    //llpos * aux;
+    AVLTree * pointer;
+
+    char c;
+
+    /*
+    if(ldbargs->thread_id == 'A'){
+        printf("read to is: %"PRIu64"\n", ldbargs->read_to);
+        printf("make sure: %c %c %c\n", ldbargs->temp_seq_buffer[ldbargs->read_to-1], ldbargs->temp_seq_buffer[ldbargs->read_to], ldbargs->temp_seq_buffer[ldbargs->read_to+1]);
+        
+        uint64_t z = ldbargs->read_to-1;
+        while(ldbargs->temp_seq_buffer[z] != '>'){
+            printf("%c", ldbargs->temp_seq_buffer[z]);
+            z--;
+        }
+        getchar();
+    }
+    if(ldbargs->thread_id == 'C'){
+        printf("HELLOOOOOOO im going from %"PRIu64"\n", ldbargs->read_from);
+    }
+    */
+
+    c_pos = ldbargs->read_from;
+    while(ldbargs->temp_seq_buffer[c_pos] != '>') ++c_pos;
+    ldbargs->read_from = c_pos;
+    c_pos = ldbargs->read_to;
+    while(c_pos < ldbargs->t_len && ldbargs->temp_seq_buffer[c_pos] != '>') ++c_pos;
+    ldbargs->read_to = c_pos;
+
+    c_pos = ldbargs->read_from;
+    c = ldbargs->temp_seq_buffer[c_pos];
+
+    
+    //printf("thread going from %"PRIu64" to %"PRIu64"\n", ldbargs->read_from, ldbargs->read_to);
+    
+
+    while(c_pos < ldbargs->read_to){
+        
+
+        if(c == '>'){
+            
+            //if(ldbargs->thread_id == 'G') printf("putting in %"PRIu64" @ %"PRIu64"\n", curr_seq, c_pos);
+            ldbargs->data_database->start_pos[curr_seq] = pos_in_database; ++curr_seq;
+
+            // REalloc sequences and sequence index
+            if(pos_in_database == READBUF*ldbargs->n_allocs){
+                ldbargs->n_allocs++; ldbargs->data_database->sequences = (unsigned char *) realloc(ldbargs->data_database->sequences, READBUF*ldbargs->n_allocs*sizeof(unsigned char));
+                if(ldbargs->data_database->sequences == NULL) terror("Could not reallocate temporary database");
+            }
+
+            if(curr_seq == INITSEQS*ldbargs->n_allocs){
+                ldbargs->n_allocs++; ldbargs->data_database->start_pos =  (uint64_t *) realloc(ldbargs->data_database->start_pos, INITSEQS*ldbargs->n_allocs*sizeof(uint64_t));
+            }
+
+
+
+            while(c != '\n'){ c = ldbargs->temp_seq_buffer[c_pos]; ++c_pos; }  //Skip ID
+
+            while(c != '>' && c_pos < ldbargs->read_to){ //Until next id
+
+                //if(ldbargs->thread_id == 'A') printf("!!!!!!%"PRIu64" from:%"PRIu64", to %"PRIu64"\n", c_pos, ldbargs->read_from, ldbargs->read_to);
+                c = ldbargs->temp_seq_buffer[c_pos]; ++c_pos;
+                c = toupper(c);
+                if(c == 'A' || c == 'C' || c == 'G' || c == 'T'){
+                    curr_kmer[word_size] = (unsigned char) c;
+                    if(word_size < custom_kmer) ++word_size;
+
+                    ldbargs->data_database->sequences[pos_in_database] = (unsigned char) c; ++pos_in_database;
+                    // REalloc sequences and sequence index
+                    if(pos_in_database == READBUF*ldbargs->n_allocs){
+                        ldbargs->n_allocs++; ldbargs->data_database->sequences = (unsigned char *) realloc(ldbargs->data_database->sequences, READBUF*ldbargs->n_allocs*sizeof(unsigned char));
+                        if(ldbargs->data_database->sequences == NULL) terror("Could not reallocate temporary database");
+                    }
+
+                    if(curr_seq == INITSEQS*ldbargs->n_allocs){
+                        ldbargs->n_allocs++; ldbargs->data_database->start_pos =  (uint64_t *) realloc(ldbargs->data_database->start_pos, INITSEQS*ldbargs->n_allocs*sizeof(uint64_t));
+                    }
+                }else{ //It can be anything (including N, Y, X ...)
+
+                    if(c != '\n' && c != '\r' && c != '>'){
+                        word_size = 0;
+                        ldbargs->data_database->sequences[pos_in_database] = (unsigned char) 'N'; ++pos_in_database; //Convert to N
+                        // REalloc sequences and sequence index
+                        if(pos_in_database == READBUF*ldbargs->n_allocs){
+                            ldbargs->n_allocs++; ldbargs->data_database->sequences = (unsigned char *) realloc(ldbargs->data_database->sequences, READBUF*ldbargs->n_allocs*sizeof(unsigned char));
+                            if(ldbargs->data_database->sequences == NULL) terror("Could not reallocate temporary database");
+                        }
+
+                        if(curr_seq == INITSEQS*ldbargs->n_allocs){
+                            ldbargs->n_allocs++; ldbargs->data_database->start_pos =  (uint64_t *) realloc(ldbargs->data_database->start_pos, INITSEQS*ldbargs->n_allocs*sizeof(uint64_t));
+                        }
+                    } 
+                }
+                if(word_size == custom_kmer){
+                    //write to hash table
+                    
+		
+                    pointer = &ldbargs->ct->root[char_converter[curr_kmer[1]]][char_converter[curr_kmer[2]]][char_converter[curr_kmer[3]]]
+                        [char_converter[curr_kmer[4]]][char_converter[curr_kmer[5]]][char_converter[curr_kmer[6]]]
+                        [char_converter[curr_kmer[7]]][char_converter[curr_kmer[8]]][char_converter[curr_kmer[9]]]
+                        [char_converter[curr_kmer[10]]][char_converter[curr_kmer[11]]];
+
+                    
+                    pointer = insert_AVLTree(pointer, hashOfWord(&curr_kmer[FIXED_K], custom_kmer-FIXED_K), ldbargs->mp_AVL, &ldbargs->n_pools_used_AVL, pos_in_database, ldbargs->mp, &ldbargs->n_pools_used, curr_seq-1);
+
+
+
+                    // CURRENTLY USING OVERLAPPING
+                    
+                    memcpy(aux_kmer, &curr_kmer[1], custom_kmer-1);
+                    memcpy(curr_kmer, aux_kmer, custom_kmer-1);
+                    word_size--;
+                        
+                    // For NON OVERLAPPING ENABLE THIS
+                    //word_size = 0;
+                }
+
+            }
+            word_size = 0;
+        }else{
+            c = ldbargs->temp_seq_buffer[c_pos]; ++c_pos;
+        }
+
+    }
+    /*
+    if(ldbargs->thread_id == 'T'){
+        uint64_t j;
+        for(j=0; j < curr_seq-1; j++){
+            printf("%"PRIu64" - %"PRIu64"\n", ldbargs->data_database->start_pos[j], ldbargs->data_database->start_pos[j+1]);
+        }
+    }
+    */
+    /*
+    if(ldbargs->thread_id == 'A'){
+        printf("\nAT %"PRIu64", and pos_database = %"PRIu64"\n", ldbargs->data_database->start_pos[curr_seq-1], pos_in_database);        
+        uint64_t z = pos_in_database;
+        while(z > ldbargs->data_database->start_pos[curr_seq-1]){
+            printf("%c", ldbargs->data_database->sequences[z]);
+            z--;
+        }
+
+        getchar();
+    }
+    */
+
+    ldbargs->data_database->start_pos[curr_seq] = pos_in_database;
+    ldbargs->data_database->total_len = pos_in_database;
+    ldbargs->contained_reads = curr_seq;
+    ldbargs->data_database->n_seqs = curr_seq;
+    ldbargs->base_coordinates = pos_in_database;
+    return NULL;
+}
+
+
+void * computeAlignmentsByThread(void * a){
+
+/*
+typedef struct {
+    SeqInfo * database; //Database sequence and lengths
+    SeqInfo * query;    //Query sequence and lengths
+    uint64_t from;      //Starting READ to compute alignments from
+    uint64_t to;        //End READ to compute alignments from
+    Container * container; //Container to hold the multidimensional array
+    uint64_t accepted_query_reads; //Number of reads that have a fragment with evalue less than specified
+    long double min_e_value;    //Minimum evalue to accept read
+} HashTableArgs;
+*/
+
+    HashTableArgs * hta = (HashTableArgs *) a;
+    Queue * my_current_task = NULL;
+
+    unsigned char char_converter[91];
+    char_converter[(unsigned char)'A'] = 0;
+    char_converter[(unsigned char)'C'] = 1;
+    char_converter[(unsigned char)'G'] = 2;
+    char_converter[(unsigned char)'T'] = 3;
+    Quickfrag qf;
+    int64_t * cell_path_y = (int64_t *) malloc(MAX_READ_SIZE*sizeof(int64_t));
+    if(cell_path_y == NULL) terror("Could not allocate cell paths");
+    
+
+    Point p0, p1, p2, p3; //Points for NW anchored
+    p0.x = 0; p0.y = 0;
+
+    AVLContainer * ptr_table_redirect[4];
+    ptr_table_redirect[0] = hta->container_a;
+    ptr_table_redirect[1] = hta->container_b;
+    ptr_table_redirect[2] = hta->container_c;
+    ptr_table_redirect[3] = hta->container_d;
+    unsigned char current_table = 0;
+
+    
+
+    //To keep track of which reads are we reading
+    uint64_t curr_read, curr_db_seq, xlen, ylen;
+    uint64_t crrSeqL, pos_of_hit = 0xFFFFFFFFFFFFFFFF;
+
+    //Reading from buffer
+    char c;
+    unsigned char curr_kmer[custom_kmer], b_aux[custom_kmer];
+    llpos * aux;
+    AVLTree * pointer;
+
+    // For NW-alignment
+    int NWaligned;
+    uint64_t n_hits, alignments_tried;
+
+    BasicAlignment ba; //The resulting alignment from the NW
+    uint64_t curr_pos = 0; //Reading-head position
+    uint64_t up_to = 0;
+
+    int64_t last_diagonal = INT64_MIN; // Diagonal to skip repeated hits
+    unsigned char already_aligned = FALSE; // To not count more times the same read
+    
+
+    
+
+    //Get next operation in queue
+    while(NULL != ( my_current_task = get_task_from_queue(hta->queue_head, hta->lock))){
+        //Initialize all variables
+        
+        qf.x_start = qf.y_start = qf.t_len = 0;
+        qf.e_value = LDBL_MAX;
+        last_diagonal = INT64_MIN;
+
+        //Starting from
+        curr_read = my_current_task->r1;
+        crrSeqL = 0; pos_of_hit = 0;
+
+        curr_kmer[0] = '\0'; b_aux[0] = '\0';
+        aux = NULL;
+        pointer = NULL;
+
+        NWaligned = 0;
+        n_hits = 0;
+        alignments_tried = 0;
+
+        ba.identities = 0; ba.length = 0; ba.igaps = 0xFFFFFFFFFFFFFFFF; ba.egaps = 0xFFFFFFFFFFFFFFFF;
+        memset(&hta->markers[0], 0, hta->database->n_seqs); // Reset used tags
+        already_aligned = FALSE;
+
+        //Set current header position at the position of the read start (the ">")
+        curr_pos = hta->query->start_pos[curr_read]; //Skip the ">"
+        c = (char) hta->query->sequences[curr_pos];
+
+        //printf("Im doing from %"PRIu64" to %"PRIu64", nseqs=%"PRIu64"\n", my_current_task->r1, my_current_task->r2, hta->query->n_seqs);
+        //getchar();
+
+        while(curr_read < my_current_task->r2 && curr_pos < hta->query->total_len){
+
+            
+            
+            if(curr_read != hta->query->n_seqs) up_to = hta->query->start_pos[curr_read+1]-1; else up_to = hta->query->total_len;
+            //printf("Currrpos: %"PRIu64" up to: %"PRIu64" on read: %"PRIu64"\n", curr_pos, up_to, curr_read);
+
+            if (curr_pos == up_to) { // Comment, empty or quality (+) line
+                crrSeqL = 0; // Reset buffered sequence length
+                #ifdef VERBOSE
+                printf("Read: %"PRIu64" yielded (%d)\n", curr_read, NWaligned);
+                #endif
+                //if(NWaligned == 0){ printf("Read: %"PRIu64" yielded (%d)\n", curr_read, NWaligned);}
+                //printf("Read: %"PRIu64" yielded (%d)\n", curr_read, NWaligned); if(NWaligned == 0) getchar();
+                NWaligned = 0;
+                //fprintf(stdout, "Seq %"PRIu64" has %"PRIu64" hits and tried to align %"PRIu64" times\n", curr_read, n_hits, alignments_tried);
+                //fflush(stdout);
+                n_hits = 0;
+                already_aligned = FALSE;
+                alignments_tried = 0;
+                last_diagonal = INT64_MIN; // This is not perfect but if the diagonal reaches the value then we have an overflow anyway
+                qf.x_start = 0;
+                qf.t_len = 0;
+
+                //if(hta->full_comp == TRUE) memset(&hta->markers[my_current_task->r1], 0, my_current_task->r2 - my_current_task->r1 + 1); // Reset used tags
+                memset(&hta->markers[0], FALSE, hta->database->n_seqs); // Reset used tags
+                
+                curr_read++;
+                //printf("On current read %"PRIu64"\n", curr_read);
+                continue;
+            }
+
+            if(c == 'A' || c == 'C' || c == 'T' || c == 'G'){
+                curr_kmer[crrSeqL] = (unsigned char) c;
+                crrSeqL++;
+            }else{
+                crrSeqL = 0;
+            }
+
+            if (crrSeqL >= custom_kmer) { // Full well formed sequence
+            
+                
+                //printf("comparing hit: %.11s\n", (char *)&curr_kmer[0]);
+                //getchar();
+
+                // Choose table
+                /*
+                if(curr_kmer[0] == (unsigned char) 'A'){
+                    ptr_table_redirect = hta->container_A;
+                }else if(curr_kmer[0] == (unsigned char) 'C'){
+                    ptr_table_redirect = hta->container_C;
+                }else if(curr_kmer[0] == (unsigned char) 'G'){
+                    ptr_table_redirect = hta->container_G;
+                }else{
+                    ptr_table_redirect = hta->container_T;
+                }
+                */
+
+                //fprintf(stdout, "%s\n", curr_kmer);
+                //fflush(stdout);
+                current_table = 0;
+                pointer = &ptr_table_redirect[current_table]->root[char_converter[curr_kmer[1]]][char_converter[curr_kmer[2]]][char_converter[curr_kmer[3]]]
+                        [char_converter[curr_kmer[4]]][char_converter[curr_kmer[5]]][char_converter[curr_kmer[6]]]
+                        [char_converter[curr_kmer[7]]][char_converter[curr_kmer[8]]][char_converter[curr_kmer[9]]]
+                        [char_converter[curr_kmer[10]]][char_converter[curr_kmer[11]]];
+
+                if(pointer == NULL){
+                    ++current_table;
+                    pointer = &ptr_table_redirect[current_table]->root[char_converter[curr_kmer[1]]][char_converter[curr_kmer[2]]][char_converter[curr_kmer[3]]]
+                        [char_converter[curr_kmer[4]]][char_converter[curr_kmer[5]]][char_converter[curr_kmer[6]]]
+                        [char_converter[curr_kmer[7]]][char_converter[curr_kmer[8]]][char_converter[curr_kmer[9]]]
+                        [char_converter[curr_kmer[10]]][char_converter[curr_kmer[11]]];
+                }
+                if(pointer == NULL){
+                    ++current_table;
+                    pointer = &ptr_table_redirect[current_table]->root[char_converter[curr_kmer[1]]][char_converter[curr_kmer[2]]][char_converter[curr_kmer[3]]]
+                        [char_converter[curr_kmer[4]]][char_converter[curr_kmer[5]]][char_converter[curr_kmer[6]]]
+                        [char_converter[curr_kmer[7]]][char_converter[curr_kmer[8]]][char_converter[curr_kmer[9]]]
+                        [char_converter[curr_kmer[10]]][char_converter[curr_kmer[11]]];
+                }
+                if(pointer == NULL){
+                    ++current_table;
+                    pointer = &ptr_table_redirect[current_table]->root[char_converter[curr_kmer[1]]][char_converter[curr_kmer[2]]][char_converter[curr_kmer[3]]]
+                        [char_converter[curr_kmer[4]]][char_converter[curr_kmer[5]]][char_converter[curr_kmer[6]]]
+                        [char_converter[curr_kmer[7]]][char_converter[curr_kmer[8]]][char_converter[curr_kmer[9]]]
+                        [char_converter[curr_kmer[10]]][char_converter[curr_kmer[11]]];
+                }
+
+                //While there are hits
+                //fprintf(stdout, "%p\n", aux);
+                //fflush(stdout);
+                
+                uint64_t hash_forward = hashOfWord(&curr_kmer[FIXED_K], custom_kmer - FIXED_K);
+                AVLTree * search = find_AVLTree(pointer, hash_forward);
+                if(search != NULL) aux = search->next; else aux = NULL;
+                
+
+                while(aux != NULL && ((hta->full_comp == FALSE && NWaligned == 0 && hta->markers[aux->s_id+ hta->contained_reads[current_table]] == 0) || (hta->full_comp && hta->markers[aux->s_id+ hta->contained_reads[current_table]] == 0))){
+
+                    n_hits++;
+                    //fprintf(stdout, "%p\n", aux);
+                    //fflush(stdout);
+                    // ADD OFFSET CUCOOOOOOOOOOOOOOOOOOOOOO!!!!!!!!!!!!!!!
+                    //printf("my current table is %u\n", current_table);
+                    //printf("check this woop: %"PRIu64" - %"PRIu64" - %"PRIu64" - %"PRIu64"\n", aux->s_id, hta->contained_reads[current_table], aux->pos, hta->base_coordinates[current_table]);
+                    curr_db_seq = aux->s_id + hta->contained_reads[current_table];
+                    pos_of_hit = aux->pos + hta->base_coordinates[current_table];
+                    //printf("Pos of hit db: %"PRIu64", seq num %"PRIu64", contained reads: %"PRIu64", contained coord %"PRIu64"\n", pos_of_hit, curr_db_seq, hta->contained_reads[current_table], hta->base_coordinates[current_table]);
+                    if(hta->hits != NULL){
+                        hta->hits[curr_db_seq]++;
+                        goto only_hits; // Count only hits and skip the rest
+                    } 
+                    
+                    //fprintf(stdout, "Launching curr_read: %"PRIu64" @ %"PRIu64", vs curr_db_read: %"PRIu64" @ %"PRIu64": ", curr_read, curr_pos+1, curr_db_seq, pos_of_hit);
+                    /*
+                    if(curr_read == 534) fprintf(stdout, "Launching %"PRIu64" @ %"PRIu64", vs %"PRIu64" @ %"PRIu64": ", curr_read, curr_pos+1, curr_db_seq, pos_of_hit);
+                    */
+                    #ifdef VERBOSE 
+                    fprintf(stdout, "Launching %"PRIu64" @ %"PRIu64", vs %"PRIu64" @ %"PRIu64": ", curr_read, curr_pos+1, curr_db_seq, pos_of_hit);
+                    #endif 
+                    int64_t curr_diagonal = (int64_t)(curr_pos+1) - (int64_t) pos_of_hit;
+
+                    
+                    
+                    if( (last_diagonal != curr_diagonal && !(qf.x_start <= (pos_of_hit + custom_kmer) && pos_of_hit <= (qf.x_start + qf.t_len)))){
+                        
+                        /*
+                        if(curr_db_seq == hta->database->n_seqs-1){
+                            xlen = hta->database->total_len - hta->database->start_pos[curr_db_seq];
+                        }else{
+                            xlen = hta->database->start_pos[curr_db_seq+1] - hta->database->start_pos[curr_db_seq];
+                        }
+                        if(curr_read == hta->query->n_seqs-1){
+                            ylen = hta->query->total_len - hta->query->start_pos[curr_read];
+                        }else{
+                            ylen = hta->query->start_pos[curr_read+1] - hta->query->start_pos[curr_read];
+                        }
+                        */
+                        
+                        /*if(curr_read == 35){
+                            fprintf(stdout, "Launching %"PRIu64" @ %"PRIu64", vs %"PRIu64" @ %"PRIu64": \n", curr_read, curr_pos+1, curr_db_seq, pos_of_hit);
+                            printf("what do you think will happen: %"PRIu64"\n", hta->database->start_pos[curr_db_seq]);
+                            //fprintf(stdout, "lengths: x: %"PRIu64", y: %"PRIu64"\n", xlen, ylen);
+                            getchar();
+                        }*/
+                        
+
+                        //printf("accepted because: \n");
+                        /*if(curr_read % 100 == 0){
+                            fprintf(stdout, "Launching %"PRIu64" @ %"PRIu64", vs %"PRIu64" @ %"PRIu64": \n", curr_read, curr_pos+1, curr_db_seq, pos_of_hit);
+                        }
+                        */
+                        //printf("prev_diag: %"PRId64"- currdiag: %"PRId64"\n", last_diagonal, curr_diagonal);
+                        //printf("\t covers to [%"PRIu64"+%"PRIu64"=%"PRIu64"] [%"PRIu64"] \n", qf.x_start, qf.t_len, qf.x_start+qf.t_len, pos_of_hit); getchar();
+                        if(hta->markers[curr_db_seq] == FALSE){
+
+                            //if(current_table > 0) getchar();
+                            alignmentFromQuickHits(hta->database, hta->query, pos_of_hit, curr_pos+1, curr_read, curr_db_seq, &qf, hta->contained_reads[current_table], hta->base_coordinates[current_table]);
+                            last_diagonal = curr_diagonal;
+                        }else{
+                            qf.e_value = 100000000;
+                        }
+                        
+                        //if(curr_read == 35) printf(" evalue: %Le from %"PRIu64", %"PRIu64" with l: %"PRIu64"\n", qf.e_value, qf.x_start, qf.y_start, qf.t_len);
+                    }else{
+                        
+                        /*if(curr_read == 35){
+                            printf("rejected because: \n");
+                            fprintf(stdout, "UNLaunching %"PRIu64" @ %"PRIu64", vs %"PRIu64" @ %"PRIu64": \n", curr_read, curr_pos+1, curr_db_seq, pos_of_hit);
+                            printf("prev_diag: %"PRId64"- currdiag: %"PRId64"\n", last_diagonal, curr_diagonal);
+                            printf("\t covers to [%"PRIu64"+%"PRIu64"=%"PRIu64"] [%"PRIu64"] \n", qf.x_start, qf.t_len, qf.x_start+qf.t_len, pos_of_hit); getchar();
+                        }*/
+                        
+                        qf.e_value = 100000000;
+                    }
+
+                    #ifdef VERBOSE 
+                    printf(" evalue: %Le %"PRIu64"\n", qf.e_value, qf.t_len);
+                    #endif
+                    //getchar();
+
+
+                    
+
+
+                    //If e-value of current frag is good, then we compute a good gapped alignment
+                    if(qf.e_value < hta->min_e_value /*&& xlen == 799 && ylen == 2497*/){
+                        alignments_tried++;
+                        ba.identities = ba.length = ba.igaps = ba.egaps = 0;
+                        //Compute lengths of reads
+                        if(curr_db_seq == hta->database->n_seqs-1){
+                            xlen = hta->database->total_len - hta->database->start_pos[curr_db_seq];
+                        }else{
+                            xlen = hta->database->start_pos[curr_db_seq+1] - hta->database->start_pos[curr_db_seq];
+                            //printf("!!!\n%"PRIu64", %"PRIu64" :: %"PRIu64"; its db->start_pos[curr_db_seq]  db->start_pos[curr_db_seq+1]  curr_db_seq\n", hta->database->start_pos[curr_db_seq], hta->database->start_pos[curr_db_seq+1], curr_db_seq);
+                        }
+                        if(curr_read == hta->query->n_seqs-1){
+                            ylen = hta->query->total_len - hta->query->start_pos[curr_read];
+                        }else{
+                            ylen = hta->query->start_pos[curr_read+1] - hta->query->start_pos[curr_read];
+                        }
+                        //fprintf(stdout, "lengths: x: %"PRIu64", y: %"PRIu64"\n", xlen, ylen);
+                        //Perform alignment plus backtracking
+                        //void build_alignment(char * reconstruct_X, char * reconstruct_Y, uint64_t curr_db_seq, uint64_t curr_read, HashTableArgs * hta, char * my_x, char * my_y, struct cell ** table, struct cell * mc, char * writing_buffer_alignment, BasicAlignment * ba, uint64_t xlen, uint64_t ylen)
+                        if(xlen > MAX_READ_SIZE || ylen > MAX_READ_SIZE){ printf("(%"PRIu64",%"PRIu64")\n", xlen, ylen); terror("Read size reached for gapped alignment."); }
+                        //fprintf(stdout, "R0 %"PRIu64", %"PRIu64"\n", curr_db_seq, curr_read);
+                        
+                        
+                        #ifdef VERBOSE 
+                        fprintf(stdout, "qfxs %"PRIu64", dbs %"PRIu64", qfys %"PRIu64" qys %"PRIu64"\n", qf.x_start, hta->database->start_pos[curr_db_seq], qf.y_start, hta->query->start_pos[curr_read]);
+                        #endif
+
+                        //fprintf(stdout, "dbFragxs %"PRIu64", dbs %"PRIu64", rFragys %"PRIu64" rys %"PRIu64"\n", qf.x_start, hta->database->start_pos[curr_db_seq], qf.y_start, hta->query->start_pos[curr_read]);
+                        /*
+                        printf("at table: %u\n", current_table);
+                        fprintf(stdout, "Launching curr_read: %"PRIu64" @ %"PRIu64", vs curr_db_read: %"PRIu64" @ %"PRIu64": ", curr_read, curr_pos+1, curr_db_seq, pos_of_hit);
+                        fprintf(stdout, "Launching NW %"PRIu64" @ %"PRIu64", vs %"PRIu64" @ %"PRIu64": \n", curr_read, curr_pos+1, curr_db_seq, pos_of_hit);
+                        printf("have len: %"PRIu64", %"PRIu64"\n", xlen, ylen);
+                        printf("Quickfrag (xs, ys): qf::%"PRIu64", %"PRIu64", tlen:%"PRIu64"\n", qf.x_start, qf.y_start, qf.t_len);
+                        printf("Yea, but start and end of read in db is: %"PRIu64" - %"PRIu64"\n", hta->database->start_pos[curr_db_seq], hta->database->start_pos[curr_db_seq+1]);
+                        */
+
+                        p1.x = qf.x_start - hta->database->start_pos[curr_db_seq];
+                        //p1.y = qf.y_start - hta->query->start_pos[curr_read];
+                        p1.y = qf.y_start - (hta->query->start_pos[curr_read] -1);
+                        p2.x = p1.x + qf.t_len;
+                        p2.y = p1.y + qf.t_len;
+                        p3.x = xlen;
+                        p3.y = ylen;
+
+                        #ifdef VERBOSE
+                        fprintf(stdout, "p0 (%"PRIu64", %"PRIu64") p1 (%"PRIu64", %"PRIu64") p2 (%"PRIu64", %"PRIu64") p3 (%"PRIu64", %"PRIu64")\n", p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
+                        #endif
+                        //fprintf(stdout, "p0 (%"PRIu64", %"PRIu64") p1 (%"PRIu64", %"PRIu64") p2 (%"PRIu64", %"PRIu64") p3 (%"PRIu64", %"PRIu64")\n", p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
+                        
+                        calculate_y_cell_path(p0, p1, p2, p3, cell_path_y);
+
+                        // REMOVE
+                        /*
+                        uint64_t r1,r2;
+                        for(r1=0;r1<MAX_WINDOW_SIZE;r1++){
+                            for(r2=0;r2<MAX_WINDOW_SIZE;r2++){
+                                hta->table[r1][r2].score = INT64_MIN;
+                            }
+                        }
+                        */
+                        
+                        build_alignment(hta->reconstruct_X, hta->reconstruct_Y, curr_db_seq, curr_read, hta, hta->my_x, hta->my_y, hta->table, hta->mc, hta->writing_buffer_alignment, &ba, xlen, ylen, cell_path_y, &hta->window);
+                        
+                        // Set the read to already aligned so that it does not repeat
+                        hta->markers[curr_db_seq] = 1;
+                        
+                        #ifdef VERBOSE
+                        printf("len 1 %"PRIu64", len 2 %"PRIu64"\n", ba.length, ylen);
+                        printf("ident %"PRIu64"\n", ba.identities);
+                        #endif
+
+                        //If is good
+                        if(((long double)(ba.length-(ba.igaps+ba.egaps))/ylen) >= hta->min_coverage && ((long double)ba.identities/(ba.length-(ba.igaps+ba.egaps))) >=  hta->min_identity){
+                            if(already_aligned == FALSE){
+                                hta->accepted_query_reads++;
+                                already_aligned = TRUE;
+                                //printf("accepted: %"PRIu64"\n", hta->accepted_query_reads);
+                            }
+                            
+                            hta->markers[curr_db_seq] = 1;
+                            if(hta->out != NULL){
+                                //printf("Last was: (%"PRIu64", %"PRIu64")\n", curr_read, curr_db_seq);
+                                fprintf(hta->out, "(%"PRIu64", %"PRIu64") : %d%% %d%% %"PRIu64"\n $$$$$$$ \n", curr_read, curr_db_seq, MIN(100,(int)(100*(ba.length-(ba.igaps+ba.egaps))/ylen)), MIN(100,(int)((long double)100*ba.identities/(ba.length-(ba.igaps+ba.egaps)))), ylen);
+                                fprintf(hta->out, "%s", hta->writing_buffer_alignment);
+                                //fprintf(stdout, "(%"PRIu64", %"PRIu64") : %d%% %d%% %"PRIu64"\n $$$$$$$ \n", curr_read, curr_db_seq, MIN(100,(int)(100*ba.identities/ba.length)), MIN(100,(int)(100*ba.length/ylen)), ylen);
+                                //fprintf(stdout, "%s", hta->writing_buffer_alignment);
+                            }
+                            NWaligned = 1;
+                        }/*else{
+                            printf("what: ");
+                            printf("len x %"PRIu64", len y %"PRIu64"\n", xlen, ylen);
+                            printf("ident %"PRIu64" len %"PRIu64"\n", ba.identities, ba.length); getchar();
+                        }*/
+                    
+                    }
+
+                    //strncpy(get_from_db, &hta->database->sequences[qf.x_start], qf.t_len);
+                    //strncpy(get_from_query, &hta->query->sequences[qf.y_start], qf.t_len);
+                    //fprintf(hta->out, "%s\n%s\n%Le\t%d\n-------------------\n", get_from_db, get_from_query, qf.e_value, (int)(100*qf.coverage));
+                    //fprintf(hta->out, "%"PRIu64", %"PRIu64", %"PRIu64"\n", qf.x_start, qf.y_start, qf.t_len);
+
+                    //printf("Hit comes from %"PRIu64", %"PRIu64"\n", pos_of_hit, curr_pos);
+                    only_hits:
+                    aux = aux->next;
+                    while(aux == NULL && current_table < FIXED_LOADING_THREADS-1){
+                        ++current_table;
+                        pointer = &ptr_table_redirect[current_table]->root[char_converter[curr_kmer[1]]][char_converter[curr_kmer[2]]][char_converter[curr_kmer[3]]]
+                        [char_converter[curr_kmer[4]]][char_converter[curr_kmer[5]]][char_converter[curr_kmer[6]]]
+                        [char_converter[curr_kmer[7]]][char_converter[curr_kmer[8]]][char_converter[curr_kmer[9]]]
+                        [char_converter[curr_kmer[10]]][char_converter[curr_kmer[11]]];
+                        hash_forward = hashOfWord(&curr_kmer[FIXED_K], custom_kmer - FIXED_K);
+                        search = find_AVLTree(pointer, hash_forward);
+                        if(search != NULL) aux = search->next; else aux = NULL;
+                    }
+                    //fprintf(stdout, "%p\n", aux);
+                    //fflush(stdout);
+                }
+                //printf("SWITCHED\n");
+
+                if(NWaligned == 1 && hta->full_comp == FALSE){
+                    if(curr_read < hta->query->n_seqs) curr_pos = hta->query->start_pos[curr_read+1]-2;
+                }else{
+                    memcpy(b_aux, curr_kmer, custom_kmer);
+                    memcpy(curr_kmer, &b_aux[1], custom_kmer-1);
+                    crrSeqL -= 1;
+                }
+            }
+            //printf("current pos: %"PRIu64"\n", curr_pos);
+            curr_pos++;
+            if(curr_pos < hta->query->total_len) c = (char) hta->query->sequences[curr_pos];
+            
+
+
+        }
+
+
+
+
+
+    }
+    
+    
+    
+
+    
+    //fprintf(stdout, "Going from %"PRIu64" to %"PRIu64"\n", hta->from, hta->to);
+    //fflush(stdout);
+
+    free(cell_path_y);
+
+    return NULL;
+
+}
+
+void build_alignment(char * reconstruct_X, char * reconstruct_Y, uint64_t curr_db_seq, uint64_t curr_read, HashTableArgs * hta, unsigned char * my_x, unsigned char * my_y, struct cell ** table, struct positioned_cell * mc, char * writing_buffer_alignment, BasicAlignment * ba, uint64_t xlen, uint64_t ylen, int64_t * cell_path_y, long double * window){
+ 
+
+    //Do some printing of alignments here
+    uint64_t maximum_len, i, j, curr_pos_buffer, curr_window_size;
+
+    maximum_len = 2*MAX(xlen,ylen);
+    memcpy(my_x, &hta->database->sequences[hta->database->start_pos[curr_db_seq]], xlen);
+    memcpy(my_y, &hta->query->sequences[hta->query->start_pos[curr_read]], ylen);
+
+    struct best_cell bc = NW(my_x, 0, xlen, my_y, 0, ylen, (int64_t) hta->igap, (int64_t) hta->egap, table, mc, 0, cell_path_y, window, &curr_window_size);
+    backtrackingNW(my_x, 0, xlen, my_y, 0, ylen, table, reconstruct_X, reconstruct_Y, &bc, &i, &j, ba, cell_path_y, curr_window_size);
+    uint64_t offset = 0, before_i = 0, before_j = 0;
+    i++; j++;
+    
+    #ifdef VERBOSE
+    uint64_t z=0;
+    for(z=0;z<maximum_len;z++) printf("%c", reconstruct_X[z]);
+    printf("\n");
+    for(z=0;z<maximum_len;z++) printf("%c", reconstruct_Y[z]);
+    #endif
+    
+    curr_pos_buffer = 0;
+    while(i <= maximum_len && j <= maximum_len){
+        offset = 0;
+        before_i = i;
+        writing_buffer_alignment[curr_pos_buffer++] = 'D';
+        writing_buffer_alignment[curr_pos_buffer++] = '\t';
+        while(offset < ALIGN_LEN && i <= maximum_len){
+            //fprintf(stdout, "%c", reconstruct_X[i]);
+            writing_buffer_alignment[curr_pos_buffer++] = (char) reconstruct_X[i];
+            i++;
+            offset++;
+        }
+        //fprintf(out, "\n");
+        
+        writing_buffer_alignment[curr_pos_buffer++] = '\n';
+        offset = 0;
+        before_j = j;
+        
+        //fprintf(stdout, "\n");
+
+        writing_buffer_alignment[curr_pos_buffer++] = 'Q';
+        writing_buffer_alignment[curr_pos_buffer++] = '\t';
+
+        while(offset < ALIGN_LEN && j <= maximum_len){
+            //fprintf(stdout, "%c", reconstruct_Y[j]);
+            writing_buffer_alignment[curr_pos_buffer++] = (char) reconstruct_Y[j];
+            j++;
+            offset++;
+        }
+        //fprintf(out, "\n");
+        writing_buffer_alignment[curr_pos_buffer++] = '\n';
+        writing_buffer_alignment[curr_pos_buffer++] = ' ';
+        writing_buffer_alignment[curr_pos_buffer++] = '\t';
+        while(before_i < i){
+            if(reconstruct_X[before_i] != '-' && reconstruct_Y[before_j] != '-' && reconstruct_X[before_i] == reconstruct_Y[before_j]){
+                //fprintf(out, "*");
+                writing_buffer_alignment[curr_pos_buffer++] = '*';
+                ba->identities++;
+            }else{
+                //fprintf(out, " ");
+                writing_buffer_alignment[curr_pos_buffer++] = ' ';
+            }
+            before_j++;
+            before_i++;
+        }
+        writing_buffer_alignment[curr_pos_buffer++] = '\n';
+
+    }
+    //fprintf(out, "\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n");
+    writing_buffer_alignment[curr_pos_buffer++] = '\n';
+    writing_buffer_alignment[curr_pos_buffer++] = '\0';
+
+
+}
+
+void alignmentFromQuickHits(SeqInfo * database, SeqInfo * query, uint64_t pos_database, uint64_t pos_query, uint64_t curr_read, uint64_t curr_db_seq, Quickfrag * qf, uint64_t offset_db_reads, uint64_t offset_db_coordinates){
+
+    int64_t read_x_start, read_x_end, read_y_start, read_y_end;
+
+    if(curr_db_seq == database->n_seqs-1){
+        read_x_start = database->start_pos[curr_db_seq];
+	    read_x_end = database->total_len;
+    }else{     
+        read_x_start = database->start_pos[curr_db_seq];
+	    read_x_end = database->start_pos[curr_db_seq+1] - 1;
+    }
+
+    //printf("read x start -> %"PRId64", end -> %"PRId64" btw: %"PRIu64"\n", read_x_start, read_x_end, database->n_seqs);
+
+    if(curr_read == query->n_seqs-1){
+        read_y_start = query->start_pos[curr_read];
+        read_y_end = query->total_len;
+    }else{
+        read_y_start = query->start_pos[curr_read];
+        read_y_end = query->start_pos[curr_read+1] - 1;
+    }
+
+    //printf("db_end %"PRId64" query_end %"PRId64"\n", read_x_end, read_y_end);
+    //printf("pos database: %"PRIu64"\n", pos_database);
+    int64_t curr_pos_db = (int64_t) pos_database;
+    int64_t curr_pos_qy = (int64_t) pos_query;
+    int64_t final_end_x = (int64_t) pos_database - 1, final_start_x = final_end_x - custom_kmer + 1, final_start_y = pos_query - custom_kmer;
+    int64_t score_right = custom_kmer * POINT;
+    int64_t score_left = score_right;
+    int64_t high_left = score_left, high_right = score_right;
+    qf->t_len = custom_kmer;
+    uint64_t idents = custom_kmer;
+
+    /*
+    char le_hit[1000];
+    memcpy(le_hit, &database->sequences[final_start_x], FIXED_K);
+    
+	fprintf(stdout, "HIT: %s\n", le_hit);
+	fflush(stdout);
+    */
+    //printf("final start x: %"PRId64"\n", final_start_x);
+    int keep_going = 1;
+
+    //Forward search
+    while(keep_going == 1){
+        
+        
+        if(score_right > 0 && curr_pos_db < database->total_len && curr_pos_qy < query->total_len){
+            if(curr_pos_db  > read_x_end ||  curr_pos_qy > read_y_end) break;
+            //if(database->sequences[curr_pos_db] == query->sequences[curr_pos_qy]){ score_right+=POINT; idents++; }else{ score_right-=POINT;}
+            if(compare_letters(database->sequences[curr_pos_db], query->sequences[curr_pos_qy]) == POINT){ score_right+=POINT; idents++; }else{ score_right-=POINT;}
+            if(high_right <= score_right){
+                final_end_x = curr_pos_db;
+                high_right = score_right;
+            }
+            curr_pos_db++;
+            curr_pos_qy++;
+        }else{
+            keep_going = 0;
+        }
+    }
+
+    //printf("pos here %"PRIu64" curr_pos_db, curr_pos_query %"PRIu64"\n", curr_pos_db, curr_pos_qy);
+    //printf("final start x: %"PRId64"\n", final_start_x);
+    keep_going = 1;
+    curr_pos_db = pos_database - custom_kmer - 1;
+    curr_pos_qy = pos_query - custom_kmer - 1;
+
+    score_left = high_right;
+
+    //Backward search
+    while(keep_going == 1){
+        
+        if(score_left > 0 && curr_pos_db >= 0 && curr_pos_qy >= 0){
+            if(curr_pos_db < read_x_start || curr_pos_qy < read_y_start ) break;
+            //if(database->sequences[curr_pos_db] == query->sequences[curr_pos_qy]){ score_left+=POINT; idents++; }else{ score_left-=POINT;}
+            if(compare_letters(database->sequences[curr_pos_db], query->sequences[curr_pos_qy]) == POINT){ score_left+=POINT; idents++; }else{ score_left-=POINT;}
+            if(high_left <= score_left){
+                final_start_x = curr_pos_db;
+                final_start_y = curr_pos_qy;
+                //printf("got %"PRIu64" when min is %"PRIu64"\n", final_start_y, read_y_start);
+                high_left = score_left;
+            }
+            curr_pos_db--;
+            curr_pos_qy--;
+        }else{
+            keep_going = 0;
+        }
+    }
+
+    qf->t_len = final_end_x - final_start_x;
+    
+    /*
+    char s1[1000];
+    char s2[1000];
+
+    memcpy(s1, &database->sequences[final_start_x], qf->t_len);
+    memcpy(s2, &query->sequences[final_start_y], qf->t_len);
+    s1[qf->t_len] = '\0';
+    s2[qf->t_len] = '\0';
+    
+	fprintf(stdout, "%s\n%s\n------\n", s1, s2);
+	fflush(stdout);
+
+    printf("the real hit was:\n");
+    memcpy(s1, &database->sequences[pos_database-12+1], 12);
+    memcpy(s2, &query->sequences[pos_query-12+1], 12);
+    s1[12] = '\0';
+    s2[12] = '\0';
+    
+	fprintf(stdout, "%s\n%s\n------\n", s1, s2);
+	fflush(stdout);
+    //getchar();
+    printf("%"PRIu64"\n", idents);
+    */
+    
+    long double rawscore = (idents*POINT) - (qf->t_len - idents)*(POINT);
+
+    long double t_len;
+    if(curr_read == query->n_seqs-1){
+        t_len = (long double) query->total_len - query->start_pos[curr_read];
+    }else{
+        t_len = (long double) query->start_pos[curr_read+1] - query->start_pos[curr_read];
+    }
+    //printf("final start x: %"PRId64"\n", final_start_x);
+    qf->x_start = final_start_x;
+    qf->y_start = final_start_y;
+    qf->e_value = (long double) QF_KARLIN*t_len*database->total_len*expl(-QF_LAMBDA * rawscore);
+    qf->coverage = qf->t_len / t_len;
+
+}
+
+void calculate_y_cell_path(Point p0, Point p1, Point p2, Point p3, int64_t * y_points){
+    
+    //Calculate lines between points
+    uint64_t i;
+
+    #ifdef VERBOSE
+    printf("Built on\n");
+    printf("(%"PRIu64", %"PRIu64")\n", p0.x, p0.y);
+    printf("(%"PRIu64", %"PRIu64")\n", p1.x, p1.y);
+    printf("(%"PRIu64", %"PRIu64")\n", p2.x, p2.y);
+    printf("(%"PRIu64", %"PRIu64")\n", p3.x, p3.y);
+    #endif
+
+    
+
+    if(p0.x > MAX_READ_SIZE){ fprintf(stdout, "LEN error %"PRIu64"\n", p0.x); terror("Reached max length in read for anchoring procedure (1)"); }
+    if(p1.x > MAX_READ_SIZE){ fprintf(stdout, "LEN error %"PRIu64"\n", p1.x); terror("Reached max length in read for anchoring procedure (2)"); }
+    if(p2.x > MAX_READ_SIZE){ fprintf(stdout, "LEN error %"PRIu64"\n", p2.x); terror("Reached max length in read for anchoring procedure (3)"); }
+    if(p3.x > MAX_READ_SIZE){ fprintf(stdout, "LEN error %"PRIu64"\n", p3.x); terror("Reached max length in read for anchoring procedure (4)"); }
+
+    long double deltax, deltay, deltaerr, error;
+    uint64_t y;
+
+    //P0 to P1
+    deltax = p1.x - p0.x;
+    deltay = p1.y - p0.y;
+    if(deltax != 0) deltaerr = fabsl(deltay/deltax); else deltaerr = 0;
+    //printf("Deltas  x: %Le y: %Le Error: %Le\n", deltax, deltay, deltaerr);
+    error = deltaerr - 0.5;
+    y = p0.y;
+
+    for(i=p0.x;i<p1.x;i++){
+        y_points[i] = (int64_t) y;
+        error = error + deltaerr;
+        if(error >= 0.5){
+            y++;
+            error = error - 1;
+        }
+    }
+
+    //P1 to P2
+
+    deltax = p2.x - p1.x;
+    deltay = p2.y - p1.y;
+    if(deltax != 0) deltaerr = fabsl(deltay/deltax); else deltaerr = 0;
+    //printf("Deltas  x: %Le y: %Le Error: %Le\n", deltax, deltay, deltaerr);
+    error = deltaerr - 0.5;
+    y = p1.y;
+
+    for(i=p1.x;i<p2.x;i++){
+        y_points[i] = (int64_t) y;
+        error = error + deltaerr;
+        if(error >= 0.5){
+            y++;
+            error = error - 1;
+        }
+    }
+    
+    //P2 to P3
+
+    deltax = p3.x - p2.x;
+    deltay = p3.y - p2.y;
+    if(deltax != 0) deltaerr = fabsl(deltay/deltax); else deltaerr = 0;
+    //printf("Deltas  x: %Le y: %Le Error: %Le\n", deltax, deltay, deltaerr);
+    error = deltaerr - 0.5;
+    y = p2.y;
+
+    for(i=p2.x;i<p3.x;i++){
+        y_points[i] = (int64_t) y;
+        error = error + deltaerr;
+        if(error >= 0.5){
+            y++;
+            error = error - 1;
+        }
+    }
+
+    /*
+    if(p3.x == 799 && p3.y == 2497){
+        for(i=0;i<p3.x;i++){
+            printf("%"PRIu64": %"PRIu64"\n", i, y_points[i]);
+            if(i % 50 == 0) getchar();
+        }    
+    }
+    */
+
+    #ifdef VERBOSE
+    for(i=0;i<p3.x;i++){
+        printf("%"PRIu64" -> ", y_points[i]);
+        if(i % 50 == 0) getchar();
+    }
+    
+    #endif
+    
+    
+
+}
+
+struct best_cell NW(unsigned char * X, uint64_t Xstart, uint64_t Xend, unsigned char * Y, uint64_t Ystart, uint64_t Yend, int64_t iGap, int64_t eGap, struct cell ** table, struct positioned_cell * mc, int show, int64_t * cell_path_y, long double * window, uint64_t * current_window_size){
+    
+
+    uint64_t i, j, j_prime;
+    int64_t scoreDiagonal = INT64_MIN, scoreLeft = INT64_MIN, scoreRight = INT64_MIN, score = INT64_MIN, delta_dif_1_0, delta_dif_2_1, limit_left, limit_right, j_right_prime = 1, j_left_prime = 1, j_diag_prime = 1;
+
+    struct best_cell bc;
+    bc.c.score = INT64_MIN;
+    bc.c.xpos = 0; bc.c.ypos = 0;
+    
+    //The window size will be a +-15% of the square root of the product of lengths
+    int64_t window_size = MIN(MAX_WINDOW_SIZE/2, (uint64_t) (*window * sqrtl((long double) Xend * (long double) Yend)));
+    //printf("xlen: %"PRIu64", ylen: %"PRIu64" w-size: %"PRId64"\n", Xend, Yend, window_size);    
+    *current_window_size = (uint64_t) window_size;
+
+    //The limits to the window
+    limit_left = 0;
+    limit_right = 2*window_size + 1;
+    if(limit_right > MAX_WINDOW_SIZE) limit_right = MAX_WINDOW_SIZE;
+    
+    struct positioned_cell mf;
+    mf.score = INT64_MIN;
+    
+
+    //First row. iCounter serves as counter from zero
+    //printf("..0%%");
+    //Zero will always be
+    table[0][0].score = compare_letters(X[0], Y[0]);
+    mc[0].score = table[0][0].score;
+    mc[0].xpos = 0;
+    mc[0].ypos = 0;
+    
+    //if(Xend == 799 && Yend == 2497) printf("I am %p The count is real %.5s %.5s %p %p \n", &table[0][0], X, Y, X, Y);
+
+    
+    for(i=1;i<Yend;i++){
+        //table[0][i].score = (X[0] == Y[i]) ? POINT : -POINT;
+        if(i < MAX_WINDOW_SIZE) table[0][i].score = compare_letters(X[0], Y[i]) + iGap + (i-1)*eGap;
+        //table[Xstart][i].xfrom = Xstart;
+        //table[Xstart][i].yfrom = i;
+        //Set every column max
+        mc[i].score = compare_letters(X[0], Y[i]) + iGap + (i-1)*eGap;
+        #ifdef VERBOSE
+        printf("%02"PRId64" ", mc[i].score);
+        #endif
+        mc[i].xpos = 0;
+        mc[i].ypos = i;
+
+    }
+    #ifdef VERBOSE
+    printf("\n");
+    #endif
+    //Set row max
+    mf.score = table[0][0].score;
+    mf.xpos = 0;
+    mf.ypos = 0;
+    //Init j
+    j = MAX(1,(cell_path_y[1] - window_size));
+
+    //Go through full matrix
+    for(i=1;i<Xend;i++){
+        //Fill first rowcell
+        if(cell_path_y[i-1]+window_size < cell_path_y[i]) return bc; //terror("Sequence proportions make window shift too large");
+        //Conversion for the j-coordinate
+        j_prime = 1;
+
+        //table[i][0].score = (X[i] == Y[0]) ? POINT : -POINT;
+        if(cell_path_y[i] - window_size <= 0){
+            table[i][0].score = compare_letters(X[i], Y[0]) + iGap + (i-1)*eGap;
+            mf.score = table[i][0].score;
+        }else{
+            mf.score = compare_letters(X[i], Y[0]) + iGap + (i-1)*eGap;
+        }
+
+        mf.xpos = i-1;
+        mf.ypos = 0;
+
+        delta_dif_1_0 = MAX(1, (cell_path_y[i] - window_size)) - MAX(1,(cell_path_y[i-1] - window_size)); //j-1
+        if(i>1) delta_dif_2_1 = MAX(1, (cell_path_y[i-1] - window_size)) - MAX(1, (cell_path_y[i-2] - window_size)); //j-2
+
+        #ifdef VERBOSE 
+        printf("D1_0: %"PRId64" D2_1: %"PRId64"\n", delta_dif_1_0, delta_dif_2_1);
+        #endif
+
+        #ifdef VERBOSE
+        printf("%02"PRId64" ", mf.score);
+        #endif
+        //printf("Check on i: (%"PRIu64") from - to (%"PRIu64", %"PRIu64")\n", i, 0L, Xend);
+        /*
+        if(1||i==262){
+            printf("I will go from %"PRIu64" to %"PRIu64" and I am %"PRIu64", %"PRIu64"\n", (uint64_t) MAX(1,(cell_path_y[i] - (int64_t)window_size)), (uint64_t) MIN((int64_t)Yend,(cell_path_y[i] + (int64_t)window_size)), i, j);
+            //printf("lengs: %"PRIu64", %"PRIu64"\n", Xend, Yend);
+            //printf("cp[i]: %"PRId64", cp[i-1] %"PRId64"\n", cell_path_y[i], cell_path_y[i-1]);
+            //printf("min(%"PRId64", %"PRId64" + %"PRId64")-------------------\n", Yend, cell_path_y[i] ,(int64_t)window_size);
+            
+        }
+        */
+        //getchar();
+
+        //printf("@%"PRIu64"[%"PRId64"] -> (%"PRIu64", %"PRIu64") jp %"PRIu64", lright %"PRIu64"\n", i, cell_path_y[i], MAX(1,(cell_path_y[i] - window_size)), MIN(Yend,(cell_path_y[i] + window_size)), j_prime, limit_right);
+        //printf("M:@%"PRIu64"-> %"PRIu64"\n", i, MIN(Yend,(cell_path_y[i] + window_size)));
+        #ifdef VERBOSE
+        int64_t r;
+        for(r=0;r<MAX(0,(cell_path_y[i] - window_size)); r++){
+            printf("  ");
+        }
+        #endif
+
+        /*
+        if(Xend == 799 && Yend == 2497 && i >= 145 && i <= 155){
+                printf("them limits @i %"PRIu64"::: %"PRIu64", %"PRIu64"\n", i, MAX(1,(cell_path_y[i] - window_size)), MIN(Yend,(cell_path_y[i] + window_size)));
+                getchar();
+        }
+        */
+        
+
+        for(j=MAX(1,(cell_path_y[i] - window_size));j<MIN(Yend,(cell_path_y[i] + window_size)) && j_prime < limit_right;j++){
+            //if(i == 8302){ printf("Doing on : (%"PRIu64",%"PRIu64" and jprime=%"PRIu64"\n", i,j,j_prime); getchar(); }
+            //Check if max in row has changed
+            //if(j > MAX(1, cell_path_y[i-1] - window_size +1) && mf.score <= table[i][j-2].score){
+            //if(j_prime == MAX_WINDOW_SIZE) break;
+            //Calculate the real j position in the windowed table
+            
+            j_left_prime = ((int64_t)j_prime - (2 - delta_dif_1_0));
+            //j_diag_prime = ((int64_t)j_prime - (1 - delta_dif_1_0));
+            j_diag_prime = ((int64_t)j_prime - (1 - delta_dif_1_0));
+            if(i > 1){
+                j_right_prime = ((int64_t)j_prime - (1 - (delta_dif_1_0 + delta_dif_2_1)));
+            }
+
+            if(j > MAX(1, cell_path_y[i-1] - window_size +1) && j < MIN(Yend,(cell_path_y[i-1] + window_size)) && j_left_prime < limit_right && table[i-1][j_left_prime].score >= mf.score){
+                //mf.score = table[i-1][j-2].score;
+                mf.score = table[i-1][j_left_prime].score;
+                mf.xpos = i-1;
+                mf.ypos = j-2;
+                if(table[i-1][j_left_prime].score == INT64_MIN){ printf("A: mf.x\t%"PRIu64"\tmf.y\t%"PRIu64"\ts%"PRId64"\n", mf.xpos, mf.ypos, mf.score); printf("@[%"PRIu64", %"PRIu64"] with j_prime: %"PRIu64", wsize: %"PRIu64", cp[i-1]=%"PRId64", cp[i]=%"PRId64"\n", i, j, j_prime, 2*window_size, cell_path_y[i-1], cell_path_y[i]); getchar(); }
+                
+            }
+            //printf("RowMax: %"PRId64"@(%"PRIu64", %"PRIu64")\t", mf.score, mf.xpos, mf.ypos);
+            
+            //score = (X[i] == Y[j]) ? POINT : -POINT;
+            score = compare_letters(X[i], Y[j]);
+
+            //Precondition: Upper row needs to reach up to diagonal
+            //if((cell_path_y[i-1]+window_size) >= j-1){
+            if(i > 1 && j >= 1 && j-1 >= MAX(1,(cell_path_y[i-2] - window_size)) && j-1 < MIN(Yend,(cell_path_y[i-2] + window_size)) && j_right_prime >= limit_left && j_right_prime < limit_right && table[i-2][j_right_prime].score >= mc[j-1].score ){
+                //mc[j-1].score = table[i-2][j-(1+j_prime)].score;
+                //Should be the j_prime we had at cell_path_y
+                //MAX(1,(cell_path_y[i] - window_size));j<MIN(Yend,(cell_path_y[i] + window_size))
+                
+                mc[j-1].score = table[i-2][j_right_prime].score;
+                mc[j-1].xpos = i-2;
+                mc[j-1].ypos = j-1;
+
+                if(table[i-2][j_right_prime].score == INT64_MIN){ printf("A: j-1\t%"PRIu64"\tmc.xpos\t%"PRIu64"\ts%"PRId64"\n", j-1, mc[j-1].xpos, mc[j-1].score); printf("@[%"PRIu64", %"PRIu64"] with j_prime: %"PRIu64", wsize: %"PRIu64", cp[i-1]=%"PRId64", cp[i]=%"PRId64"\n", i, j, j_prime, 2*window_size, cell_path_y[i-1], cell_path_y[i]); getchar(); }
+    
+            }
+            
+
+            if(j-1 >= MAX(0, (cell_path_y[i-1]-window_size)) && (cell_path_y[i-1]+window_size) >= j-1 && j_diag_prime >= limit_left && j_diag_prime < limit_right && j_diag_prime < cell_path_y[i-1]+window_size){
+                //scoreDiagonal = table[i-1][j-1].score + score;
+                //printf("prevdiag: %"PRId64"\n", table[i-1][j_diag_prime].score);
+                scoreDiagonal = table[i-1][j_diag_prime].score + score;                
+                if(table[i-1][j_diag_prime].score == INT64_MIN){ printf("A: i-1\t%"PRIu64"\tj_diag\t%"PRIu64"\ts%"PRId64"\n", i-1, j_diag_prime, table[i-1][j_diag_prime].score); printf("@[%"PRIu64", %"PRIu64"] with j_prime: %"PRIu64", wsize: %"PRIu64", cp[i-1]=%"PRId64", cp[i]=%"PRId64"\n", i, j, j_prime, 2*window_size, cell_path_y[i-1], cell_path_y[i]); getchar(); }
+            }else{
+                scoreDiagonal = INT64_MIN;
+            }
+            
+            if(i>=1 && j>1){
+                scoreLeft = mf.score + iGap + (j - (mf.ypos+2))*eGap + score;
+                
+                if(mf.score == INT64_MIN){ printf("A: mf.x\t%"PRIu64"\tmf.y\t%"PRIu64"\ts%"PRId64"\n", mf.xpos, mf.ypos, mf.score); printf("@[%"PRIu64", %"PRIu64"] with j_prime: %"PRIu64", wsize: %"PRIu64", cp[i-1]=%"PRId64", cp[i]=%"PRId64"\n", i, j, j_prime, 2*window_size, cell_path_y[i-1], cell_path_y[i]); getchar(); }
+            }else{
+                scoreLeft = INT64_MIN;
+            }
+
+            if(j>=1 && i>1){
+                scoreRight = mc[j-1].score + iGap + (i - (mc[j-1].xpos+2))*eGap + score;
+                //if(scoreRight == -12) printf("MC: %"PRId64", From: %"PRIu64", %"PRIu64"->", mc[j-1].score, mc[j-1].xpos, mc[j-1].ypos);
+                
+                if(mc[j-1].score == INT64_MIN){ printf("A: j-1\t%"PRIu64"\tmc.xpos\t%"PRIu64"\ts%"PRId64"\n", j-1, mc[j-1].xpos, mc[j-1].score); printf("@[%"PRIu64", %"PRIu64"] with j_prime: %"PRIu64", wsize: %"PRIu64", cp[i-1]=%"PRId64", cp[i]=%"PRId64"\n", i, j, j_prime, 2*window_size, cell_path_y[i-1], cell_path_y[i]); getchar(); }
+            }else{
+                scoreRight = INT64_MIN;
+            }
+            
+            /*
+            if(Xend == 799 && Yend == 2497 && i >= 152 && i == 153){
+                printf("@%"PRIu64", %"PRIu64" -> scores: %"PRId64", %"PRId64", %"PRId64"\n", i, j, scoreDiagonal, scoreRight, scoreLeft);
+                printf("in position @ jprime= %"PRIu64" cellpaths [i-2, i-1, i] are %"PRId64", %"PRId64", %"PRId64", window_size: %"PRId64", j_diag_prime: %"PRId64"\n", j_prime, cell_path_y[i-2], cell_path_y[i-1], cell_path_y[i], window_size, j_diag_prime);
+                printf("Mfs from scoreLeft: mf.x\t%"PRIu64"\tmf.y\t%"PRIu64"\ts%"PRId64"\n", mf.xpos, mf.ypos, mf.score);
+                getchar();
+            }
+            */
+
+            //Choose maximum
+            /*
+            #ifdef VERBOSE
+            printf("The game starts at %"PRId64"\n", MAX(0, cell_path_y[i] - window_size));
+            printf("from %c %c and I get to %"PRIu64" while j=%"PRIu64"\n", X[i], Y[j], j_prime, j);
+            printf("j_prime: %"PRId64"\n", j_prime);
+            printf("j_diag_prime: %"PRId64" limits[%"PRId64", %"PRId64"]\n", j_diag_prime, limit_left, limit_right);
+            printf("Score DIAG: %"PRId64"; LEFT: %"PRId64"; RIGHT: %"PRId64"\n", scoreDiagonal, scoreLeft, scoreRight);
+            printf("currmf: %"PRId64" mc: %"PRId64"\n", mf.score, mc[j-1].score);
+            #endif
+            */
+            
+
+            //if(i >= MAX_READ_SIZE){ printf("i=%"PRIu64"\n", i); terror("i overflowed\n");}
+            //if(j_prime >= MAX_WINDOW_SIZE){ printf("upper : %"PRId64"\n", MIN(Yend,(cell_path_y[i] + window_size-1))); printf("jp=%"PRIu64"\n", j_prime); terror("j overflowed\n"); }
+          
+
+
+            if(scoreDiagonal >= scoreLeft && scoreDiagonal >= scoreRight){
+                //Diagonal
+                
+                //fprintf(stdout, "The JPRIME: %"PRId64" actual pos: %"PRIu64"\n", j_prime, j); getchar();
+                table[i][j_prime].score = scoreDiagonal;
+                table[i][j_prime].xfrom = i-1;
+                table[i][j_prime].yfrom = j-1;
+                
+                                
+            }else if(scoreRight > scoreLeft){
+                table[i][j_prime].score = scoreRight;
+                table[i][j_prime].xfrom = mc[j-1].xpos;
+                table[i][j_prime].yfrom = mc[j-1].ypos;
+                
+            }else{
+                //printf("Scores %"PRId64", %"PRId64", %"PRId64"\n", scoreDiagonal, scoreLeft, scoreRight);
+                table[i][j_prime].score = scoreLeft;
+                table[i][j_prime].xfrom = mf.xpos;
+                table[i][j_prime].yfrom = mf.ypos;
+            }
+            //printf("F: i\t%"PRIu64"\tj_prime\t%"PRIu64"\n", i, j_prime);
+            //getchar();
+            //if(i == 94){ printf("showing j %"PRIu64" jprime %"PRIu64" lleft %"PRIu64", llright %"PRIu64"\n", j, j_prime, limit_left, limit_right); getchar(); }
+            //if(i == 94 && j == 374){ printf("stopped at 94, 374 s %"PRId64"\n", table[i][j_prime].score); getchar(); }
+            
+            
+                       
+
+            /*
+            if(i == 264 && j == 176){
+                    printf("@%"PRIu64", %"PRIu64"\n", i, j);
+                    printf("my score is %"PRId64"\n", mc[j-1].score);
+                    printf("in position @ jprime= %"PRIu64" cellpaths [i-1, i] are %"PRId64", %"PRId64"\n", j_prime, cell_path_y[i-1], cell_path_y[i]);
+                    printf("Scores %"PRId64", %"PRId64", %"PRId64"\n", scoreDiagonal, scoreLeft, scoreRight);
+                    printf("check j_right_prime == %"PRIu64"\n", j_right_prime);
+                    getchar();
+                    //exit(-1);
+            }
+            */
+            
+            //check if column max has changed
+            //New condition: check if you filled i-2, j-1
+            
+            
+            if(i == Xend-1 || j == Yend-1){
+
+                if(i == Xend-1 && j != Yend-1){
+            		table[i][j_prime].score = table[i][j_prime].score + iGap + (Yend - j)*eGap;
+            	}else if(j == Yend-1 && i != Xend-1){
+            		table[i][j_prime].score = table[i][j_prime].score + iGap + (Xend - i)*eGap;
+            	}
+                //Check for best cell
+                if(table[i][j_prime].score >= bc.c.score){ 
+                    
+                    /*
+                    if(i == 798 && j == 1052){ // yields 799, 2497
+                        printf("in position @ jprime= %"PRIu64" cellpaths [i-1, i] are %"PRId64", %"PRId64"\n", j_prime, cell_path_y[i-1], cell_path_y[i]);
+                        printf("Scores %"PRId64", %"PRId64", %"PRId64"\n", scoreDiagonal, scoreLeft, scoreRight);
+                        printf("score comes from %"PRIu64", %"PRIu64",\n", mc[j-1].xpos, mc[j-1].ypos);
+                        printf("IDlengths: %"PRIu64", %"PRIu64"\n", Xend, Yend);
+                        
+                        //exit(-1);
+                    }
+                    */
+                    
+                    bc.c.score = table[i][j_prime].score; bc.c.xpos = i; bc.c.ypos = j; bc.j_prime = j_prime; 
+                }
+                //bc.c.score = table[i][j_prime].score; bc.c.xpos = i; bc.c.ypos = j; bc.j_prime = j_prime;
+            }
+            
+            
+            #ifdef VERBOSE
+            //printf("Put score: %"PRId64"\n\n", table[i][j_prime].score);
+            //printf("(%"PRId64")%02"PRId64" ", j_diag_prime, table[i][j_prime].score); //printf("->(%"PRIu64", %"PRIu64")", i, j); printf("[%c %c]", X[i], Y[j]);
+            //if(scoreDiagonal >= scoreLeft && scoreDiagonal >= scoreRight) printf("*\t");
+            //else if(scoreRight > scoreLeft) printf("{\t"); else printf("}\t");
+            //getchar();
+
+            #endif
+            j_prime++;
+        }
+        #ifdef VERBOSE
+        printf("\n");
+        getchar();
+        #endif
+    }
+        
+    return bc;
+}
+
+
+
+void backtrackingNW(unsigned char * X, uint64_t Xstart, uint64_t Xend, unsigned char * Y, uint64_t Ystart, uint64_t Yend, struct cell ** table, char * rec_X, char * rec_Y, struct best_cell * bc, uint64_t * ret_head_x, uint64_t * ret_head_y, BasicAlignment * ba, int64_t * cell_path_y, uint64_t window_size){
+    uint64_t curr_x, curr_y, prev_x, prev_y, head_x, head_y, limit_x, limit_y;
+    int64_t k, j_prime, delta_diff = 0;
+
+    //limit_x = 2*MAX_READ_SIZE-1;
+    //limit_y = limit_x;
+    limit_x = 2*MAX(Xend, Yend);
+    limit_y = limit_x;
+    //head_x = 2*MAX(Xend, Yend);
+    //head_y = 2*MAX(Xend, Yend);
+    head_x = limit_x;
+    head_y = limit_y;
+    curr_x = bc->c.xpos;
+    curr_y = bc->c.ypos;
+    #ifdef VERBOSE
+    printf("Optimum : %"PRIu64", %"PRIu64"\n", curr_x, curr_y);
+    #endif
+    //printf("Optimum : %"PRIu64", %"PRIu64"\n", curr_x, curr_y);
+    
+    prev_x = curr_x;
+    prev_y = curr_y;
+    int show = 0;
+   
+    for(k=Xend-1; k>curr_x; k--) rec_X[head_x--] = '-';
+    for(k=Yend-1; k>curr_y; k--) rec_Y[head_y--] = '-';
+
+    j_prime = bc->j_prime;
+    //printf("init prime: %"PRIu64"\n", j_prime);
+    unsigned char first_track = 1;
+    
+    while(curr_x > 0 && curr_y > 0){
+
+        
+        if(first_track == 0){
+            delta_diff = MAX(1, cell_path_y[prev_x] - (int64_t) window_size) - MAX(1, cell_path_y[curr_x] - (int64_t)window_size); //j-1
+            j_prime = MAX(0, j_prime - (int64_t)(prev_y - curr_y) + (int64_t) delta_diff);
+            
+
+            if(/*(bc->c.xpos == 630 && bc->c.ypos == 541 )||*/ j_prime > MAX_WINDOW_SIZE){
+                
+                printf("from %"PRIu64", %"PRIu64"\nto   %"PRIu64", %"PRIu64"\n", prev_x, prev_y, curr_x, curr_y);
+                printf("jp: %"PRIu64", py,cy %"PRIu64", %"PRIu64", delta: %"PRId64"\n", j_prime, prev_y, curr_y, (int64_t)delta_diff);
+                printf("currx curry : %"PRIu64", %"PRIu64"\n", curr_x, curr_y);
+                printf("window size: %"PRIu64"\n", window_size);
+                printf("cp[prev, curr] : %"PRId64", %"PRId64"\n", cell_path_y[prev_x], cell_path_y[curr_x]);
+                printf("my cell path: %"PRId64"\n", cell_path_y[curr_x]);
+                printf("Optimum : %"PRIu64", %"PRIu64"\n", bc->c.xpos, bc->c.ypos);
+                getchar();
+            }
+            
+            //j_prime = j_prime - (int64_t)(prev_y - curr_y) + (int64_t) delta_diff;
+
+            prev_x = curr_x;
+            prev_y = curr_y;
+
+            /*
+            if(bc->c.xpos == 798 && bc->c.ypos == 1052){
+                printf("[%c %c]", X[prev_x], Y[prev_y]);
+                printf("(%"PRIu64", %"PRIu64") ::: \n", curr_x, curr_y);
+
+            }
+            */
+
+            #ifdef VERBOSE
+            //printf("Jprime: %"PRId64" :DELTADIF:%"PRId64"\n", j_prime, delta_diff);
+            printf("[%c %c]", X[prev_x], Y[prev_y]);
+            printf("(%"PRIu64", %"PRIu64") ::: \n", curr_x, curr_y);
+            //printf("(%"PRIu64", %"PRIu64") ::: \n", prev_x, prev_y);
+            //printf("cellp Prev: %"PRId64" Post: %"PRId64"\n", cell_path_y[prev_x], cell_path_y[curr_x]);
+            //printf("the difs? %"PRId64" the other: %"PRId64"\n", MAX(0, cell_path_y[prev_x] - (int64_t) window_size), MAX(0, cell_path_y[curr_x] - (int64_t)window_size));
+            getchar();
+            #endif
+
+        }
+        
+        //if(table[prev_x][j_prime].xfrom > MAX_READ_SIZE || table[prev_x][j_prime].yfrom > MAX_WINDOW_SIZE) fprintf(stdout, "OH NOES !! %"PRIu64"\t%"PRId64"\t%"PRIu64"\t%"PRIu64" dangers: %"PRIu64", %"PRIu64"\n", prev_x, j_prime, Xend, Yend, table[prev_x][j_prime].xfrom, table[prev_x][j_prime].yfrom);
+
+        /*
+        if(table[prev_x][j_prime].xfrom > MAX_READ_SIZE || table[prev_x][j_prime].yfrom > MAX_WINDOW_SIZE){
+            fprintf(stdout, "OH NOES !! %"PRIu64"\t%"PRId64"\t%"PRIu64"\t%"PRIu64" dangers: %"PRIu64", %"PRIu64"\n", prev_x, j_prime, Xend, Yend, table[prev_x][j_prime].xfrom, table[prev_x][j_prime].yfrom);
+            uint64_t k;
+            for(k=0;k<Xend;k++){
+                fprintf(stdout, "%c", X[k]);
+            }
+            fprintf(stdout, "\n");
+            for(k=0;k<Yend;k++){
+                fprintf(stdout, "%c", Y[k]);
+            }
+            fprintf(stdout, "\n");
+            show = 1;
+        } 
+        */
+        if(j_prime >= MAX_WINDOW_SIZE) printf("j_prime:overflow %"PRIu64"\n", j_prime);
+
+ 
+        curr_x = table[prev_x][j_prime].xfrom;
+        curr_y = table[prev_x][j_prime].yfrom;
+        first_track = 0;
+        
+        //printf("w: %"PRIu64"- %"PRIu64"\n", curr_x, curr_y);
+        
+
+        if((curr_x == (prev_x - 1)) && (curr_y == (prev_y -1))){
+            //Diagonal case
+            //printf("DIAG\n");
+            if(head_x == 0 || head_y == 0) goto exit_point;
+            rec_X[head_x--] = (char) X[prev_x];
+            rec_Y[head_y--] = (char) Y[prev_y];
+            ba->length++;
+            
+        }else if((prev_x - curr_x) > (prev_y - curr_y)){
+            //Gap in X
+            //printf("Gap X\n");
+            if(head_x == 0 || head_y == 0) goto exit_point;
+            if(bc->c.xpos != prev_x && bc->c.ypos != prev_y){
+                rec_Y[head_y--] = Y[prev_y];
+                rec_X[head_x--] = X[prev_x];
+            }else{
+                rec_Y[head_y--] = '-';
+                rec_X[head_x--] = X[prev_x];
+            }
+            ba->length++;
+            
+            for(k=prev_x-1;k>curr_x;k--){
+                if(head_x == 0 || head_y == 0) goto exit_point;
+                #ifdef VERBOSE 
+                if(head_x == 0 || head_y == 0){
+                    printf("%"PRIu64" %"PRIu64" and prevs are %"PRIu64" %"PRIu64"\n", head_x, head_y, prev_x, prev_y);
+                    printf("origin is %"PRIu64", %"PRIu64"\n", bc->c.xpos, bc->c.ypos);
+                    uint64_t z;
+                    for(z=head_x;z<limit_x;z++){
+                        fprintf(stdout, "%c", (char) rec_X[z]);
+                    }
+                    printf("\n");
+                    for(z=head_y;z<limit_y;z++){
+                        fprintf(stdout, "%c", (char) rec_Y[z]);
+                    }
+                    getchar();
+                }
+                #endif
+                rec_Y[head_y--] = '-';
+                rec_X[head_x--] = (char) X[k];
+                ba->length++;
+                ba->egaps++;
+            }
+            ba->igaps += 1;
+            ba->egaps--;
+        }else{
+            //Gap in Y
+            //printf("GAP Y\n");
+            //10, 0, 401, 281
+            if(head_x == 0 || head_y == 0) goto exit_point;
+            if(bc->c.xpos != prev_x && bc->c.ypos != prev_y){
+                rec_Y[head_y--] = Y[prev_y];
+                rec_X[head_x--] = X[prev_x];
+            }else{
+                rec_Y[head_y--] = Y[prev_y];
+                rec_X[head_x--] = '-';
+            }
+            ba->length++;
+
+            for(k=prev_y-1;k>curr_y;k--){
+                if(head_x == 0 || head_y == 0) goto exit_point;
+                #ifdef VERBOSE 
+                if(head_x == 0 || head_y == 0){
+                    printf("%"PRIu64" %"PRIu64" and prevs are %"PRIu64" %"PRIu64"\n", head_x, head_y, prev_x, prev_y);
+                    printf("origin is %"PRIu64", %"PRIu64"\n", bc->c.xpos, bc->c.ypos);
+                    uint64_t z;
+                    for(z=head_x;z<limit_x;z++){
+                        fprintf(stdout, "%c", (char) rec_X[z]);
+                    }
+                    printf("\n");
+                    for(z=head_y;z<limit_y;z++){
+                        fprintf(stdout, "%c", (char) rec_Y[z]);
+                    }
+                    getchar();
+                }
+                #endif
+                rec_X[head_x--] = '-';
+                rec_Y[head_y--] = (char) Y[k];
+                ba->length++;
+                ba->egaps++;
+            }
+            
+            ba->igaps += 1;
+            ba->egaps--;
+        }
+        
+    }
+    
+    if(curr_x == 0 && curr_y == 0 && (curr_x == (prev_x - 1)) && (curr_y == (prev_y -1))){
+        rec_X[head_x--] = (char) X[curr_x];
+        rec_Y[head_y--] = (char) Y[curr_y];
+        ba->length++;
+    }
+    
+    exit_point:
+
+    //printf("curr: %"PRIu64", %"PRIu64"\n", curr_x, curr_y);
+    //printf("Heads: %"PRIu64", %"PRIu64"\n", head_x, head_y);
+    if(show == 1)fprintf(stdout, "%"PRIu64", %"PRIu64"\n", head_x, head_y);
+    uint64_t huecos_x = 0, huecos_y = 0;
+    k=(int64_t)curr_x-1;
+    while(k>=0){ if(head_x == 0) break; rec_X[head_x--] = '-'; huecos_x++;  k--; }
+    k=(int64_t)curr_y-1;
+    while(k>=0){ if(head_y == 0) break; rec_Y[head_y--] = '-'; huecos_y++; k--; }
+    
+    if(show == 1)fprintf(stdout, "%"PRIu64", %"PRIu64"\n", head_x, head_y);
+
+    if(huecos_x >= huecos_y){
+        while(huecos_x > 0) { if(head_y == 0) break; rec_Y[head_y--] = ' '; huecos_x--;}
+    }else{
+        while(huecos_y > 0) { if(head_x == 0) break; rec_X[head_x--] = ' '; huecos_y--;}
+    }
+
+    if(show == 1){
+        fprintf(stdout, "%"PRIu64", %"PRIu64"\n", head_x, head_y);
+        fprintf(stdout, "%"PRIu64", %"PRIu64"\n", 2*Xend, 2*Yend);
+        uint64_t k;
+        for(k=head_x;k<limit_x;k++){
+            fprintf(stdout, "%c", (char) rec_X[k]);
+        }
+        printf("\n");
+        for(k=head_y;k<limit_y;k++){
+            fprintf(stdout, "%c", (char) rec_Y[k]);
+        }
+        printf("\n");
+        getchar();
+    }
+
+    *ret_head_x = head_x;
+    *ret_head_y = head_y;
+    #ifdef VERBOSE
+    printf("hx hy: %"PRIu64", %"PRIu64"\n", head_x, head_y);
+    #endif
+}
+
+
+AVLTree * getNewLocationAVLTree(Mempool_AVL * mp, uint64_t * n_pools_used, uint64_t key){
+
+    if(mp[*n_pools_used].current == POOL_SIZE){
+        *n_pools_used += 1;
+        if(*n_pools_used == MAX_MEM_POOLS) terror("Reached max pools");
+        init_mem_pool_AVL(&mp[*n_pools_used]);
+        
+    }
+
+    AVLTree * new_pos = mp[*n_pools_used].base + mp[*n_pools_used].current;
+    mp[*n_pools_used].current++;
+
+    new_pos->key = key;
+    new_pos->count = 1;
+    new_pos->height = 1;
+
+    return new_pos;
+}
+
+void init_mem_pool_AVL(Mempool_AVL * mp){
+    mp->base = (AVLTree *) calloc(POOL_SIZE, sizeof(AVLTree));
+    if(mp->base == NULL) terror("Could not request memory pool");
+    mp->current = 0;
+}
+
+
+
+/*
+// An AVL tree node
+typedef struct AVL_Node{
+    uint64_t key;
+    struct AVL_Node * left;
+    struct AVL_Node * right;
+    uint64_t height;
+    llpos * next;
+} AVLTree;
+*/
+ 
+// A utility function to get height of the tree
+
+uint64_t height(AVLTree * N){
+    if (N == NULL)
+        return 0;
+    return N->height;
+}
+
+/* Substituted by (x == NULL) ? (0) : (x->height) */
+ 
+/* Helper function that allocates a new node with the given key and
+    NULL left and right pointers. */
+
+/* This one is substituted by AVLTree * getNewLocationAVLTree(Mempool_AVL * mp, uint64_t * n_pools_used, uint64_t key) */
+ 
+// A utility function to right rotate subtree rooted with y
+// See the diagram given above.
+AVLTree * right_rotate(AVLTree * y){
+    AVLTree * x = y->left;
+    AVLTree * T2 = x->right;
+ 
+    // Perform rotation
+    x->right = y;
+    y->left = T2;
+ 
+    // Update heights
+    //x->height = MAX((x == NULL) ? (0) : (x->left->height), (x == NULL) ? (0) : (x->right->height))+1;
+    //y->height = MAX((y == NULL) ? (0) : (y->left->height), (y == NULL) ? (0) : (y->right->height))+1;
+    // Update heights
+    y->height = MAX(height(y->left), height(y->right))+1;
+    x->height = MAX(height(x->left), height(x->right))+1;
+ 
+    // Return new root
+    return x;
+}
+ 
+// A utility function to left rotate subtree rooted with x
+// See the diagram given above.
+AVLTree * left_rotate(AVLTree * x){
+    AVLTree * y = x->right;
+    AVLTree * T2 = y->left;
+ 
+    // Perform rotation
+    y->left = x;
+    x->right = T2;
+ 
+    //  Update heights
+    //x->height = MAX((x == NULL) ? (0) : (x->left->height), (x == NULL) ? (0) : (x->right->height))+1;
+    //y->height = MAX((y == NULL) ? (0) : (y->left->height), (y == NULL) ? (0) : (y->right->height))+1;
+    x->height = MAX(height(x->left), height(x->right))+1;
+    y->height = MAX(height(y->left), height(y->right))+1;
+ 
+    // Return new root
+    return y;
+}
+ 
+// Get Balance factor of node N
+
+int64_t get_balance(AVLTree * N){
+    if (N == NULL)
+        return 0;
+    return height(N->left) - height(N->right);
+}
+
+/* Substituted by (node == NULL) ? (0) : ((int64_t) node->left->height - (int64_t) node->right->height) */
+
+AVLTree * find_AVLTree(AVLTree * node, uint64_t key){
+    AVLTree * found = NULL;
+    if(node == NULL) return NULL;
+
+    if (key < node->key) {
+        found = find_AVLTree(node->left, key);
+    } else if (key > node->key) {
+        found = find_AVLTree(node->right, key);
+    } else { 
+        return node;
+    }
+    return found;
+} 
+
+llpos * find_AVLTree_llpos(AVLTree * node, uint64_t key){
+    llpos * aux = NULL;
+    if(node == NULL) return NULL;
+
+    if (key < node->key) {
+        aux = find_AVLTree_llpos(node->left, key);
+    } else if (key > node->key) {
+        aux = find_AVLTree_llpos(node->right, key);
+    } else { 
+        return node->next;
+    }
+    return aux;
+}
+
+// Recursive function to insert key in subtree rooted
+// with node and returns new root of subtree.
+AVLTree * insert_AVLTree(AVLTree * node, uint64_t key, Mempool_AVL * mp, uint64_t * n_pools_used, uint64_t pos, Mempool_l * mp_l, uint64_t * n_pools_used_l, uint64_t s_id){
+    /* 1.  Perform the normal BST insertion */
+    if (node == NULL){
+        
+        AVLTree * n_node = getNewLocationAVLTree(mp, n_pools_used, key);
+        llpos * aux = getNewLocationllpos(mp_l, n_pools_used_l);
+        aux->pos = pos;
+        aux->s_id = s_id;
+        n_node->next = aux;
+        return n_node;
+    }
+ 
+    if (key < node->key) {
+        node->left  = insert_AVLTree(node->left, key, mp, n_pools_used, pos, mp_l, n_pools_used_l, s_id);
+    } else if (key > node->key) {
+        node->right = insert_AVLTree(node->right, key, mp, n_pools_used, pos, mp_l, n_pools_used_l, s_id);
+    } else { 
+        // Equal keys are inserted as a linked list
+        llpos * aux = getNewLocationllpos(mp_l, n_pools_used_l);
+        aux->pos = pos;
+        aux->s_id = s_id;
+        aux->next = node->next;
+        node->next = aux;
+        ++(node->count);
+        return node;
+    }
+ 
+    /* 2. Update height of this ancestor node */
+    //node->height = 1 + MAX((node->left == NULL) ? (0) : (node->left->height), (node->right == NULL) ? (0) : (node->right->height));
+    node->height = 1 + MAX(height(node->left), height(node->right));
+ 
+    /* 3. Get the balance factor of this ancestor
+          node to check whether this node became
+          unbalanced */
+    //int64_t balance = (node->left == NULL || node->right == NULL) ? (0) : ((int64_t) node->left->height - (int64_t) node->right->height);
+    int64_t balance = get_balance(node);
+ 
+    // If this node becomes unbalanced, then
+    // there are 4 cases
+ 
+    // Left Left Case
+    if (balance > 1 && key < node->left->key)
+        return right_rotate(node);
+ 
+    // Right Right Case
+    if (balance < -1 && key > node->right->key)
+        return left_rotate(node);
+ 
+    // Left Right Case
+    if (balance > 1 && key > node->left->key)
+    {
+        node->left =  left_rotate(node->left);
+        return right_rotate(node);
+    }
+ 
+    // Right Left Case
+    if (balance < -1 && key < node->right->key)
+    {
+        node->right = right_rotate(node->right);
+        return left_rotate(node);
+    }
+ 
+    /* return the (unchanged) node pointer */
+    return node;
+}
+ 
+// A utility function to print preorder traversal
+// of the tree.
+// The function also prints height of every node
+
+void pre_order(AVLTree * root){
+    if(root != NULL){
+        printf("%"PRIu64" ", root->key);
+        llpos * aux = root->next;
+        while(aux != NULL){ printf("#%"PRIu64", ", aux->pos); aux = aux->next; }
+        pre_order(root->left);
+        pre_order(root->right);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/alignmentFunctions.h	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,136 @@
+#define QF_LAMBDA 0.275
+#define QF_KARLIN 0.333
+
+
+
+typedef struct {
+    uint64_t id;        //The thread id
+    SeqInfo * database; //Database sequence and lengths
+    SeqInfo * query;    //Query sequence and lengths
+    uint64_t from;      //Starting READ to compute alignments from
+    uint64_t to;        //End READ to compute alignments from
+    AVLContainer * container_a; //Container to hold the multidimensional array
+    AVLContainer * container_b; //Container to hold the multidimensional array
+    AVLContainer * container_c; //Container to hold the multidimensional array
+    AVLContainer * container_d; //Container to hold the multidimensional array
+    uint64_t * contained_reads;
+    uint64_t * base_coordinates;
+    uint64_t accepted_query_reads; //Number of reads that have a fragment with evalue less than specified
+    long double min_e_value;    //Minimum evalue to accept read
+    long double min_coverage;    //Minimum coverage percentage to accept read
+    long double min_identity;    //Minimum identity percentage to accept read
+    long double window;         //Percentage of window that will be explored (+-)
+    FILE * out; //File to write alignments out
+    int igap;
+    int egap;
+    uint64_t * hits;        // To work in hits mode only
+    struct positioned_cell * mc;
+    struct cell ** table;
+    char * reconstruct_X;
+    char * reconstruct_Y;
+    char * writing_buffer_alignment;
+    unsigned char * my_x;
+    unsigned char * my_y;
+    Head * queue_head;  //To tell where the queue starts after modifications
+    pthread_mutex_t * lock;
+    unsigned char full_comp; // Tells whether read reporting should stop at first match or keep reporting
+    unsigned char * markers; // To tell which sequences were already used
+} HashTableArgs;
+
+
+
+/*
+    Nucleotides matching function
+*/
+int64_t compare_letters(unsigned char a, unsigned char b);
+
+/**
+ * Initialize the memory pool to later retrieve individual memory addresses for llpos
+ * 
+ */
+void init_mem_pool_llpos(Mempool_l * mp);
+
+/**
+ * Get a new memory address from the pool mp for a type llpos
+ * 
+ */
+llpos * getNewLocationllpos(Mempool_l * mp, uint64_t * n_pools_used);
+
+/*
+    Load input database using 4 threads
+*/
+void * load_input(void * a);
+/*
+    Compute alignments by thread given a hash table argument
+*/
+void * computeAlignmentsByThread(void * a);
+
+
+/*
+    Performs NW and backtracking to recover alignment
+*/
+void build_alignment(char * reconstruct_X, char * reconstruct_Y, uint64_t curr_db_seq, uint64_t curr_read, HashTableArgs * hta, unsigned char * my_x, unsigned char * my_y, struct cell ** table, struct positioned_cell * mc, char * writing_buffer_alignment, BasicAlignment * ba, uint64_t xlen, uint64_t ylen, int64_t * cell_path_y, long double * window);
+
+/*
+    Compute the alignment and evalue of a given hit
+    The positions pos_database and pos_query refer to the last match in the hit
+*/
+void alignmentFromQuickHits(SeqInfo * database, SeqInfo * query, uint64_t pos_database, uint64_t pos_query, uint64_t curr_read, uint64_t curr_db_seq, Quickfrag * qf, uint64_t offset_db_reads, uint64_t offset_db_coordinates);
+
+/*
+    Computes the cell path for the y points given incremental x
+    Only add +- window size to each to know which path to go through
+*/
+void calculate_y_cell_path(Point p0, Point p1, Point p2, Point p3, int64_t * cell_path_y);
+/*
+    Calculates NW table with two rows and stores a cellpath of scores, identities, gaps and starting and ending positions
+*/
+struct best_cell NW(unsigned char * X, uint64_t Xstart, uint64_t Xend, unsigned char * Y, uint64_t Ystart, uint64_t Yend, int64_t iGap, int64_t eGap, struct cell ** table, struct positioned_cell * mc, int show, int64_t * cell_path_y, long double * window, uint64_t * curr_window_size);
+
+/*
+    Computes the alignment given a NW table
+*/
+void backtrackingNW(unsigned char * X, uint64_t Xstart, uint64_t Xend, unsigned char * Y, uint64_t Ystart, uint64_t Yend, struct cell ** table, char * rec_X, char * rec_Y, struct best_cell * bc, uint64_t * ret_head_x, uint64_t * ret_head_y, BasicAlignment * ba, int64_t * cell_path_y, uint64_t window_size);
+
+/*
+    Get memory for a new AVL tree node
+*/
+AVLTree * getNewLocationAVLTree(Mempool_AVL * mp, uint64_t * n_pools_used, uint64_t key);
+
+/*
+    Initialize a memory pool for AVL trees
+*/
+void init_mem_pool_AVL(Mempool_AVL * mp);
+
+/*
+    Right rotate an AVL tree to make it balanced
+*/
+AVLTree * right_rotate(AVLTree * y);
+
+/*
+    Left rotate an AVL tree to make it balanced
+*/
+AVLTree * left_rotate(AVLTree * x);
+
+
+/*
+    Find a key in an AVL tree
+*/
+AVLTree * find_AVLTree(AVLTree * node, uint64_t key);
+
+/*
+    Find a key in an AVL tree but return its hit list
+*/
+llpos * find_AVLTree_llpos(AVLTree * node, uint64_t key);
+
+/*
+    Insert node in AVL tree
+*/
+AVLTree * insert_AVLTree(AVLTree * node, uint64_t key, Mempool_AVL * mp, uint64_t * n_pools_used, uint64_t pos, Mempool_l * mp_l, uint64_t * n_pools_used_l, uint64_t s_id);
+
+/*
+    Traverse AVL tree in pre order
+*/
+void pre_order(AVLTree * root);
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/combine_reads.c	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,128 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include "structs.h"
+#include "commonFunctions.h"
+
+#define MAX(x, y) (((x) > (y)) ? (x) : (y))
+#define MIN(x, y) (((x) <= (y)) ? (x) : (y))
+#define STARTING_SEQS 1000
+#define PIECE_OF_DB_REALLOC 3200000 //half a gigabyte if divided by 8 bytes
+#define MATVAL 101
+
+// void terror(char *s) {
+//     fprintf(stdout, "ERR**** %s ****\n", s);
+//     exit(-1);
+// }
+
+
+int main(int argc, char ** av){
+    
+    if(argc != 2) terror("USE:: combine_reads <file>");
+
+	
+    char names[10][100] = {"14np", "47np", "BR0716C", "BR11044P", "CA01044C", "CA01067C", "CA11149P", "CA11154P", "MA07066C", "MA09032P"};
+    uint64_t llen[10] = {1758451, 959020, 1616163, 884193, 934256, 1007436, 1670521, 584151, 671010, 516632};
+    uint64_t nseqs = 10;
+
+    FILE * results, * data;
+    data = fopen(av[1], "rt");
+    if(data == NULL) terror("Could not open input file");
+
+    uint64_t * mat = (uint64_t *) calloc(MATVAL, sizeof(uint64_t));
+    if(mat == NULL) terror("Could not allocate matrix array");
+    long double * mat_e = (long double *) calloc(MATVAL, sizeof(long double));
+    if(mat_e == NULL) terror("Could not allocate float table");
+
+    char current_file[100];
+    uint64_t i=5, idx=0;
+    while(av[1][i] != '_' && av[1][i+1] != 'g'){
+	    current_file[idx++] = av[1][i];
+	    i++;
+    }
+    current_file[idx] = '\0';
+    fprintf(stdout, "Current file is %s\n", current_file);
+
+    char buffer[MAXLID];
+    if ((results = fopen("accu.log", "r")) == NULL){
+        results = fopen("accu.log", "wt");
+    }else{
+        // Load the matrix
+       
+        
+        for(i=0;i<100;i++){
+            if(0 == fgets(buffer, MAXLID, results)) terror("Missing number on load");
+            
+            //fprintf(stdout, "Have %s\n", buffer);
+            buffer[strlen(buffer)-1] = '\0';
+            //mat[i] = asciiToUint64(buffer);
+	    mat_e[i] = (long double) atof(buffer);
+            //fprintf(stdout, "%"PRIu64"\n", mat[i]);
+            //getchar();
+        }
+        fclose(results);
+        results = fopen("accu.log", "wt"); // Re open
+    }
+
+    // Read file 
+    uint64_t read_id_1, read_id_2, coverage, identity, length, current, currmax, j, last = 100000, lastmax = 0xFFFFFFFFFFFFFFFF;
+    while(!feof(data)){
+        if(0 == fgets(buffer, MAXLID, data) && !feof(data)) terror("Missing values");
+        // 2 77277 89 64 213
+        sscanf(buffer, "%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64, &read_id_1, &read_id_2, &coverage, &identity, &length);
+        //fprintf(stdout, "%"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64" %"PRIu64"\n", read_id_1, read_id_2, coverage, identity, length);
+        currmax = MIN(identity, coverage);
+        //fprintf(stdout, "%"PRIu64"\n", currmax);
+        current = read_id_1;
+        /*
+        for(j=currmax; j > 1; j--){
+            if(current != lasts[j]){
+                mat[j]++;
+                lasts[j] = current;
+            }
+        }
+        */
+	if(lastmax == 0xFFFFFFFFFFFFFFFF){
+		last = current;
+		lastmax = 0;
+	}
+	if(current == last){
+		//mat[currmax] += 1;
+		if(lastmax < currmax){
+			lastmax = currmax;
+		}
+	}else{
+		mat[lastmax]++;
+		last = current;
+		lastmax = 0;
+	}
+
+    }
+
+    uint64_t divider = 0;
+    for(i=0; i < nseqs; i++){
+
+	    if(strcmp(current_file, names[i]) == 0){
+		    divider = llen[i];
+	    }
+    }
+    if(divider == 0) terror("Could not find file for divider"); else fprintf(stdout, "The divider is %"PRIu64"\n", divider);
+
+    for(j=99; j>0; j--){
+        mat[j] += mat[j+1];
+    }
+    mat[0] = mat[1];
+
+    for(j=0; j<100; j++){
+        fprintf(stdout, "%"PRIu64" --> %.5f\n", mat[j], (float)((100*(long double)mat[j])/(long double)divider));
+	
+        fprintf(results, "%.5f\n", (float)(mat_e[j] + ((100*(long double)mat[j])/(long double)divider))/2);
+    }
+
+
+    fclose(results);
+    fclose(data);
+    free(mat);
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/commonFunctions.c	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,283 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <inttypes.h>
+#include <ctype.h>
+#include <string.h>
+#include <pthread.h>
+#include <emmintrin.h>
+#include <math.h>
+#include "structs.h"
+
+#define ALIGNED_BYTES 16
+
+void terror(char *s) {
+    fprintf(stdout, "ERR**** %s ****\n", s);
+    exit(-1);
+}
+
+char buffered_fgetc(char *buffer, uint64_t *pos, uint64_t *read, FILE *f) {
+    if (*pos >= READBUF) {
+        *pos = 0;
+        memset(buffer, 0, READBUF);
+        *read = fread(buffer, 1, READBUF, f);
+    }
+    *pos = *pos + 1;
+    return buffer[*pos-1];
+}
+
+void get_num_seqs_and_length(char * seq_buffer, uint64_t * n_seqs, uint64_t * t_len, LoadingDBArgs * ldbargs){
+    char check[16] = ">>>>>>>>>>>>>>>>";
+    uint64_t a_fourth = *t_len / 4;
+
+    uint64_t i=0;
+    
+    __m128i * ptr1;
+    __m128i * ptr2;
+    __m128i res = _mm_setzero_si128();
+    ptr2 = (__m128i *) check;
+
+    ldbargs[0].read_from = 0;
+    for(i=0; i<a_fourth - 16; i+=16){
+        ptr1 = (__m128i *) &seq_buffer[i];
+        res = _mm_cmpeq_epi8(*ptr1, *ptr2);
+        // TODO parallelize this
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[0]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[1]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[2]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[3]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[4]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[5]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[6]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[7]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[8]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[9]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[10]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[11]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[12]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[13]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[14]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[15]) >> 7;
+    }
+    while(seq_buffer[i] != '>'){ ++i; }
+    ldbargs[0].read_to = i;
+    ldbargs[0].data_database->n_seqs = *n_seqs;
+    ldbargs[1].read_from = i;
+    while(i % 16 != 0){ ++i; if(seq_buffer[i] == '>') terror("Sequence of length < 16"); }
+    if(i > ldbargs[1].read_from) ++(*n_seqs); // For the advance to align bytes
+
+    //printf("seqs at 0: %"PRIu64" readfrom: %"PRIu64", readto: %"PRIu64", \n", ldbargs[0].data_database->n_seqs, ldbargs[0].read_from, ldbargs[0].read_to);
+
+    
+    for(i=i; i<2*(a_fourth) - 16; i+=16){
+        ptr1 = (__m128i *) &seq_buffer[i];
+        res = _mm_cmpeq_epi8(*ptr1, *ptr2);
+        // TODO parallelize this
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[0]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[1]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[2]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[3]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[4]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[5]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[6]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[7]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[8]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[9]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[10]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[11]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[12]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[13]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[14]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[15]) >> 7;
+    }
+    while(seq_buffer[i] != '>') ++i;
+    ldbargs[1].read_to = i;
+    ldbargs[1].data_database->n_seqs = *n_seqs - ldbargs[0].data_database->n_seqs;
+    ldbargs[2].read_from = i;
+    while(i % 16 != 0){ ++i; if(seq_buffer[i] == '>') terror("Sequence of length < 16"); }
+    if(i > ldbargs[2].read_from) ++(*n_seqs); // For the advance to align bytes
+
+    //printf("seqs at 1: %"PRIu64" readfrom: %"PRIu64", readto: %"PRIu64", \n", ldbargs[1].data_database->n_seqs, ldbargs[1].read_from, ldbargs[1].read_to);
+
+    
+    for(i=i; i<3*(a_fourth) - 16; i+=16){
+        ptr1 = (__m128i *) &seq_buffer[i];
+        res = _mm_cmpeq_epi8(*ptr1, *ptr2);
+        // TODO parallelize this
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[0]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[1]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[2]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[3]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[4]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[5]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[6]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[7]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[8]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[9]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[10]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[11]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[12]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[13]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[14]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[15]) >> 7;
+    }
+    while(seq_buffer[i] != '>') ++i;
+    ldbargs[2].read_to = i;
+    ldbargs[2].data_database->n_seqs = *n_seqs - (ldbargs[1].data_database->n_seqs + ldbargs[0].data_database->n_seqs);
+    ldbargs[3].read_from = i;
+    while(i % 16 != 0){ ++i; if(seq_buffer[i] == '>') terror("Sequence of length < 16"); }
+    if(i > ldbargs[3].read_from) ++(*n_seqs); // For the advance to align bytes
+
+    //printf("seqs at 2: %"PRIu64" readfrom: %"PRIu64", readto: %"PRIu64", \n", ldbargs[2].data_database->n_seqs, ldbargs[2].read_from, ldbargs[2].read_to);
+
+    
+    for(i=i; i<(*t_len) - 16; i+=16){
+        ptr1 = (__m128i *) &seq_buffer[i];
+        res = _mm_cmpeq_epi8(*ptr1, *ptr2);
+        // TODO parallelize this
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[0]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[1]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[2]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[3]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[4]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[5]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[6]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[7]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[8]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[9]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[10]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[11]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[12]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[13]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[14]) >> 7;
+        *n_seqs += (uint64_t) (((unsigned char *) &res)[15]) >> 7;
+    }
+    while(i < *t_len){
+        if(seq_buffer[i] == '>') ++(*n_seqs);
+        ++i;
+    }
+    ldbargs[3].read_to = *t_len;
+    ldbargs[3].data_database->n_seqs = *n_seqs - (ldbargs[2].data_database->n_seqs + ldbargs[1].data_database->n_seqs + ldbargs[0].data_database->n_seqs);
+
+    //printf("seqs at 3: %"PRIu64" readfrom: %"PRIu64", readto: %"PRIu64", \n", ldbargs[3].data_database->n_seqs, ldbargs[3].read_from, ldbargs[3].read_to);
+
+}
+
+Queue * generate_queue(Head * queue_head, uint64_t t_reads, uint64_t n_threads, uint64_t levels){
+    uint64_t i, j;
+    uint64_t reads_per_thread;
+    if(levels > t_reads) levels = t_reads;
+    uint64_t pieces = t_reads/levels;
+    uint64_t from, to, t_queues = 0, current_queue = 0;
+    for(i=0;i<levels;i++) t_queues += ((i+1)*n_threads);
+    if(t_queues > t_reads) t_queues = t_reads;
+    Queue * queues = (Queue *) malloc(t_queues * sizeof(Queue));
+    if(queues == NULL) terror("Could not allocate queue tasks");
+    queue_head->head = &queues[0];
+
+    
+    for(i=0;i<levels;i++){
+
+        //reads_per_thread = (uint64_t) (floorl((long double) pieces / (long double) ((i+1)*n_threads)));
+        reads_per_thread = (uint64_t) (ceill((long double) pieces / (long double) ((i+1)*n_threads)));
+        
+
+        for(j=0;j<(i+1)*n_threads;j++){
+            from = j * reads_per_thread + (pieces*i);
+            to = (j + 1) * reads_per_thread + (pieces*i);
+            
+            if(j == (i+1)*n_threads - 1) to = pieces*(i+1);
+		
+	    if(from >= t_reads){
+		    queues[current_queue-1].next = NULL;
+                    return &queues[0];
+            }
+
+
+            if(i == levels - 1 && j == (i+1)*n_threads - 1){
+                //If its the last 
+                queues[current_queue].next = NULL;
+            }else{
+                //Else add it to the queue
+                queues[current_queue].next = &queues[current_queue+1];
+            }
+            
+
+            queues[current_queue].r1 = from;
+            queues[current_queue].r2 = (to <= t_reads) ? (to) : (t_reads);
+            current_queue++;
+            //printf("current_piece: %"PRIu64"-%"PRIu64" diff: %"PRIu64"\n", from, to, to - from);
+
+        }
+
+    }
+    //printf("TREADS was %"PRIu64"\n", t_reads);    
+    queues[current_queue-1].r2 = t_reads;
+    return &queues[0];
+}
+
+void print_queue(Queue * q){
+    fprintf(stdout, "Task: %"PRIu64"-%"PRIu64"\n", q->r1, q->r2);
+}
+
+Queue * get_task_from_queue(Head * queue_head, pthread_mutex_t * lock){
+    pthread_mutex_lock(lock);
+
+    Queue * ptr = queue_head->head;
+    if(queue_head->head != NULL) queue_head->head = queue_head->head->next;
+    //if(ptr != NULL){ printf("Taking "); /*print_queue(ptr);*/ }
+
+    pthread_mutex_unlock(lock);
+
+
+    return ptr;
+}
+
+uint64_t quick_pow4(uint64_t n){
+    static uint64_t pow4[33]={1L, 4L, 16L, 64L, 256L, 1024L, 4096L, 16384L, 65536L, 
+    262144L, 1048576L, 4194304L, 16777216L, 67108864L, 268435456L, 1073741824L, 4294967296L, 
+    17179869184L, 68719476736L, 274877906944L, 1099511627776L, 4398046511104L, 17592186044416L, 
+    70368744177664L, 281474976710656L, 1125899906842624L, 4503599627370496L, 18014398509481984L, 
+    72057594037927936L, 288230376151711744L, 1152921504606846976L, 4611686018427387904L};
+    return pow4[n];
+}
+
+uint64_t quick_pow4byLetter(uint64_t n, const char c){
+    static uint64_t pow4_G[33]={2*1L, 2*4L, 2*16L, 2*64L, 2*256L, 2*1024L, 2*4096L, 2*16384L, 2*65536L, 
+    (uint64_t)2*262144L, (uint64_t)2*1048576L,(uint64_t)2*4194304L, (uint64_t)2*16777216L, (uint64_t)2*67108864L, (uint64_t)2*268435456L, (uint64_t)2*1073741824L, (uint64_t)2*4294967296L, 
+    (uint64_t)2*17179869184L, (uint64_t)2*68719476736L, (uint64_t)2*274877906944L, (uint64_t)2*1099511627776L, (uint64_t)2*4398046511104L, (uint64_t)2*17592186044416L, 
+    (uint64_t)2*70368744177664L, (uint64_t)2*281474976710656L, (uint64_t)2*1125899906842624L, (uint64_t)2*4503599627370496L, (uint64_t)2*18014398509481984L, 
+    (uint64_t)2*72057594037927936L, (uint64_t) 2*288230376151711744L, (uint64_t) 2*1152921504606846976L, (uint64_t) 2*4611686018427387904L};
+    
+    static uint64_t pow4_T[33]={3*1L, 3*4L, 3*16L, 3*64L, 3*256L, 3*1024L, 3*4096L, 3*16384L, 3*65536L, 
+    (uint64_t)3*262144L, (uint64_t) 3*1048576L, (uint64_t)3*4194304L, (uint64_t)3*16777216L, (uint64_t)3*67108864L, (uint64_t)3*268435456L, (uint64_t)3*1073741824L, (uint64_t)3*4294967296L, 
+    (uint64_t)3*17179869184L, (uint64_t)3*68719476736L, (uint64_t)3*274877906944L, (uint64_t)3*1099511627776L, (uint64_t)3*4398046511104L, (uint64_t)3*17592186044416L, 
+    (uint64_t)3*70368744177664L, (uint64_t)3*281474976710656L, (uint64_t)3*1125899906842624L, (uint64_t)3*4503599627370496L, (uint64_t)3*18014398509481984L, 
+    (uint64_t)3*72057594037927936L, (uint64_t) 3*288230376151711744L, (uint64_t) 3*1152921504606846976L, (uint64_t) 3*4611686018427387904L};
+    
+    if(c == 'A') return 0;
+    if(c == 'C') return quick_pow4(n);
+    if(c == 'G') return pow4_G[n];
+    if(c == 'T') return pow4_T[n];
+    return 0;
+}
+
+uint64_t hashOfWord(const unsigned char * word, uint32_t k){
+    
+    uint64_t value = 0, jIdx;
+    for(jIdx=0;jIdx<k;jIdx++){
+        value += quick_pow4byLetter(k-(jIdx+1), (char) word[jIdx]);
+    }
+    return value;
+}
+
+
+uint64_t asciiToUint64(const char *text){
+	uint64_t number=0;
+
+	for(;*text;text++){
+		char digit=*text-'0';           
+		number=(number*10)+digit;
+	}
+	return number;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/commonFunctions.h	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,41 @@
+#ifndef COMMON_FUNCTIONS_H
+#define COMMON_FUNCTIONS_H
+#include "structs.h"
+/**
+ * Print the error message 's' and exit(-1)
+ */
+void terror(char *s);
+
+
+/**
+ * Function to read char by char buffered from a FILE
+ */
+char buffered_fgetc(char *buffer, uint64_t *pos, uint64_t *read, FILE *f);
+
+
+void get_num_seqs_and_length(char * seq_buffer, uint64_t * n_seqs, uint64_t * t_len, LoadingDBArgs * ldbargs);
+
+/*
+    Generates a queue of tasks for threads
+*/
+Queue * generate_queue(Head * queue_head, uint64_t t_reads, uint64_t n_threads, uint64_t levels);
+
+/*
+    Prints a queue task
+*/
+void print_queue(Queue * q);
+
+/*
+    Gets the next task to do when a pthread is free
+*/
+Queue * get_task_from_queue(Head * queue_head, pthread_mutex_t * lock);
+
+uint64_t quick_pow4(uint64_t n);
+
+uint64_t quick_pow4byLetter(uint64_t n, const char c);
+
+uint64_t hashOfWord(const unsigned char * word, uint32_t k);
+
+uint64_t asciiToUint64(const char *text);
+
+#endif /* COMMON_FUNCTIONS_H */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/covident.c	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,65 @@
+/*
+for i in $IMS/_distribution; do ./covident $i computed/$(basename $i); done
+gcc -O3 -D_FILE_OFFSET_BITS=64 covident.c -o covident
+**********/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <inttypes.h>
+
+#define MAXLID	200
+#define OUT_MATSIZE 101
+
+
+
+int main(int argc, char ** av){
+	
+	if(argc != 3){ printf("USE:covident in output.MAT\n"); exit(-1); }
+	
+	
+	FILE * f, * g;
+	f = fopen(av[1], "rt");
+	if(f == NULL){
+		printf("Error opening input file\n");
+		exit(-1);
+	}
+	g = fopen(av[2], "wt");
+	if(g == NULL){
+		printf("	Error opening output file %s\n", av[2]);
+		exit(-1);
+	}
+	
+	
+	uint64_t matrix[OUT_MATSIZE][OUT_MATSIZE];	
+	uint64_t i,j;
+	for(i=0;i<OUT_MATSIZE;i++){
+		for(j=0;j<OUT_MATSIZE;j++){
+			matrix[i][j] = 0;
+		}
+	}
+	uint64_t cov, ident, len;
+	while(!feof(f)){
+		
+		if(3 != fscanf(f, "%"PRIu64" %"PRIu64" %"PRIu64, &cov, &ident, &len) && !feof(f)){ printf("Did not read 3\n"); exit(-1);}
+		matrix[cov][ident]++;
+		
+		
+	}
+	
+	
+	for(i=0;i<OUT_MATSIZE;i++){
+		for(j=0;j<OUT_MATSIZE;j++){
+			fprintf(g, "%"PRIu64"\t", matrix[i][j]);
+		}
+		fprintf(g, "\n");
+	}
+	
+	fclose(f);
+	fclose(g);
+	return 0;
+}
+
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/reverseComplement.c	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,123 @@
+/* reverseComplement.c
+   Program reading a FASTA file as input (one or multiple sequence)
+   and then returning the reverse complementary sequence in the output file.
+   It is important to note that for multiple sequence file the first input
+   sequence is the last one at the output file and the last one in the input
+   is the first one in the output.
+   oscart@uma.es
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <inttypes.h>
+#include "commonFunctions.h"
+
+#define SEQSIZE 2000000000
+#define READINPUT 10000
+#define WSIZE 32
+#define NREADS 1000000
+
+int main(int ac, char** av) {
+	FILE *fIn, *fOut;
+	int64_t i, j, nR, seqLen = 0;
+	char *seq, c, toW;
+	long *offset = NULL;
+
+	if (ac != 3)
+		terror("USE: reverseComplement seqFile.IN reverseComplementarySeq.OUT");
+
+	/**
+	 * Allocating memory for the sequence
+	 * Fixed amount of memory, change it to loadSeqDB?
+	 */
+	if ((seq = (char*) malloc(SEQSIZE)) == NULL)
+		terror("memory for Seq");
+
+	if ((fIn = fopen(av[1], "rt")) == NULL)
+		terror("opening IN sequence FASTA file");
+
+	if ((fOut = fopen(av[2], "wt")) == NULL)
+		terror("opening OUT sequence Words file");
+	
+	if ((offset = (long *) malloc(sizeof(long)*NREADS)) == NULL)
+		terror("memory for offsets");
+
+	for(i=0;i<NREADS;i++){
+		offset[i]=0;
+	}
+
+	nR = 0;
+	c = fgetc(fIn);
+	while(!feof(fIn)){
+		if(c == '>'){
+			offset[nR++] = ftell(fIn)-1;
+		}
+		c = fgetc(fIn);
+	}
+
+	for(i=nR-1; i>=0; i--){
+		fseek(fIn, offset[i], SEEK_SET);
+		//READ and write header
+		fgets(seq, READINPUT, fIn);
+		
+		fprintf(fOut, "%s", seq);
+		//READ and write sequence
+		c = fgetc(fIn);
+		while(c != '>' && !feof(fIn)){
+			if(isupper(c) || islower(c)){
+				seq[seqLen++]=c;
+			}
+			c = fgetc(fIn);
+		}
+		for(j=seqLen-1; j >= 0; j--){
+			switch(seq[j]){
+				case 'A':
+					toW = 'T';
+					break;
+				case 'C':
+					toW = 'G';
+					break;
+				case 'G':
+					toW = 'C';
+					break;
+				case 'T':
+					toW = 'A';
+					break;
+				case 'U':
+					toW = 'A';
+					break;
+				case 'a':
+					toW = 't';
+					break;
+				case 'c':
+					toW = 'g';
+					break;
+				case 'g':
+					toW = 'c';
+					break;
+				case 't':
+					toW = 'a';
+					break;
+				case 'u':
+					toW = 'a';
+					break;
+				default:
+					toW = seq[j];
+					break;
+			}
+			fwrite(&toW, sizeof(char), 1, fOut);
+		}
+		toW='\n';
+		fwrite(&toW, sizeof(char), 1, fOut);
+		seqLen=0;
+	}
+
+	fclose(fIn);
+	fclose(fOut);
+
+	return 0;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMSAME/src/structs.h	Thu Dec 13 08:57:14 2018 -0500
@@ -0,0 +1,144 @@
+#ifndef STRUCTS_H
+#define STRUCTS_H
+
+#include <inttypes.h>
+
+//Structs required for the dotplot workflow
+#define MAXLID 200
+//#define READBUF 2000000000 //2 GB
+#define READBUF 500000000 //500MB
+#define INITSEQS 3000 //Number of starting sequences (in database)
+#define POINT 4
+
+#define FIXED_K 12
+
+#define MAXLID 200
+#define ALIGN_LEN 60 //For NW alignment
+#define MAX_READ_SIZE 10000 //Maximum length of read to have a portion of the table allocated
+#define MAX_WINDOW_SIZE 1000 //Maximum window length to explore NW table
+//#define POOL_SIZE 2500000000 // by 16 bytes it is 40 GB
+#define POOL_SIZE 12500000 // 1 GB if 16 bytes
+#define MAX_MEM_POOLS 128 
+#define FIXED_LOADING_THREADS 4
+
+#define FALSE 0
+#define TRUE 1
+
+extern uint64_t custom_kmer;
+
+typedef char _vector_char __attribute__ ((vector_size (32*sizeof(char))));
+
+//Struct for linked list of positions
+typedef struct linked_list_pos{
+    uint64_t pos;
+    uint64_t s_id;
+    //uint64_t extended_hash;
+    struct linked_list_pos * next;
+} llpos;
+
+typedef struct AVL_Node{
+    uint64_t key;
+    struct AVL_Node * left;
+    struct AVL_Node * right;
+    uint64_t height;
+    uint64_t count;
+    llpos * next;
+} AVLTree;
+
+//Struct for memory pool por lists
+typedef struct mempool_l{
+    llpos * base;
+    uint64_t current;
+} Mempool_l;
+
+//Struct for memory pool por AVLtree
+typedef struct mempool_AVL{
+    AVLTree * base;
+    uint64_t current;
+} Mempool_AVL;
+
+
+//Struct for a whole sequence(s) data
+typedef struct seqinfo{
+    unsigned char * sequences;
+    uint64_t * start_pos;
+    uint64_t total_len;
+    uint64_t n_seqs;
+} SeqInfo;
+
+//Struct for the alignment of a quick hit
+typedef struct quickfrag{
+    uint64_t x_start;
+    uint64_t y_start;
+    uint64_t t_len;
+    long double coverage;
+    long double e_value;
+} Quickfrag;
+
+typedef struct point{
+    uint64_t x;
+    uint64_t y;
+} Point;
+
+typedef struct container{
+    llpos * table[4][4][4][4][4][4][4][4][4][4][4]; // One reduced; A,C,G,T tables in use
+} Container;
+
+typedef struct AVLcontainer{
+    AVLTree root[4][4][4][4][4][4][4][4][4][4][4];
+} AVLContainer;
+
+typedef struct{
+    char * temp_seq_buffer;
+    SeqInfo * data_database;
+    uint64_t t_len;
+    uint64_t word_size;
+    uint64_t read_from;
+    uint64_t read_to;
+    uint64_t contained_reads;
+    uint64_t base_coordinates;
+    uint64_t n_allocs;
+    char thread_id;
+    AVLContainer * ct;
+    Mempool_l * mp;
+    uint64_t n_pools_used;
+    uint64_t n_pools_used_AVL;
+    Mempool_AVL * mp_AVL;
+} LoadingDBArgs;
+
+struct cell{
+    int64_t score;
+    uint64_t xfrom;
+    uint64_t yfrom;
+};
+
+struct positioned_cell{
+    int64_t score;
+    uint64_t xpos;
+    uint64_t ypos;
+};
+
+struct best_cell{
+    struct positioned_cell c;
+    uint64_t j_prime;
+};
+
+typedef struct{
+    uint64_t identities;
+    uint64_t length;
+    uint64_t igaps;
+    uint64_t egaps;
+} BasicAlignment;
+
+typedef struct queue{
+    uint64_t r1; //reads region
+    uint64_t r2;
+    struct queue * next;
+} Queue;
+
+typedef struct{
+    Queue * head;
+} Head;
+
+
+#endif