# HG changeset patch # User bitlab # Date 1544915050 18000 # Node ID 762009a9189549413d3826bdcd02ba2f7a0027fa Uploaded diff -r 000000000000 -r 762009a91895 IMSAME/IMSAME.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IMSAME/IMSAME.xml Sat Dec 15 18:04:10 2018 -0500 @@ -0,0 +1,15 @@ + + A Pairwise Incremental Multi-Staged Alignment Method for Metagenomes Comparison + + + + + + + + + /home/galaxy-bitlab/galaxy/tools/IMSAME/bin/IMSAME -query $query -db $db -evalue $evalue -coverage $coverage -identity $identity -kmer $kmer -out $output --full + + + + diff -r 000000000000 -r 762009a91895 IMSAME/LICENSE --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IMSAME/LICENSE Sat Dec 15 18:04:10 2018 -0500 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + 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 . + +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 +. + + 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 +. diff -r 000000000000 -r 762009a91895 IMSAME/bin/IMSAME Binary file IMSAME/bin/IMSAME has changed diff -r 000000000000 -r 762009a91895 IMSAME/bin/all_vs_all_metagenomes_IMSAME.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IMSAME/bin/all_vs_all_metagenomes_IMSAME.sh Sat Dec 15 18:04:10 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 diff -r 000000000000 -r 762009a91895 IMSAME/bin/combine Binary file IMSAME/bin/combine has changed diff -r 000000000000 -r 762009a91895 IMSAME/bin/revComp Binary file IMSAME/bin/revComp has changed diff -r 000000000000 -r 762009a91895 IMSAME/src/IMSAME.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IMSAME/src/IMSAME.c Sat Dec 15 18:04:10 2018 -0500 @@ -0,0 +1,760 @@ +/********* + +File IMSAME.c +Author EPW +Description Computes an incremental alignment on reads versus reads using n threads + +USAGE Usage is described by calling ./IMSAME --help + + + +**********/ + + +#include +#include +#include +#include +#include +#include +#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'){ + 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 max) max = final_db.start_pos[i+2] - final_db.start_pos[i+1]; + //getchar(); + } + printf("%"PRIu64"\n", max); + */ + + + + + + for(i=0;iroot); + free(ct_B->root); + free(ct_C->root); + free(ct_D->root); + //free(ct); + free(threads); + free(hta); + + + + for(i=0;i1 (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 +#include +#include +#include +#include +#include +#include +#include +#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;r1table[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;zidentities++; + }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= 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= 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= 0.5){ + y++; + error = error - 1; + } + } + + /* + if(p3.x == 799 && p3.y == 2497){ + for(i=0;i ", 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;i1) 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= 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 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= 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= 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;zlength++; + 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;zlength++; + 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;kkey = 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 diff -r 000000000000 -r 762009a91895 IMSAME/src/alignmentFunctions.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IMSAME/src/alignmentFunctions.h Sat Dec 15 18:04:10 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); + + diff -r 000000000000 -r 762009a91895 IMSAME/src/combine_reads.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IMSAME/src/combine_reads.c Sat Dec 15 18:04:10 2018 -0500 @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#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 "); + + + 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; +} diff -r 000000000000 -r 762009a91895 IMSAME/src/commonFunctions.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IMSAME/src/commonFunctions.c Sat Dec 15 18:04:10 2018 -0500 @@ -0,0 +1,283 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#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> 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 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= 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 +#include +#include +#include + +#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 +#include +#include +#include +#include +#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'){ + 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; +} + + diff -r 000000000000 -r 762009a91895 IMSAME/src/structs.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IMSAME/src/structs.h Sat Dec 15 18:04:10 2018 -0500 @@ -0,0 +1,144 @@ +#ifndef STRUCTS_H +#define STRUCTS_H + +#include + +//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