├── COPYING ├── ChangeLog ├── Makefile ├── Readme.md └── src ├── BloomFilter.cpp ├── BloomFilter.h ├── ReverseBloomFilter.cpp ├── ReverseBloomFilter.h ├── Rscripts ├── Q20Q30.R ├── base.R └── quality.R ├── gc.cpp ├── gc.h ├── global_parameter.h ├── global_variable.cpp ├── global_variable.h ├── mGzip.cpp ├── mGzip.h ├── main.cpp ├── peFilterTmpOut.h ├── peprocess.cpp ├── peprocess.h ├── processHts.cpp ├── processHts.h ├── processStLFR.cpp ├── processStLFR.h ├── process_argv.cpp ├── process_argv.h ├── read_filter.cpp ├── read_filter.h ├── rmdup.cpp ├── rmdup.h ├── seprocess.cpp ├── seprocess.h ├── sequence.cpp └── sequence.h /COPYING: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 3, 29 June 2007 4 | 5 | Copyright © 2007 Free Software Foundation, Inc. 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The GNU General Public License is a free, copyleft license for software and other kinds of works. 12 | 13 | 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. 14 | 15 | 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. 16 | 17 | 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. 18 | 19 | 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. 20 | 21 | 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. 22 | 23 | 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. 24 | 25 | 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. 26 | 27 | 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. 28 | 29 | The precise terms and conditions for copying, distribution and modification follow. 30 | 31 | TERMS AND CONDITIONS 32 | 33 | 0. Definitions. 34 | 35 | “This License” refers to version 3 of the GNU General Public License. 36 | 37 | “Copyright” also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. 38 | 39 | “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. 40 | 41 | 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. 42 | 43 | A “covered work” means either the unmodified Program or a work based on the Program. 44 | 45 | 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. 46 | 47 | 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. 48 | 49 | 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. 50 | 51 | 1. Source Code. 52 | 53 | 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. 54 | 55 | 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. 56 | 57 | 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. 58 | 59 | 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. 60 | 61 | The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. 62 | 63 | The Corresponding Source for a work in source code form is that same work. 64 | 65 | 2. Basic Permissions. 66 | 67 | 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. 68 | 69 | 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. 70 | 71 | Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 72 | 73 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 74 | 75 | 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. 76 | 77 | 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. 78 | 79 | 4. Conveying Verbatim Copies. 80 | 81 | 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. 82 | 83 | 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. 84 | 85 | 5. Conveying Modified Source Versions. 86 | 87 | 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: 88 | 89 | a) The work must carry prominent notices stating that you modified it, and giving a relevant date. 90 | 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”. 91 | 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. 92 | 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. 93 | 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. 94 | 95 | 6. Conveying Non-Source Forms. 96 | 97 | 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: 98 | 99 | 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. 100 | 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. 101 | 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. 102 | 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. 103 | 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. 104 | 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. 105 | 106 | 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. 107 | 108 | “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. 109 | 110 | 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). 111 | 112 | 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. 113 | 114 | 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. 115 | 116 | 7. Additional Terms. 117 | 118 | “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. 119 | 120 | 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. 121 | 122 | 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: 123 | 124 | a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or 125 | 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 126 | 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 127 | d) Limiting the use for publicity purposes of names of licensors or authors of the material; or 128 | e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or 129 | 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. 130 | 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. 131 | 132 | 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. 133 | 134 | 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. 135 | 136 | 8. Termination. 137 | 138 | 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). 139 | 140 | 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. 141 | 142 | 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. 143 | 144 | 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. 145 | 146 | 9. Acceptance Not Required for Having Copies. 147 | 148 | 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. 149 | 150 | 10. Automatic Licensing of Downstream Recipients. 151 | 152 | 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. 153 | 154 | 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. 155 | 156 | 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. 157 | 158 | 11. Patents. 159 | 160 | 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”. 161 | 162 | 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. 163 | 164 | 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. 165 | 166 | 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. 167 | 168 | 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. 169 | 170 | 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. 171 | 172 | 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. 173 | 174 | 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. 175 | 176 | 12. No Surrender of Others' Freedom. 177 | 178 | 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. 179 | 180 | 13. Use with the GNU Affero General Public License. 181 | 182 | 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. 183 | 184 | 14. Revised Versions of this License. 185 | 186 | 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. 187 | 188 | 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. 189 | 190 | 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. 191 | 192 | 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. 193 | 194 | 15. Disclaimer of Warranty. 195 | 196 | 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. 197 | 198 | 16. Limitation of Liability. 199 | 200 | 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. 201 | 202 | 17. Interpretation of Sections 15 and 16. 203 | 204 | 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. 205 | 206 | END OF TERMS AND CONDITIONS 207 | 208 | How to Apply These Terms to Your New Programs 209 | 210 | 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. 211 | 212 | 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. 213 | 214 | 215 | Copyright (C) 216 | 217 | This program is free software: you can redistribute it and/or modify 218 | it under the terms of the GNU General Public License as published by 219 | the Free Software Foundation, either version 3 of the License, or 220 | (at your option) any later version. 221 | 222 | This program is distributed in the hope that it will be useful, 223 | but WITHOUT ANY WARRANTY; without even the implied warranty of 224 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 225 | GNU General Public License for more details. 226 | 227 | You should have received a copy of the GNU General Public License 228 | along with this program. If not, see . 229 | Also add information on how to contact you by electronic and paper mail. 230 | 231 | If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: 232 | 233 | Copyright (C) 234 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 235 | This is free software, and you are welcome to redistribute it 236 | under certain conditions; type `show c' for details. 237 | 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”. 238 | 239 | 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 . 240 | 241 | 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 . 242 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | 2012-12-19 2 | * Release 1.1.1 3 | * (FilterProcessor.cpp) Change the method of determining low mean-quality for PE reads 4 | From: Sum(Q)[read1,read2] / (len(read1)+len(read2)) < Threshold 5 | To: Sum(Q)[read1]/(len(read1) < Threshold || Sum(Q)[read2]/(len(read2) < Threshold 6 | 7 | 2012-12-21 8 | * (PeBuffer.cpp::getReads) Initialize result1 and result2 9 | * (PeBuffer.cpp::readTask) Initialize result at very beginning 10 | 11 | 2012-12-25 12 | * Release 1.1.2 13 | * Change deduplication module, replace BTree with std::map 14 | * (FilterProcessor) Use External sort and merge for low memory usage 15 | 16 | 2013-4-7 17 | * Release 1.2.0.2 18 | * sRNA module start outputing two files: small.txt, clean.txt 19 | * sRNA module, length distribution starts from 10 20 | * Change SRNACleanFA.cpp and SRNAProcessor.h 21 | 22 | 2013-4-9 23 | * Release 1.3.0 24 | * Tile-filter function added to FqBuffer and PeBuffer 25 | * Filter, FilterSRNA, FilterDGE modules support Tile-filter function 26 | * Filter, FilterSRNA, FilterDGE modules all use FqBuffer and PeBuffer 27 | * When filtering tile, FilterSRNA and FilterDGE will not mandatory output anymore, while DNA remains the same 28 | 29 | 2013-4-9 30 | * Release 1.4.0 31 | * FilterMeta added 32 | 33 | 2014-9-10 34 | * Release 1.4.2 35 | * Upper limit of length changed to 512 for FilterMeta 36 | 37 | 2014-9-10 38 | * Release 1.4.2.1 39 | * Upper limit of length changed to 1024 for Filter 40 | 41 | 2014-10-14 42 | * Release 1.4.2 43 | * Bug fixed when determing seq length of read2 44 | * Bug fixed when outputing seq length of read2 in FilterProcessor.cpp 45 | 46 | 2015-01-05 47 | * Release 1.5 48 | * Add --seqtype to process another name format 49 | * Add --polyatype for 2 methods of strip PolyA, 0 for AND, 1 for OR 50 | * Load adapterlist first and align adapter then 51 | * Filter index 52 | 53 | 2015-11-12 54 | * Release 1.5.3 55 | * Add –cutAdaptor which cut adapters at ends of reads. Only reads shorter then –BaseNum will be aborted。 -cut will be ignored when applied this param 56 | * Add –BaseNum which used with -cutAdapter 57 | * No more support of adapter list 58 | 59 | 2016-03-18 60 | * Fix bug of keeping raw gz data open when filtering tile 61 | 62 | 2016-04-25 63 | * Release 1.5.4 64 | * Fix bug of low data volume when filtering SE data 65 | 66 | 2016-06-30 67 | * Release 1.5.5 68 | * Add -3 to filter module, which accompanied with -d param to output duplicated reads while not counting them in QC stats 69 | 70 | 2016-08-22 71 | * Release 1.5.6 72 | * Add --fov which supporting filtering by FOV num in name of BGI-SEQ data, which can be used with --tile 73 | 74 | 2016-12-8 75 | * Release 1.6.0 76 | * Support compling for Windows 77 | * Support Streaming IO 78 | 79 | 2017-9-15 80 | * Release 1.6.2 81 | * Change CMakeList for automatic compling 82 | * Add Python script in assist of Streaming processing 83 | * Add plotting R-scripts for QC stats 84 | 85 | 2018-4-11 86 | * Release 1.6.3 87 | * Bug fixed of incompatibility between outType and Rmdup 88 | * Bug fixed when performing adapter cutting and length filtering 89 | * Add PolyX filtering function 90 | 91 | 2018-4-23 92 | * Release 1.6.4 93 | * Fullfil CMakeList 94 | * Add QC stats of trimming position 95 | * Optimize trimming algorithm 96 | * Fix most warning of compiling 97 | 98 | 2018-6-30 99 | * Release 1.6.5 100 | * Add low-Q filtering function to sRNA module 101 | * Bug fixed when filtering adapter 102 | * Add function of filtering contaminants 103 | 104 | 2018-8-17 105 | * Release 2.0 beta 106 | * Delete filterDGE module 107 | * Unify running logic of all modules, which mainly differ in adapter determination now. 108 | * Main pipeline includes counting raw data, filtering data and counting filtered data. 109 | * Merge params of modules. Default values mainly derive from filter module, so users should be cautious when using other modules. 110 | * filter and filterMeta modules support SE and PE, filtersRNA support SE only. 111 | * filter and filterMeta modules update adapter determination algorithms. 112 | * Have 2 running modes now: ssd and non-ssd. It is recommended to use ssd mode on high-speed IO storage(like SSD). Default to be non-ssd. 113 | * Remove deduplication function. 114 | * As thread number increases, running efficiency improves obviously. It costs 70 mins to process 1.3G reads (PE50) with 16 threads at non-ssd mode. 115 | 116 | 2018-12-1 117 | * Release 2.0.1 118 | * Bugs fixed 119 | * Change of split module for fastq files after filtering 120 | * Loose standard of determining adapters 121 | 122 | 2018-12-26 123 | * Release 2.0.2 124 | * Promise order consistent for multi-threading 125 | * Lower MEM and accelerate much 126 | 127 | 2019-1-10 128 | * Release 2.0.3 129 | * Bugs fixed of SE trimming 和 fov filtering 130 | 131 | 2019-2-1 132 | * Release 2.0.5 133 | * Add extraction function on filtered data. 134 | * Fix bugs of data loading 135 | 136 | 2019-3-31 137 | * Release 2.0.6 138 | * Fix the bug of unstead output 139 | * Optimize algorithms of global determination of contaminants 140 | 141 | 2019-5-17 142 | * Release 2.0.7 143 | * Fix bugs of running on MacOS and others 144 | 145 | 2019-6-28 146 | * Release 2.0.8 147 | * Update README to adapt to 2.X 148 | * Optimize the algorithm of filtering FOV 149 | 150 | 2019-7-24 151 | * Release 2.1.0 152 | * Change the output order to the same as input, which accelerate the split function 153 | * Add randomness of random extraction 154 | 155 | 2019-12-3 156 | * Release 2.1.1 157 | * Bugs fixed of SE trim、polyX and random extraction 158 | 159 | 2020-4-19 160 | * Release 2.1.2 161 | * Add filterHts module 162 | 163 | 2020-7-23 164 | * Release 2.1.3 165 | * Support adapter list as input 166 | * Add filterStLFR module 167 | * Fix bugs of adapter detection in filterHts module 168 | 169 | 2020-8-27 170 | * Release 2.1.4.beta.1 171 | * Bugs fixed 172 | 173 | 2020-11-27 174 | * Release 2.1.4.beta.3 175 | * add rmdup function by adopting reverse Bloom filter 176 | 177 | 2020-12-17 178 | * Release 2.1.5 179 | * add rmdup function by adopting reverse Bloom filter 180 | 181 | 2021-4-30 182 | * Release 2.1.6 183 | * Fix the bug of detecting adapter in the head of read 184 | * Increase the max threading num from 48 to 72 185 | 186 | 2022-1-16 187 | * Release 2.1.7 188 | * Fix the bug when totalReadsNum parameter is too large to do the extraction 189 | 190 | 2023-8-31 191 | * Release 2.1.8 192 | * Assign max value of Quality Score by parameter 193 | * Automatically set the max threading number by software 194 | * Max supported read length increased from 500 to 1000 195 | 196 | 2024-3-28 197 | * Release 2.1.9 198 | * Fix the bug of quality value getting out of bounds and some statistical values overflowing 199 | * Remove the obsolete description about parameter L 200 | * Add some description about usage of config file 201 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | cc := g++ 2 | src := ./src 3 | obj := ./obj 4 | 5 | MIN_GCC_VERSION = 4.7 6 | GCC_VERSION := $(shell gcc -dumpversion) 7 | IS_GCC_ABOVE_MIN_VERSION := $(shell echo `gcc -dumpversion | cut -f1-2 -d.` \>= $(MIN_GCC_VERSION) | bc ) 8 | ifeq "$(IS_GCC_ABOVE_MIN_VERSION)" "1" 9 | GCC_VERSION_STRING := "GCC version Passes, $(GCC_VERSION) >= $(MIN_GCC_VERSION)" 10 | else 11 | GCC_VERSION_STRING := "Warning: GCC version $(GCC_VERSION) is lower than $(MIN_GCC_VERSION)." 12 | endif 13 | $(info $(GCC_VERSION_STRING)) 14 | 15 | 16 | 17 | all=SOAPnuke 18 | exe=SOAPnuke 19 | MIN_ZLIB_VERSION = 1.2.3.5 20 | #ZLIB_VERSION := $(shell readlink $(whereis libz) | sed 's/libz.so.\(.*\)$/\1/g') 21 | ZLIBLOCATION:=$(shell whereis libz) 22 | ZLIB_VERSION=$(shell readlink $(ZLIBLOCATION) | awk -F 'so.' '{print $$NF}') 23 | #$(info $(ZLIB_VERSION_STRING)) 24 | IS_ZLIB_ABOVE_MIN_VERSION := $(shell expr "$(ZLIB_VERSION)" ">=" "$(MIN_ZLIB_VERSION)") 25 | ifeq "$(IS_ZLIB_ABOVE_MIN_VERSION)" "1" 26 | ZLIB_VERSION_STRING := "ZLIB version Passes, $(ZLIB_VERSION) >= $(MIN_ZLIB_VERSION)" 27 | else 28 | ZLIB_VERSION_STRING := "Warning: ZLIB version $(ZLIB_VERSION) is lower than $(MIN_ZLIB_VERSION)." 29 | endif 30 | $(info $(ZLIB_VERSION_STRING)) 31 | 32 | #set USEHTS true if you want use filterHts module 33 | USEHTS=false 34 | 35 | source := $(wildcard ${src}/*.cpp) 36 | source := $(filter-out ./src/mGzip.cpp, $(source)) 37 | LIBS := -lz -lpthread -labc 38 | LD_FLAGS := $(foreach librarydir,$(LIBRARY_DIRS),-L$(librarydir)) $(LIBS) $(LD_FLAGS) 39 | $(warning $(LD_FLAGS)) 40 | DFLAG=-lz -lpthread 41 | CXXFLAGS=-std=c++11 -g -O3 42 | ifeq "$(USEHTS)" "true" 43 | CXXFLAGS+=-D _PROCESSHTS 44 | DFLAG+= -lhts 45 | else 46 | source := $(filter-out ./src/processHts.cpp, $(source)) 47 | endif 48 | #$(warning $(source)) 49 | objfile := $(patsubst %.cpp,${obj}/%.o,$(notdir ${source})) 50 | objfile:=$(filter-out processHts.o,$(objfile)) 51 | $(exe):${objfile} 52 | $(cc) $(objfile) -o $@ $(DFLAG) 53 | ${obj}/%.o:${src}/%.cpp mk_dir 54 | $(cc) $(CXXFLAGS) -c $< -o $@ 55 | mk_dir: 56 | @if test ! -d $(obj);\ 57 | then\ 58 | mkdir $(obj);\ 59 | fi 60 | .PHONY:clean 61 | clean: 62 | rm -f obj/*.o 63 | rm -f SOAPnuke 64 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Introduction 4 | 5 | As a novel analysis tool developed for quality control and preprocessing of FASTQ and SAM/BAM data, SOAPnuke includes 5 modules for different usage scenarios, namely **filter**, **filterHts**, **filterStLFR**, **filtersRNA** and **filterMeta**. 6 | 7 | **filter**: Preprocess FASTQ files, include trimming (adapter, low quality end and etc.) if set, discarding (adapter, low quality, high N base ratio and etc.) and generating statistic report. 8 | 9 | **filterHts**: Preprocess BAM/CRAM files. The process procedure remains the same as filter module. 10 | 11 | (Note: Input BAM/CRAM files should be sorted by readID when it contains Paired-End data.) 12 | 13 | **filterStLFR**: Preprocess stLFR FASTQ files, added with a barcode-detection step at the beginning, and support FASTQ files list as input. 14 | 15 | **filtersRNA**: Preprocess sRNA FASTQ files. Since it is still under testing, please inform us if you encounter any bug. 16 | 17 | **filterMeta**: Preprocess Meta FASTQ files. Since it is still under testing, please inform us if you encounter any bug. 18 | 19 | 20 | ## PERFORMANCE 21 | 22 | SOAPnuke 2.X version shows an excellent performance compared with 1.X version. An great acceleration has been accomplished by refactoring the whole framework, optimizing multithreading and IO. 23 | 24 | This table presents a benchmark result on 628M Paired-End 150bp reads. As thread number increases, user time obviously decreases. 25 | 26 | |Software | ThreadNum | RunTime(min) | MaxMem(MB)|Parameter| 27 | | :-----| ----: | :----: | :----: | :----: | 28 | | SOAPnuke | 16| 35.7 |2270 | filter module 29 | | SOAPnuke | 8 | 48.4 |881 | filter module 30 | | SOAPnuke | 4 | 72.1 |275 | filter module 31 | | fastp | 8 | 62.0 |1004 |-A -w 8| 32 | 33 | 34 | ## Getting started 35 | #### Requirements 36 | gcc: 4.7 or higher 37 | zlib: 1.2.3.5 or higher 38 | htslib: 1.9 or higher 39 | pthread library 40 | 41 | #### Install 42 | git clone https://github.com/BGI-flexlab/SOAPnuke.git 43 | cd SOAPnuke 44 | 45 | // Considering rarely been used and complex compile dependency, we turn off filterHts module by default. 46 | // If you want to use filterHts module, please set USEHTS true in Makefile like this: 47 | // USEHTS=true 48 | 49 | make 50 | 51 | 52 | #### QuickStart 53 | 54 | All usages start with executable file **SOAPnuke**, and different modules are invoked with different sub-commands. Here are some usage examples: 55 | ```shell 56 | #filter: 57 | 58 | #QC the input fastq and extract 10M clean reads to the output files. 59 | echo "totalReadsNum=10000000" >config.txt 60 | 61 | SOAPnuke filter -1 test.r1.fq.gz -2 test.r2.fq.gz -C clean_1.fq.gz -D clean_2.fq.gz -o result -T 8 -c config.txt 62 | 63 | 64 | #filterHts: 65 | 66 | SOAPnuke filterHts --ref chr21.fa -1 input.bam -2 output.cram -o result 67 | SOAPnuke filterHts -1 input.bam -2 output.bam -o result 68 | 69 | 70 | #filterStLFR: 71 | 72 | filterStLFR -1 fq1.list -2 fq2.list -C clean1.gz -D clean2.gz -o result -T 8 -c config 73 | ``` 74 | 75 | #### Detailed QC steps 76 | 77 | If set trim-related parameters(no trim if not set), do **trimming** first: 78 | 79 |
80 | 81 | **Read ID** 82 | 83 | If parameter “index” set in config file, remove index sequence from read ID. 84 | 85 | Once “index” is set, if seqType is 0(default value), read ID would be expected like: 86 | 87 | @FCD1PB1ACXX:4:1101:1799:2201#GAAGCACG/2, 88 | 89 | “#GAAGCACG” would be removed then. 90 | 91 | If seqType is 1, read ID would be expected like: 92 | 93 | @HISEQ:310:C5MH9ANXX:1:1101:3517:20432:N:0:TCGGTCAC, 94 | 95 | “:TCGGTCAC” would be removed then. 96 | 97 | **Read sequence and quality** 98 | 99 | First, the cutting length of all trimming type would be calculated, including hard trim, low quality end trim, adapter trim and tail-polyG trim. The longest cutting would be performed. 100 | 101 | - hard trim: directly remove a certain length sequence from head or tail on read sequence 102 | - low quality end trim: remove low quality base starting from end until quality higher than cutoff 103 | - adapter trim: when adapter was found, the base sequence and quality sequence would be trimmed from the start position which match adapter 104 | - tail-polyG trim: if polyG number is greater than cutoff, then these polyG sequence in tail would be trimmed 105 | 106 | Then do **filtering**: 107 | 108 | Note that the read pair would be both discarded both when any of which fails to pass QC. 109 | 110 | Priority(High to Low): 111 | 112 | - **Tile, may be used in some types of BGI data.** 113 | 114 |         115 | If you want to discard reads with certain tile ID, set the parameter like “1101-1104,1205”. 116 | 117 | - **Fov, may be used in data from zebra-platform.** 118 | 119 |         120 | If you want to discard reads with certain FOV ID, set the parameter like “C001R003,C003R004”. 121 | 122 | - **Minimal read length** 123 | 124 |         125 | Discard a read with sequence length shorter than the parameter. 126 | 127 | - **Maximal read length** 128 | 129 |         130 | Discard a read with sequence length longer than the parameter. 131 | 132 | - **N ratio** 133 | 134 |         135 | Discard a read with N base ratio not smaller than the parameter. 136 | 137 | - **High A ratio** 138 | 139 |         140 | Discard a read with A base ratio not smaller than the parameter. 141 | 142 | - **polyX number (X means any one base)** 143 | 144 |         145 | Discard a read with poly-X number not smaller than the parameter. 146 | 147 | - **Low quality base ratio** 148 | 149 |         150 | Discard a read with low-quality bases ratio not smaller than the parameter. 151 | 152 | - **Mean quality** 153 | 154 |         155 | Discard a read of which mean quality of sequence smaller than the parameter. 156 | 157 | - **Overlapped length if PE** 158 | 159 |         160 | Discard a read pair which is suspected to be overlapped longer then the parameter. 161 | 162 | - **Adapter** 163 | 164 |         165 | Discard a read which contains an adapter. 166 | 167 | ## Parameter 168 | 169 | ### Commonly used parameters 170 | 171 |
172 | 173 | #### filter module 174 | 175 | - -1 / --fq1 176 | 177 | fq1 file(required), .gz or normal text format are both supported 178 | 179 | - -2 / --fq2 180 | 181 | fq2 file(used when process PE data), format should be same as fq1 file, both are gz or both are normal text 182 | 183 | - -C / --cleanFq1 184 | 185 | reads which passed QC from fq1 file would output to this file 186 | 187 | - -D / --cleanFq2 188 | 189 | reads which passed QC from fq2 file would output to this file 190 | 191 | - -o / --out 192 | 193 | Output directory. Processed fq files and statistical results would be output to here 194 | 195 | - -f / --adapter1 196 | 197 | adapter sequence or list file of read1 198 | 199 | - -r / --adapter2 200 | 201 | adapter sequence or list file of read2 202 | 203 | - -J / --ada_trim 204 | 205 | trim read when find adapter, it’s a bool parameter, default is false which means discard the read when find adapter 206 | 207 | - -T / --thread 208 | 209 | threads number used in process, default value is 6 210 | 211 | - -c / --configFile 212 | 213 | config file which include uncommonly used parameters. Each line contains a parameter, e.g., for value needed parameter: adaMis=2, for bool parameter: contam_trim, which means set mode as discard when find contaminant sequence 214 | 215 | - -l / --lowQual 216 | 217 | low quality threshold, default value is 5 218 | 219 | - -q / --qualRate 220 | 221 | low quality rate threshold, default value is 0.5 222 | 223 | - -n / --nRate 224 | 225 | N rate threshold, default value is 0.05 226 | 227 | - -m / --mean 228 | 229 | low average quality threshold, if you want discard reads with low average quality, you can set a value. The software do NOT check this item by default 230 | 231 | - -p / --highA 232 | 233 | ratio of A threshold in a read, the software do NOT check this item by default 234 | 235 | - -g / --polyG_tail 236 | 237 | polyG number threshold in read tail, the software do NOT check this item by default 238 | 239 | - -X / --polyX 240 | 241 | polyX number threshold, the software do NOT check this item by default 242 | 243 | - -4 / --minReadLen 244 | 245 | read minimal length, default value is 30 246 | 247 | - -h / --help 248 | 249 | Show help information 250 | 251 | - -v / --version 252 | 253 | Show version information 254 | 255 |
256 | 257 | 258 | #### filterHts module 259 | 260 | Here we only present options different from **filter** module. 261 | 262 | - -E / --ref 263 | 264 | reference file(required when process cram format) 265 | 266 | - -1 267 | 268 | input bam/cram file(required) 269 | 270 | - -2 271 | 272 | output bam/cram file(required) 273 | 274 |
275 | 276 | 277 | #### filterStLFR module 278 | 279 | Here we only present options different from **filter** module. 280 | 281 | - -1 / --fq1 282 | 283 | Support FASTQ files list as input 284 | 285 | - -2 / --fq2 286 | 287 | Support FASTQ files list as input 288 | 289 |
290 | 291 | 292 | ### Uncommonly used parameters 293 | 294 | - ctMatchR 295 | 296 | Contaminant sequence shortest consistent matching ratio [default:0.2] 297 | 298 | - seqType 299 | 300 | Sequence fq name type, 0->old fastq name, 1->new fastq name [0] 301 | 302 | old fastq name: @FCD1PB1ACXX:4:1101:1799:2201#GAAGCACG/2 303 | 304 | new fastq name: @HISEQ:310:C5MH9ANXX:1:1101:3517:2043 2:N:0:TCGGTCAC 305 | 306 | - trimFq1 307 | 308 | trim fq1 file name(gz format) [optional] 309 | 310 | - trimFq2 311 | 312 | trim fq2 file name [optional]. If trim related parameters were set on, these output files would include the total reads which only do trimming. For example, if read A failed QC after trimming, it will still output to -R/-W, but not to -C/-D 313 | 314 | - tile 315 | 316 | tile number to ignore reads, such as [1101-1104,1205] 317 | 318 | - fov 319 | 320 | fov number to ignore reads (only for zebra-platform data), such as [C001R003,C003R004] 321 | 322 | - barcodeListPath 323 | 324 | barcode list of two columns:sequence and barcodeID 325 | 326 | - barcodeRegionStr 327 | 328 | barcode regions, such as: 101_10,117_10,145_10 or 101_10,117_10,133_10 329 | 330 | - notCutNoLFR 331 | 332 | do not cut sequence when fail found barcode 333 | 334 | - inputAsList 335 | 336 | input file list not a file 337 | 338 | - tenX 339 | 340 | output tenX format 341 | 342 | - outFileType 343 | 344 | output file format: fastq or fasta[default: fastq] 345 | 346 | - index 347 | 348 | remove index 349 | 350 | - totalReadsNum 351 | 352 | number/fraction of reads you want to keep in the output clean FASTQ file(cannot be assigned when -w is given). It will extract reads randomly through the total clean FASTQ file by default, you also can get the head reads for save time by add head suffix to the integer 353 | 354 | - trim 355 | 356 | trim some bp of the read's head and tail, they means: (PE type:read1's head and tail and read2's head and tail [0,0,0,0]; SE type:read head and tail [0,0]) 357 | 358 | - trimBadHead 359 | 360 | Trim from head ends until meeting high-quality base or reach the length threshold, set (quality threshold,MaxLengthForTrim) [0,0] 361 | 362 | - trimBadTail 363 | 364 | Trim from tail ends until meeting high-quality base or reach the length threshold, set (quality threshold,MaxLengthForTrim) [0,0] 365 | 366 | - overlap 367 | 368 | filter the small insert size.Not filter until the value exceed 1 [-1] 369 | 370 | - mis 371 | 372 | the maximum mismatch ratio when find overlap between PE reads(depend on -O) [0.1] 373 | 374 | - patch 375 | 376 | reads number of a patch processed [400000] 377 | 378 | - qualSys 379 | 380 | quality system 1:64, 2:33 [default:2] 381 | 382 | - outQualSys 383 | 384 | out quality system 1:64, 2:33 [default:2] 385 | 386 | - maxReadLen 387 | 388 | read max length, default 49 for filtersRNA, the software do NOT check this item by default in other modules 389 | 390 | - cleanOutSplit 391 | 392 | max reads number in each output clean FASTQ file 393 | 394 | - pe_info 395 | 396 | Add /1, /2 at the end of FASTQ name. [default: not add] 397 | 398 | - baseConvert 399 | 400 | convert base when write data, example: TtoU , means convert base T to base U in the output 401 | 402 | - log 403 | 404 | log file output path 405 | 406 |
407 | 408 | ## Plotting 409 | 410 | The three scripts in src/Rscripts/ are used for plotting QC stats from SOAPnuke. 411 | 412 | **Q20Q30.R** 413 | 414 | USAGE: 415 | 416 | Rscript src/Rscripts/Q20Q30.R Distribution_of_Q20_Q30_bases_by_read_position_1.txt Distribution_of_Q20_Q30_bases_by_read_position_2.txt q2030.png 417 | 418 | ![dWZF5F.png](https://s1.ax1x.com/2020/08/26/dWZF5F.png) 419 | 420 |
421 | 422 | **base.R** 423 | 424 | USAGE: 425 | 426 | Rscript src/Rscripts/base.R Base_distributions_by_read_position_1.txt Base_distributions_by_read_position_2.txt raw.png clean.png 427 | 428 | ![dWZiUU.png](https://s1.ax1x.com/2020/08/26/dWZiUU.png) 429 | 430 |
431 | 432 | **quality.R** 433 | 434 | Rscript src/Rscripts/quality.R Base_quality_value_distribution_by_read_position_1.txt Base_quality_value_distribution_by_read_position_2.txt rawQuality.png cleanQuality.png 0 0 435 | 436 | ![dWZAC4.png](https://s1.ax1x.com/2020/08/26/dWZAC4.png) 437 | 438 |
439 | 440 | ## Availability 441 | 442 | SOAPnuke is released under [GPLv3][1]. The latest source code is [freely 443 | available at github][2]. 444 | 445 | 446 | ## Citing SOAPnuke 447 | 448 | - Chen Y, Chen Y, Shi C, et al. SOAPnuke: a MapReduce acceleration-supported software for integrated quality control and preprocessing of high-throughput sequencing data. Gigascience. 2018;7(1):1-6. doi:10.1093/gigascience/gix120 [PMID: [29220494][3]] 449 | 450 | 451 | 452 | [1]: http://en.wikipedia.org/wiki/GNU_General_Public_License 453 | [2]: https://github.com/BGI-flexlab/SOAPnuke 454 | [3]: http://www.ncbi.nlm.nih.gov/pubmed/29220494 455 | 456 | 457 | -------------------------------------------------------------------------------- /src/BloomFilter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-10-09. 3 | // 4 | 5 | #include "BloomFilter.h" 6 | #include 7 | 8 | BloomFilter::BloomFilter(long long sampleSize, int multiple):multiple(20) { 9 | if(sampleSize==0){ 10 | cerr<<"Error:no reads found in input file"<maxBfSize || realUseBitSize>maxBfSize){ 16 | cerr<<"Error:reads number maybe is too large to do remove duplication"<> 27)) ^ str[i]; 68 | } 69 | return hash; 70 | } 71 | case 2:{ 72 | unsigned long hash = 0; 73 | for(int i = 0; i < str.length(); i++) 74 | { 75 | hash = str[i] + (hash << 6) + (hash << 16) - hash; 76 | } 77 | return hash; 78 | } 79 | case 3:{ // BKDRHash 80 | unsigned long seed = 131; // 31 131 1313 13131 131313 etc.. 81 | unsigned long hash = 0; 82 | for(int i = 0; i < str.length(); i++) 83 | { 84 | hash = (hash * seed) + str[i]; 85 | } 86 | return hash; 87 | } 88 | case 4:{ 89 | unsigned long hash = 0; 90 | unsigned long x = 0; 91 | for(int i = 0; i < str.length(); i++) 92 | { 93 | hash = (hash << 4) + str[i]; 94 | if((x = hash & 0xF0000000L) != 0) 95 | { 96 | hash ^= (x >> 24); 97 | } 98 | hash &= ~x; 99 | } 100 | return hash; 101 | } 102 | case 5:{ 103 | unsigned long BitsInUnsignedInt = (unsigned long)(4 * 8); 104 | unsigned long ThreeQuarters = (unsigned long)((BitsInUnsignedInt * 3) / 4); 105 | unsigned long OneEighth = (unsigned long)(BitsInUnsignedInt / 8); 106 | unsigned long HighBits = (unsigned long)(0xFFFFFFFF) << (BitsInUnsignedInt - OneEighth); 107 | unsigned long hash = 0; 108 | unsigned long test = 0; 109 | for(int i = 0; i < str.length(); i++) 110 | { 111 | hash = (hash << OneEighth) + str[i]; 112 | if((test = hash & HighBits) != 0) 113 | { 114 | hash = (( hash ^ (test >> ThreeQuarters)) & (~HighBits)); 115 | } 116 | } 117 | return hash; 118 | } 119 | case 6:{ 120 | unsigned long hash = 1315423911; 121 | for(int i = 0; i < str.length(); i++) 122 | { 123 | hash ^= ((hash << 5) + str[i] + (hash >> 2)); 124 | } 125 | return hash; 126 | } 127 | case 7:{ //RSHash 128 | int b = 378551; 129 | int a = 63689; 130 | unsigned long hash = 0; 131 | for(int i = 0; i < str.length(); i++) 132 | { 133 | hash = hash * a + str[i]; 134 | a = a * b; 135 | } 136 | return hash; 137 | } 138 | default:{ 139 | cerr<<"Error:code error"<>smallIdx); 157 | } 158 | 159 | unsigned long BloomFilter::createHash2(string &str, int i) { 160 | string newStr=to_string(i)+str; 161 | return hash()(newStr); 162 | } 163 | -------------------------------------------------------------------------------- /src/BloomFilter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-10-09. 3 | // 4 | 5 | #ifndef SOAPNUKE_BLOOMFILTER_H 6 | #define SOAPNUKE_BLOOMFILTER_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | using namespace::std; 14 | #define maxBfSize 1024L*1024*1024*200 15 | class BloomFilter { 16 | private: 17 | int multiple; 18 | int hashNum; 19 | long realUseBitSize; 20 | long* indexs; 21 | char* arr; 22 | public: 23 | BloomFilter(long long sampleSize,int multiple); 24 | bool query(string& seq); 25 | void add(); 26 | bool getPosStatus(long idx); 27 | void setPosStatus(long idx); 28 | static unsigned long createHash(string& seq,int i); 29 | float expectedFP(); 30 | long realUseByteSize; 31 | ~BloomFilter(); 32 | 33 | unsigned long createHash2(string &str, int i); 34 | }; 35 | 36 | 37 | #endif //SOAPNUKE_BLOOMFILTER_H 38 | -------------------------------------------------------------------------------- /src/ReverseBloomFilter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-10-19. 3 | // 4 | 5 | #include "ReverseBloomFilter.h" 6 | 7 | ReverseBloomFilter::ReverseBloomFilter(long readsNum, float multiple) { 8 | arrSize=readsNum*multiple; 9 | arr=new long[arrSize]; 10 | } 11 | 12 | ReverseBloomFilter::ReverseBloomFilter(long readsNum, float multiple, long memSizeUsedInRmdup) { 13 | arrSize=readsNum*multiple; 14 | while (arrSize > maxRBfSize) { 15 | multiple -= 0.5; 16 | if (multiple < 1) { 17 | cerr << "Error:reads number maybe is too large to do remove duplication" << endl; 18 | exit(1); 19 | } 20 | } 21 | long actualMem=arrSize*8; 22 | long memG=actualMem/(1024*1024); 23 | if(actualMem>memSizeUsedInRmdup){ 24 | arrSize=memSizeUsedInRmdup/8; 25 | cerr<<"Error:given memSize is small, maybe it should be at least "<()(a); 39 | while(curHash=arrSize){ 56 | return -1; 57 | }else{ 58 | arr[idx]=curHash; 59 | return 0; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/ReverseBloomFilter.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-10-19. 3 | // 4 | 5 | #ifndef SOAPNUKE_REVERSEBLOOMFILTER_H 6 | #define SOAPNUKE_REVERSEBLOOMFILTER_H 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | using namespace ::std; 13 | #define maxRBfSize 1024L * 1024 * 1024 * 4 14 | #define minRBfSize 1024L * 1024 * 1000 15 | class ReverseBloomFilter 16 | { 17 | long idx; 18 | uint64_t curHash; 19 | long *arr; 20 | 21 | public: 22 | ReverseBloomFilter(long readsNum, float multiple); 23 | ReverseBloomFilter(long readsNum, float multiple, long memSizeUsedInRmdup); 24 | bool query(string &a); 25 | int add(); 26 | long arrSize; 27 | }; 28 | 29 | #endif // SOAPNUKE_REVERSEBLOOMFILTER_H 30 | -------------------------------------------------------------------------------- /src/Rscripts/Q20Q30.R: -------------------------------------------------------------------------------- 1 | args <- commandArgs(TRUE) 2 | if(length(args) != 3){ 3 | cat ("Usage:\n\tRscript Q20Q30.R \n") 4 | q(save="no") 5 | } 6 | rt1_1 <- read.table(pipe(paste("cut -f1-3 ",args[[1]])),skip=1) 7 | rt1_2 <- read.table(pipe(paste("cut -f4,5 ",args[[1]])),skip=1) 8 | rt2_1 <- read.table(pipe(paste("cut -f1-3 ",args[[2]])),skip=1) 9 | rt2_2 <- read.table(pipe(paste("cut -f4,5 ",args[[2]])),skip=1) 10 | pos <- c(rt1_1$V1,rt2_1$V1+max(rt1_1$V1)) 11 | rawq20 <- c(as.numeric(sub("%","",rt1_1$V2)),as.numeric(sub("%","",rt2_1$V2))) 12 | rawq30 <- c(as.numeric(sub("%","",rt1_1$V3)),as.numeric(sub("%","",rt2_1$V3))) 13 | cleanq20_1 <- as.numeric(sub("%","",rt1_2$V1)) 14 | cleanq20_2 <- as.numeric(sub("%","",rt2_2$V1)) 15 | cleanq30_1 <- as.numeric(sub("%","",rt1_2$V2)) 16 | cleanq30_2 <- as.numeric(sub("%","",rt2_2$V2)) 17 | png(file=args[[3]],height=360,width=576,antialias='default') 18 | plot(pos,rawq20,main="Q20 Q30 base percentage along reads",type="l",col="red",lwd=2, bty="o",xaxt="n",yaxt="n",xlab="",ylab="",xaxs="i",ylim=c(0,100)) 19 | lines(pos,rawq30,lty=1,col="green",lwd=2) 20 | pos1 <- seq(length(rt1_1$V1)-length(rt1_2$V1)+1,length(rt1_1$V1)) 21 | pos2 <- seq(length(rt2_1$V1)-length(rt2_2$V1)+1,length(rt2_1$V1))+max(rt1_1$V1) 22 | lines(pos1,cleanq20_1,lty=2,col="red",lwd=2) 23 | lines(pos2,cleanq20_2,lty=2,col="red",lwd=2) 24 | lines(pos1,cleanq30_1,lty=2,col="green",lwd=2) 25 | lines(pos2,cleanq30_2,lty=2,col="green",lwd=2) 26 | lines(c(max(rt1_1$V1),max(rt1_1$V1)),c(0,100),col="blue",lty=4,lwd=2) 27 | axis(side=1, seq(0,max(pos),20), tcl=0.2, labels=FALSE) 28 | axis(side=2, seq(0,100,20), tcl=0.2, labels=FALSE) 29 | axis(side=3, seq(0,max(pos),20), tcl=0.2, labels=FALSE) 30 | axis(side=4, seq(0,100,20), tcl=0.2, labels=FALSE) 31 | mtext(seq(0,max(pos),20),side=1,las=1,at=seq(0,max(pos),20),line=0.3,cex=1.5) 32 | mtext(seq(0,100,20),side=2,las=1,at=seq(0,100,20),line=0.3,cex=1.5) 33 | mtext("Position along reads",side=1, line=2, at=max(pos)/2, cex=1.5) 34 | mtext("Percent",side=2, line=2.5, at=50, cex=1.5) 35 | legend("bottomleft",lwd=2,lty=c(1,1,2,2),col=c("red","green","red","green"),bty="n",legend=c("raw Q20","raw Q30","clean Q20","clean Q30"),cex=1,inset=0.05) 36 | d <- dev.off() 37 | -------------------------------------------------------------------------------- /src/Rscripts/base.R: -------------------------------------------------------------------------------- 1 | args <- commandArgs(TRUE) 2 | if(length(args) != 4){ 3 | cat ("Usage:\n\tRscript base.R \n") 4 | q(save="no") 5 | } 6 | rt1_1 <- read.table(pipe(paste("cut -f2-6 ",args[[1]])),skip=1) 7 | rt1_2 <- read.table(pipe(paste("cut -f7-11 ",args[[1]])),skip=1) 8 | rt2_1 <- read.table(pipe(paste("cut -f2-6 ",args[[2]])),skip=1) 9 | rt2_2 <- read.table(pipe(paste("cut -f7-11 ",args[[2]])),skip=1) 10 | rawa <- c(as.numeric(sub("%","",rt1_1$V1)),as.numeric(sub("%","",rt2_1$V1))) 11 | rawc <- c(as.numeric(sub("%","",rt1_1$V2)),as.numeric(sub("%","",rt2_1$V2))) 12 | rawg <- c(as.numeric(sub("%","",rt1_1$V3)),as.numeric(sub("%","",rt2_1$V3))) 13 | rawt <- c(as.numeric(sub("%","",rt1_1$V4)),as.numeric(sub("%","",rt2_1$V4))) 14 | rawn <- c(as.numeric(sub("%","",rt1_1$V5)),as.numeric(sub("%","",rt2_1$V5))) 15 | cleana <- c(as.numeric(sub("%","",rt1_2$V1)),as.numeric(sub("%","",rt2_2$V1))) 16 | cleanc <- c(as.numeric(sub("%","",rt1_2$V2)),as.numeric(sub("%","",rt2_2$V2))) 17 | cleang <- c(as.numeric(sub("%","",rt1_2$V3)),as.numeric(sub("%","",rt2_2$V3))) 18 | cleant <- c(as.numeric(sub("%","",rt1_2$V4)),as.numeric(sub("%","",rt2_2$V4))) 19 | cleann <- c(as.numeric(sub("%","",rt1_2$V5)),as.numeric(sub("%","",rt2_2$V5))) 20 | pos1 <- seq(1,length(rawa)) 21 | pos2 <- seq(1,length(cleana)) 22 | png(file=args[[3]],height=360,width=576,antialias='default') 23 | plot(pos1,rawa,main="Base percentage composition along reads",type="l",col="red",lwd=2, bty="o",xaxt="n",yaxt="n",xlab="",ylab="",xaxs="i",ylim=c(0,50)) 24 | lines(pos1,rawc,lty=2,col="green",lwd=2) 25 | lines(pos1,rawg,lty=3,col="blue",lwd=2) 26 | lines(pos1,rawt,lty=6,col="magenta",lwd=2) 27 | lines(pos1,rawn,lty=4,col="cyan",lwd=2) 28 | lines(c(length(rt1_1$V1),length(rt1_1$V1)),c(0,50),col="blue",lty=4,lwd=2) 29 | axis(side=1, seq(0,max(pos1),20), tcl=0.2, labels=FALSE) 30 | axis(side=2, seq(0,50,10), tcl=0.2, labels=FALSE) 31 | axis(side=3, seq(0,max(pos1),20), tcl=0.2, labels=FALSE) 32 | axis(side=4, seq(0,50,10), tcl=0.2, labels=FALSE) 33 | mtext(seq(0,max(pos1),20),side=1,las=1,at=seq(0,max(pos1),20),line=0.3,cex=1.5) 34 | mtext(seq(0,50,10),side=2,las=1,at=seq(0,50,10),line=0.3,cex=1.5) 35 | mtext("Position along reads",side=1, line=2, at=max(pos1)/2, cex=1.5) 36 | mtext("Percent",side=2, line=2.5, at=25, cex=1.5) 37 | legend("topright",lwd=2,lty=c(1,2,3,6,4),col=c("red","green","blue","magenta","cyan"),bty="n",legend=c("A","C","G","T","N"),cex=1,inset=0.05) 38 | d <- dev.off() 39 | png(file=args[[4]],height=360,width=576,antialias='default') 40 | plot(pos2,cleana,main="Base percentage composition along reads",type="l",col="red",lwd=2, bty="o",xaxt="n",yaxt="n",xlab="",ylab="",xaxs="i",ylim=c(0, 50)) 41 | lines(pos2,cleanc,lty=2,col="green",lwd=2) 42 | lines(pos2,cleang,lty=3,col="blue",lwd=2) 43 | lines(pos2,cleant,lty=6,col="magenta",lwd=2) 44 | lines(pos2,cleann,lty=4,col="cyan",lwd=2) 45 | lines(c(length(rt1_2$V1),length(rt1_2$V1)),c(0,50),col="blue",lty=4,lwd=2) 46 | axis(side=1, seq(0,max(pos2),20), tcl=0.2, labels=FALSE) 47 | axis(side=2, seq(0,50,10), tcl=0.2, labels=FALSE) 48 | axis(side=3, seq(0,max(pos2),20), tcl=0.2, labels=FALSE) 49 | axis(side=4, seq(0,50,10), tcl=0.2, labels=FALSE) 50 | mtext(seq(0,max(pos2),20),side=1,las=1,at=seq(0,max(pos2),20),line=0.3,cex=1.5) 51 | mtext(seq(0,50,10),side=2,las=1,at=seq(0,50,10),line=0.3,cex=1.5) 52 | mtext("Position along reads",side=1, line=2, at=max(pos2)/2, cex=1.5) 53 | mtext("Percent",side=2, line=2.5, at=25, cex=1.5) 54 | legend("topright",lwd=2,lty=c(1,2,3,6,4),col=c("red","green","blue","magenta","cyan"),bty="n",legend=c("A","C","G","T","N"),cex=1,inset=0.05) 55 | d <- dev.off() 56 | -------------------------------------------------------------------------------- /src/Rscripts/quality.R: -------------------------------------------------------------------------------- 1 | args <- commandArgs(TRUE) 2 | if(length(args) != 6){ 3 | cat ("Usage:\n\tRscript quality.R \n") 4 | q(save="no") 5 | } 6 | line1 <- as.numeric(system(paste("wc -l ",args[[1]],"|awk '{print $1}'"),intern=T)) 7 | line1 <- (line1+as.numeric(args[[5]])-4)/2 8 | rawrt1 <- read.table(args[[1]],skip=2,nrows=line1) 9 | cleanrt1 <- read.table(args[[1]],skip=line1+4) 10 | line2 <- as.numeric(system(paste("wc -l ",args[[2]],"|awk '{print $1}'"),intern=T)) 11 | line2 <- (line2+as.numeric(args[[6]])-4)/2 12 | rawrt2 <- read.table(args[[2]],skip=2,nrows=line2) 13 | cleanrt2 <- read.table(args[[2]],skip=line2+4) 14 | rawrt1 <- rev(rawrt1) 15 | cleanrt1 <- rev(cleanrt1) 16 | rawrt2 <- rev(rawrt2) 17 | cleanrt2 <- rev(cleanrt2) 18 | pos <- c(rawrt1$V1,rawrt2$V1+max(rawrt1$V1)) 19 | rawmean <- c(rawrt1[[6]],rawrt2[[6]]) 20 | rawmedian <- c(rawrt1[[5]],rawrt2[[5]]) 21 | rawlower <- c(rawrt1[[4]],rawrt2[[4]]) 22 | rawupper <- c(rawrt1[[3]],rawrt2[[3]]) 23 | raw10th <- c(rawrt1[[2]],rawrt2[[2]]) 24 | raw90th <- c(rawrt1[[1]],rawrt2[[1]]) 25 | cleanmean <- c(cleanrt1[[6]],cleanrt2[[6]]) 26 | cleanmedian <- c(cleanrt1[[5]],cleanrt2[[5]]) 27 | cleanlower <- c(cleanrt1[[4]],cleanrt2[[4]]) 28 | cleanupper <- c(cleanrt1[[3]],cleanrt2[[3]]) 29 | clean10th <- c(cleanrt1[[2]],cleanrt2[[2]]) 30 | clean90th <- c(cleanrt1[[1]],cleanrt2[[1]]) 31 | rawstat <- matrix(c(raw10th,rawlower,rawmedian,rawupper,raw90th),line1+line2,5) 32 | rawstat <- t(rawstat) 33 | raw <- list(stats=rawstat,n=rep(Inf,line1+line2)) 34 | cleanstat <- matrix(c(clean10th,cleanlower,cleanmedian,cleanupper,clean90th),line1+line2-as.numeric(args[[5]])-as.numeric(args[[6]]),5) 35 | cleanstat <- t(cleanstat) 36 | clean <- list(stats=cleanstat,n=rep(Inf,line1+line2-as.numeric(args[[5]])-as.numeric(args[[6]]))) 37 | png(file=args[[3]],height=600,width=1500,antialias='default') 38 | # bxp(raw,main="Base quality along reads",xaxt="n",yaxt="n",xlab="",ylab="",ylim=c(0,42)) 39 | bxp(raw,main="Base quality along reads",xaxt="n",yaxt="n",xlab="",ylab="") 40 | lines(rawmean,col="red",lwd=2) 41 | abline(v=line1+.5,col="blue",lty=4,lwd=2) 42 | axis(side=1, seq(0,line1+line2,20), tcl=0.2, labels=FALSE) 43 | axis(side=2, seq(0,40,10), tcl=0.2, labels=FALSE) 44 | axis(side=3, seq(0,line1+line2,20), tcl=0.2, labels=FALSE) 45 | axis(side=4, seq(0,40,10), tcl=0.2, labels=FALSE) 46 | mtext(seq(0,line1+line2,20),side=1,las=1,at=seq(0,line1+line2,20),line=0.3,cex=1.5) 47 | mtext(seq(0,40,10),side=2,las=1,at=seq(0,40,10),line=0.3,cex=1.5) 48 | mtext("Position along reads",side=1, line=2, at=(line1+line2)/2, cex=1.5) 49 | mtext("Quality",side=2, line=2.5, at=21, cex=1.5) 50 | d <- dev.off() 51 | png(file=args[[4]],height=600,width=1500,antialias='default') 52 | # bxp(clean,main="Base quality along reads",xaxt="n",yaxt="n",xlab="",ylab="",ylim=c(0,42)) 53 | bxp(clean,main="Base quality along reads",xaxt="n",yaxt="n",xlab="",ylab="") 54 | lines(cleanmean,col="red",lwd=2) 55 | abline(v=line1-as.numeric(args[[5]])+.5,col="blue",lty=4,lwd=2) 56 | axis(side=1, seq(0,line1+line2-as.numeric(args[[5]])-as.numeric(args[[6]]),20), tcl=0.2, labels=FALSE) 57 | axis(side=2, seq(0,40,10), tcl=0.2, labels=FALSE) 58 | axis(side=3, seq(0,line1+line2-as.numeric(args[[5]])-as.numeric(args[[6]]),20), tcl=0.2, labels=FALSE) 59 | axis(side=4, seq(0,40,10), tcl=0.2, labels=FALSE) 60 | mtext(seq(0,line1+line2-as.numeric(args[[5]])-as.numeric(args[[6]]),20),side=1,las=1,at=seq(0,line1+line2-as.numeric(args[[5]])-as.numeric(args[[6]]),20),line=0.3,cex=1.5) 61 | mtext(seq(0,40,10),side=2,las=1,at=seq(0,40,10),line=0.3,cex=1.5) 62 | mtext("Position along reads",side=1, line=2, at=(line1+line2-as.numeric(args[[5]])-as.numeric(args[[6]]))/2, cex=1.5) 63 | mtext("Quality",side=2, line=2.5, at=21, cex=1.5) 64 | d <- dev.off() -------------------------------------------------------------------------------- /src/gc.cpp: -------------------------------------------------------------------------------- 1 | // #include 2 | // #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "zlib.h" 18 | #include "gc.h" 19 | // #include 20 | 21 | using namespace ::std; 22 | int MAXLEN = 1000; 23 | // char separator='\t'; 24 | quartile_result cal_quar_from_map(map data) 25 | { 26 | quartile_result return_value; 27 | float total_num(0); 28 | int data_num(0); 29 | for (map::iterator ix = data.begin(); ix != data.end(); ix++) 30 | { 31 | total_num += (ix->first) * (ix->second); 32 | data_num += ix->second; 33 | } 34 | return_value.mean = total_num / data_num; 35 | int lower_pos = data_num / 4; 36 | int upper_pos = data_num * 3 / 4; 37 | int first10_pos = data_num / 10; 38 | int last10_pos = data_num * 9 / 10; 39 | int median_pos = data_num / 2; 40 | int last_cur_pos(0), cur_pos(0); 41 | for (map::iterator ix = data.begin(); ix != data.end(); ix++) 42 | { 43 | cur_pos += ix->second; 44 | if (lower_pos >= last_cur_pos && lower_pos <= cur_pos) 45 | { 46 | return_value.lower_quar = ix->first; 47 | } 48 | if (upper_pos >= last_cur_pos && upper_pos <= cur_pos) 49 | { 50 | return_value.upper_quar = ix->first; 51 | } 52 | if (first10_pos >= last_cur_pos && first10_pos <= cur_pos) 53 | { 54 | return_value.first10_quar = ix->first; 55 | } 56 | if (last10_pos >= last_cur_pos && last10_pos <= cur_pos) 57 | { 58 | return_value.last10_quar = ix->first; 59 | } 60 | if (median_pos >= last_cur_pos && median_pos <= cur_pos) 61 | { 62 | return_value.median = ix->first; 63 | } 64 | last_cur_pos = cur_pos; 65 | } 66 | return return_value; 67 | } 68 | quartile_result cal_quar_from_array(uint64_t data[], int len) 69 | { 70 | // cout<= last_cur_pos && lower_pos <= cur_pos) 97 | { 98 | return_value.lower_quar = i; 99 | } 100 | if (upper_pos >= last_cur_pos && upper_pos <= cur_pos) 101 | { 102 | return_value.upper_quar = i; 103 | } 104 | if (first10_pos >= last_cur_pos && first10_pos <= cur_pos) 105 | { 106 | return_value.first10_quar = i; 107 | } 108 | if (last10_pos >= last_cur_pos && last10_pos <= cur_pos) 109 | { 110 | return_value.last10_quar = i; 111 | } 112 | if (median_pos >= last_cur_pos && median_pos <= cur_pos) 113 | { 114 | return_value.median = i; 115 | } 116 | last_cur_pos = cur_pos; 117 | } 118 | return return_value; 119 | } 120 | void check_gz_file(string a) 121 | { 122 | gzFile gzfp = gzopen((a).c_str(), "rb"); 123 | if (!gzfp) 124 | { 125 | cerr << "Error:cannot open file," << a << endl; 126 | exit(1); 127 | } 128 | char line_info[MAXLEN]; 129 | if (gzgets(gzfp, line_info, MAXLEN) == NULL) 130 | { 131 | cerr << "Error:empty file" << endl; 132 | exit(1); 133 | } 134 | gzclose(gzfp); 135 | } 136 | int check_gz_empty(string a) 137 | { 138 | gzFile gzfp = gzopen((a).c_str(), "rb"); 139 | if (!gzfp) 140 | { 141 | return -1; 142 | } 143 | char line_info[MAXLEN]; 144 | if (gzgets(gzfp, line_info, MAXLEN) != NULL) 145 | { 146 | return 1; 147 | } 148 | gzclose(gzfp); 149 | return -1; 150 | } 151 | void remove_space(string &a) 152 | { 153 | string b; 154 | for (string::size_type ix = 0; ix != a.size(); ix++) 155 | { 156 | if (!isspace(a[ix])) 157 | { 158 | b += a[ix]; 159 | } 160 | } 161 | a = b; 162 | } 163 | int file_exist_and_not_empty(string file_name) 164 | { 165 | int return_value = 1; 166 | ifstream if_input; 167 | if_input.open(file_name.c_str()); 168 | if (!if_input) 169 | { 170 | return_value = 0; 171 | return return_value; 172 | } 173 | if (if_input.peek() == EOF) 174 | { 175 | return_value = 0; 176 | return return_value; 177 | } 178 | return return_value; 179 | } 180 | void uniq_vector(vector &a) 181 | { 182 | sort(a.begin(), a.end()); 183 | vector::iterator end_iter = unique(a.begin(), a.end()); 184 | a.erase(end_iter, a.end()); 185 | } 186 | string get_local_time() 187 | { 188 | time_t a; 189 | time(&a); 190 | struct tm *b = localtime(&a); 191 | int cur_year = b->tm_year + 1900; 192 | int cur_mon = b->tm_mon + 1; 193 | int cur_day = b->tm_mday; 194 | ostringstream out_time; 195 | out_time << cur_year << "-" << cur_mon << "-" << cur_day << " " << b->tm_hour << ":" << b->tm_min << ":" << b->tm_sec << endl; 196 | string out = out_time.str(); 197 | out.erase(out.end() - 1); 198 | return out; 199 | } 200 | void line_split(string line_info, char sep, vector &elements) 201 | { 202 | elements.clear(); 203 | string element; 204 | for (string::size_type ix = 0; ix != line_info.size(); ix++) 205 | { 206 | if (line_info[ix] != sep) 207 | { 208 | element += line_info[ix]; 209 | } 210 | else 211 | { 212 | elements.emplace_back(element); 213 | element = ""; 214 | } 215 | } 216 | elements.emplace_back(element); 217 | } 218 | void line_split(string line_info, vector &elements) 219 | { 220 | elements.clear(); 221 | string element; 222 | for (string::size_type ix = 0; ix != line_info.size(); ix++) 223 | { 224 | if (!isspace(line_info[ix])) 225 | { 226 | element += line_info[ix]; 227 | } 228 | else 229 | { 230 | elements.emplace_back(element); 231 | element = ""; 232 | } 233 | } 234 | elements.emplace_back(element); 235 | } 236 | void line_split(string line_info, char sep, set &elements) 237 | { 238 | elements.clear(); 239 | string element; 240 | for (string::size_type ix = 0; ix != line_info.size(); ix++) 241 | { 242 | if (line_info[ix] != sep) 243 | { 244 | element += line_info[ix]; 245 | } 246 | else 247 | { 248 | elements.insert(element); 249 | element = ""; 250 | } 251 | } 252 | elements.insert(element); 253 | } 254 | int count_gc(string a) 255 | { 256 | string::size_type t_index = 0, t_index2; 257 | int gc_counts = 0; 258 | while ((t_index2 = a.find_first_of("GC", t_index)) != string::npos) 259 | { 260 | t_index = t_index2 + 1; 261 | gc_counts++; 262 | } 263 | return gc_counts; 264 | } 265 | void int2string(int &a, string &b) 266 | { 267 | stringstream ss; 268 | ss << a; 269 | b = ss.str(); 270 | } 271 | void float2string(float &a, string &b) 272 | { 273 | stringstream ss; 274 | ss << a; 275 | b = ss.str(); 276 | } 277 | void double2string(double &a, string &b) 278 | { 279 | stringstream ss; 280 | ss << a; 281 | b = ss.str(); 282 | } 283 | void string2double(string &a, double &b) 284 | { 285 | stringstream ss; 286 | ss << a; 287 | ss >> b; 288 | } 289 | void string2upper(string &a) 290 | { 291 | for (string::iterator ix = a.begin(); ix != a.end(); ix++) 292 | { 293 | *ix = toupper(*ix); 294 | } 295 | } 296 | string join_vector(vector a, char sep) 297 | { 298 | string result; 299 | for (vector::iterator ix = a.begin(); ix != a.end(); ix++) 300 | { 301 | if (ix != a.end() - 1) 302 | { 303 | result += *ix + sep; 304 | } 305 | else 306 | { 307 | result += *ix; 308 | } 309 | } 310 | return result; 311 | } 312 | string join_vector(vector a, char sep) 313 | { 314 | string result; 315 | string tmp; 316 | for (vector::iterator ix = a.begin(); ix != a.end(); ix++) 317 | { 318 | int2string(*ix, tmp); 319 | if (ix != a.end() - 1) 320 | { 321 | result += tmp + sep; 322 | } 323 | else 324 | { 325 | result += tmp; 326 | } 327 | } 328 | return result; 329 | } 330 | string join_vector(vector a, char sep) 331 | { 332 | string result; 333 | for (vector::iterator ix = a.begin(); ix != a.end(); ix++) 334 | { 335 | string tmp_a; 336 | double2string(*ix, tmp_a); 337 | if (ix != a.end() - 1) 338 | { 339 | result += tmp_a + sep; 340 | } 341 | else 342 | { 343 | result += tmp_a; 344 | } 345 | } 346 | return result; 347 | } 348 | string join_vector(set a, char sep) 349 | { 350 | string result; 351 | for (set::iterator ix = a.begin(); ix != a.end(); ix++) 352 | { 353 | result += *ix + sep; 354 | } 355 | result.erase(result.size() - 1, 1); 356 | return result; 357 | } 358 | string join_vector(vector a, string sep) 359 | { 360 | string result; 361 | for (vector::iterator ix = a.begin(); ix != a.end(); ix++) 362 | { 363 | if (ix != a.end() - 1) 364 | { 365 | result += *ix + sep; 366 | } 367 | else 368 | { 369 | result += *ix; 370 | } 371 | } 372 | return result; 373 | } 374 | string link_dir_file(string dir, string file) 375 | { 376 | // string::size_type index; 377 | // remove null char in the start or end; 378 | dir.erase(0, dir.find_first_not_of(" ")); 379 | dir.erase(dir.find_last_not_of(" ") + 1); 380 | /* while((index=dir.find(" ",index))!=string::npos){ //remove all null char 381 | dir.erase(index,1); 382 | } 383 | */ 384 | if (dir[dir.size() - 1] != '/') 385 | { 386 | dir = dir + "/"; 387 | } 388 | if (file.find("/") != string::npos) 389 | { 390 | string::size_type ix = file.find("/"); 391 | file.erase(0, ix + 1); 392 | } 393 | string out = dir + file; 394 | return out; 395 | } 396 | string get_absolute_path(string path) 397 | { 398 | char *_path = getenv("PATH"); 399 | string s_path(_path); 400 | vector path_eles; 401 | line_split(s_path, ':', path_eles); 402 | struct stat buf; 403 | for (vector::iterator ix = path_eles.begin(); ix != path_eles.end(); ix++) 404 | { 405 | string process_path = link_dir_file(*ix, path); 406 | if (lstat(process_path.c_str(), &buf) < 0) 407 | { 408 | continue; 409 | } 410 | if (S_ISREG(buf.st_mode) && S_IXUSR & (buf.st_mode)) 411 | { 412 | return process_path; 413 | } 414 | } 415 | cerr << "no such file: " << path << endl; 416 | exit(1); 417 | } 418 | int check_bam_ok(string bin_path, string bam_file) 419 | { 420 | ifstream if_pre_check(bam_file.c_str()); 421 | if (!if_pre_check) 422 | return 0; 423 | if_pre_check.close(); 424 | string check_cmd = bin_path + "/samtools quickcheck " + bam_file + " && echo 'all ok' || echo 'fail!'"; 425 | FILE *s_check = popen(check_cmd.c_str(), "r"); 426 | char line[100]; 427 | while (fgets(line, 100, s_check) != NULL) 428 | { 429 | string s_line(line); 430 | if (s_line.find("ok") != string::npos) 431 | { 432 | return 1; 433 | } 434 | if (s_line.find("fail") != string::npos) 435 | { 436 | return -1; 437 | } 438 | } 439 | cerr << "ERROR:bam check error" << endl; 440 | exit(1); 441 | } 442 | int check_bai_ok(string bin_path, string bam_file) 443 | { 444 | string check_cmd = bin_path + "/samtools tview -d T " + bam_file + " 2>&1"; 445 | FILE *s_check = popen(check_cmd.c_str(), "r"); 446 | char line[1000]; 447 | while (fgets(line, 1000, s_check) != NULL) 448 | { 449 | string s_line(line); 450 | if (s_line.find("Cannot read index for") != string::npos) 451 | { 452 | return 0; 453 | } 454 | } 455 | return 1; 456 | } 457 | string get_exe_path(string path) 458 | { 459 | if (path.find("/") != string::npos) 460 | { 461 | return path.substr(0, path.find_last_of("/") + 1); 462 | } 463 | else 464 | { 465 | string abs_path = get_absolute_path(path); 466 | return path.substr(0, abs_path.find_last_of("/") + 1); 467 | } 468 | } 469 | void chomp_space(string &a, string type) 470 | { 471 | if (type == "head") 472 | { 473 | int s_num = 0; 474 | for (string::size_type ix = 0; ix != a.size(); ix++) 475 | { 476 | if (!isspace(a[ix])) 477 | { 478 | break; 479 | } 480 | else 481 | { 482 | s_num++; 483 | } 484 | } 485 | a.erase(0, s_num); 486 | } 487 | else if (type == "tail") 488 | { 489 | string::size_type s_iter = 0; 490 | ; 491 | int s_num = 0; 492 | for (string::size_type ix = a.size() - 1; ix >= 0; ix++) 493 | { 494 | if (!isspace(a[ix])) 495 | { 496 | s_iter = ix; 497 | break; 498 | } 499 | else 500 | { 501 | s_num++; 502 | } 503 | } 504 | a.erase(s_iter, s_num); 505 | } 506 | else 507 | { 508 | int s_num = 0; 509 | for (string::size_type ix = 0; ix != a.size(); ix++) 510 | { 511 | if (!isspace(a[ix])) 512 | { 513 | break; 514 | } 515 | else 516 | { 517 | s_num++; 518 | } 519 | } 520 | a.erase(0, s_num); 521 | string::size_type s_iter = 0; 522 | ; 523 | int s_num2 = 0; 524 | for (string::size_type ix = a.size() - 1; ix >= 0; ix++) 525 | { 526 | if (!isspace(a[ix])) 527 | { 528 | s_iter = ix; 529 | break; 530 | } 531 | else 532 | { 533 | s_num++; 534 | } 535 | } 536 | a.erase(s_iter, s_num2); 537 | } 538 | } 539 | vector get_pe_hard_trim(string a) 540 | { 541 | vector tmp_eles; 542 | line_split(a, ',', tmp_eles); 543 | if (tmp_eles.size() != 4) 544 | { 545 | cerr << "Error:trim value format error" << endl; 546 | exit(1); 547 | } 548 | return tmp_eles; 549 | } 550 | vector get_se_hard_trim(string a) 551 | { 552 | vector tmp_eles; 553 | line_split(a, ',', tmp_eles); 554 | if (tmp_eles.size() != 2) 555 | { 556 | cerr << "Error:trim value format error" << endl; 557 | exit(1); 558 | } 559 | return tmp_eles; 560 | } 561 | 562 | void mkDir(string dir) 563 | { 564 | struct stat s; 565 | if (stat(dir.c_str(), &s) == 0) 566 | { 567 | if (S_ISDIR(s.st_mode)) 568 | { 569 | return; 570 | } 571 | } 572 | if (mkdir(dir.c_str(), 0755) != 0) 573 | { 574 | cerr << "Error:mkdir fail," << dir << endl; 575 | cerr << strerror(errno) << endl; 576 | exit(errno); 577 | } 578 | } 579 | 580 | void mkDir(string dir, mode_t mode) 581 | { 582 | struct stat s; 583 | if (stat(dir.c_str(), &s) == 0) 584 | { 585 | if (S_ISDIR(s.st_mode)) 586 | { 587 | return; 588 | } 589 | } 590 | if (mkdir(dir.c_str(), mode) != 0) 591 | { 592 | cerr << "Error:mkdir fail," << dir << endl; 593 | cerr << strerror(errno) << endl; 594 | exit(errno); 595 | } 596 | } 597 | 598 | long long guessReadsNum(string fq1) 599 | { 600 | struct stat s; 601 | long long fileSize = 0; 602 | float conserveFlow = 1.2; 603 | if (stat(fq1.c_str(), &s) == 0) 604 | { 605 | fileSize = s.st_size; 606 | } 607 | gzFile inFq1 = gzopen(fq1.c_str(), "r"); 608 | int bufSize = 1024 * 1024 * 10; 609 | if (bufSize > fileSize) 610 | { 611 | bufSize = fileSize / 2; 612 | } 613 | char *buf = new char[bufSize]; 614 | int readSize = 0; 615 | int lfNum = 0; 616 | int cSize = 0; 617 | if ((readSize = gzread(inFq1, buf, bufSize)) > 0) 618 | { 619 | for (int i = 0; i < readSize; i++) 620 | { 621 | if (buf[i] == '\n') 622 | { 623 | lfNum++; 624 | } 625 | } 626 | string tmpFq = fq1 + ".tmp"; 627 | gzFile outTmpFq = gzopen(tmpFq.c_str(), "wb"); 628 | gzwrite(outTmpFq, buf, readSize); 629 | gzclose(outTmpFq); 630 | struct stat s; 631 | if (stat(tmpFq.c_str(), &s) == 0) 632 | { 633 | cSize = s.st_size; 634 | } 635 | if (remove(tmpFq.c_str()) != 0) 636 | { 637 | cerr << "Error:cannot remove file," << tmpFq << endl; 638 | exit(1); 639 | } 640 | } 641 | if (lfNum == 0) 642 | { 643 | cerr << "Error:no reads found in input file," << fq1 << endl; 644 | exit(1); 645 | } 646 | long long readsNum = round(lfNum / 4); 647 | if (cSize == 0) 648 | { 649 | cerr << "Error:empty file," << fq1 << endl; 650 | exit(1); 651 | } 652 | long long guessedReadsNum = (readsNum * fileSize / cSize) * conserveFlow; 653 | gzclose(inFq1); 654 | 655 | delete[] buf; 656 | return guessedReadsNum; 657 | } 658 | -------------------------------------------------------------------------------- /src/gc.h: -------------------------------------------------------------------------------- 1 | #ifndef GC_H 2 | #define GC_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | using namespace ::std; 13 | class quartile_result 14 | { 15 | public: 16 | float mean; 17 | float median; 18 | float lower_quar, upper_quar; 19 | float first10_quar, last10_quar; 20 | }; 21 | 22 | // quartile_result cal_quar_from_map(map data); 23 | quartile_result cal_quar_from_array(uint64_t data[], int len); 24 | vector get_pe_hard_trim(string a); 25 | vector get_se_hard_trim(string a); 26 | void check_gz_file(string a); 27 | int check_gz_empty(string a); 28 | // void remove_space(string &a); 29 | int file_exist_and_not_empty(string file_name); 30 | // void uniq_vector(vector &a); 31 | string get_local_time(); 32 | void line_split(string line_info, char sep, vector &elements); 33 | void line_split(string line_info, char sep, set &elements); 34 | void line_split(string line_info, vector &elements); 35 | // int count_gc(string a); 36 | void int2string(int &a, string &b); 37 | void double2string(double &a, string &b); 38 | void float2string(float &a, string &b); 39 | void string2double(string &a, double &b); 40 | 41 | void string2upper(string &a); 42 | string join_vector(vector a, char sep); 43 | string join_vector(vector a, char sep); 44 | string join_vector(set a, char sep); 45 | string join_vector(vector a, char sep); 46 | string join_vector(vector a, string seq); 47 | string get_absolute_path(string path); 48 | int check_bam_ok(string bin_path, string bam_file); 49 | int check_bai_ok(string bin_path, string bam_file); 50 | string get_exe_path(string path); 51 | string link_dir_file(string dir, string file); 52 | void chomp_space(string &a, string type); 53 | void mkDir(string dir); 54 | void mkDir(string dir, mode_t mode); 55 | long long guessReadsNum(string fq1); 56 | long long guessReadsNum(string fq1, string fq2); 57 | #endif 58 | -------------------------------------------------------------------------------- /src/global_parameter.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLOBAL_PARAMETER_H 2 | #define _GLOBAL_PARAMETER_H 3 | #include 4 | #include 5 | #include 6 | // #include "mGzip.h" 7 | using namespace ::std; 8 | class C_global_parameter 9 | { 10 | // common parameter 11 | public: 12 | /* 13 | PROCESS_THREAD_NUM(2), IS_STREAMING(false), filterTile_(false), tileIsFov_(false), misMatch_(1), matchRatio_(0.5), lowQual_(5), 14 | qualRate_(0.5), nRate_(0.05), highA_(0), polyX_(0), minMean_(0.0), filterIndex_(false), 15 | rmdup_(false), dupRateOnly_(false), cutReadNum_(0), headTrim_(0), tailTrim_(0), headTrim2_(0), tailTrim2_(0), 16 | memLimit_(700 * MEM_UNIT), qualSys_(ILLUMINA_), isFilterSmallInsertSize_(false), overlap_(10), 17 | mis_(0.1), readLen_(0), readLen2_(0), outDir_("."), onlyStat_(false), isPE_(true),minReadLength(50),cutAdaptor(false),cutBasesNumber(0), 18 | isAdptList_(true), isFull_(false), size_(0), cleanQualSys_(ILLUMINA_), filterAdapter_(true),seqType_(0),outType_(0),highAType_(0) 19 | */ 20 | C_global_parameter() 21 | { 22 | mode = ""; 23 | is_streaming = false; 24 | seq_type = "0"; 25 | adapter_discard_or_trim = "discard"; 26 | index_remove = false; 27 | qualityPhred = 33; 28 | outputQualityPhred = 33; 29 | contam_discard_or_trim = "discard"; 30 | adapter_method = "hd"; 31 | whether_add_pe_info = false; 32 | output_file_type = "fastq"; 33 | lowQual = 5; 34 | lowQualityBaseRatio = 0.5; 35 | meanQuality = -1; 36 | n_ratio = 0.05; 37 | highA_ratio = -1; 38 | polyG_tail = -1; 39 | polyX_num = -1; 40 | overlap_length = -1; 41 | peMismatchRatio = 0.1; 42 | max_read_length = -1; 43 | min_read_length = 30; 44 | cleanOutSplit = 0; 45 | have_output1 = 0; 46 | have_output2 = 0; 47 | adaMis = 2; 48 | adaMR = 0.5; 49 | adaMis2 = 2; 50 | adaMR2 = 0.5; 51 | ctMatchR = "0.2"; 52 | adaEdge = 6; 53 | adaEdge2 = 6; 54 | adaRCtg = 6; 55 | adaRAr = 0.8; 56 | adaRMa = 5; 57 | adaREr = 0.4; 58 | adaRMm = 4; 59 | threads_num = 6; 60 | patchSize = 0; 61 | split_line = 10000000; 62 | total_reads_num = 0; 63 | f_total_reads_ratio = 0; 64 | l_total_reads_num = 0; 65 | total_reads_num_random = true; 66 | clean_file_reads = 0; 67 | catWhenrunning = true; 68 | inputGzformat = true; 69 | cleanOutGzFormat = true; 70 | trimOutGzformat = true; 71 | barcodeListPath = ""; 72 | barcodeRegionStr = "101_10,117_10,133_10"; 73 | notCutNoLFR = false; 74 | inputAsList = false; 75 | tenX = false; 76 | barcodeNumInList = 0; 77 | // whether_mGzip=false; 78 | rmdup = false; 79 | approximateReadsNum = 1; 80 | // max mem limit:4G ,user should set a larger value if want use more memory 81 | memSizeUsedInRmdup = 1024L * 1024 * 1024 * 4; 82 | expectedFalsePositive = 0; 83 | }; 84 | // C_global_parameter(int argc,char* argv[]); 85 | 86 | string mode; 87 | string module_name; 88 | // input and output file 89 | string fq1_path, fq2_path; 90 | string trim_fq1, trim_fq2, clean_fq1, clean_fq2; 91 | string output_dir; 92 | string log; 93 | 94 | bool is_streaming; 95 | // input and output file type 96 | string seq_type; // Sequence fq name type, 0->old fastq name, 1->new fastq name [0]\n"; 97 | // old fastq name: @FCD1PB1ACXX:4:1101:1799:2201#GAAGCACG/2\n"; 98 | // new fastq name: @HISEQ:310:C5MH9ANXX:1:1101:3517:2043 2:N:0:TCGGTCAC\n"; 99 | string output_file_type; // fasta or fastq 100 | // adapter 101 | string adapter_discard_or_trim; 102 | string adapter_method; 103 | vector ada1s; 104 | vector ada2s; 105 | string adapter1_seq, adapter2_seq; 106 | string contam_discard_or_trim; 107 | string contam1_seq, contam2_seq; 108 | string ctMatchR; 109 | string global_contams, g_mrs, g_mms; 110 | // tile to removed 111 | string tile; 112 | string fov; 113 | // index remove 114 | bool index_remove; 115 | // base quality 116 | int qualityPhred, outputQualityPhred; 117 | int lowQual; 118 | float lowQualityBaseRatio; 119 | int meanQuality; 120 | string trimBadHead, trimBadTail; 121 | int maxBaseQuality = 42; 122 | // base content 123 | float n_ratio, highA_ratio, polyG_tail; 124 | int polyX_num; 125 | string trim; // pe trim and se trim 126 | string base_convert; 127 | // PE reads 128 | // string whether_remove_overlap_peReads,overlap_length,peMismatchRatio; 129 | int overlap_length; 130 | float peMismatchRatio; 131 | bool whether_add_pe_info; 132 | // computer resource 133 | int threads_num; 134 | int patchSize; 135 | int split_line; 136 | // whether only stat 137 | // string whether_only_stat; 138 | // read length limit 139 | int max_read_length, min_read_length; 140 | // reads number limit 141 | float total_reads_num; 142 | float f_total_reads_ratio; 143 | unsigned long long l_total_reads_num; 144 | bool total_reads_num_random; 145 | // output reads number,the only variable 146 | // int output_reads_num; 147 | unsigned long long cleanOutSplit; 148 | unsigned long long have_output1, have_output2; 149 | unsigned long long clean_file_reads; 150 | // special parameter 151 | // filtersRNA module 152 | // adapter find method2 parameter 153 | int adaRCtg; 154 | float adaRAr; 155 | int adaRMa; 156 | float adaREr; 157 | int adaRMm; 158 | // filter module 159 | // adapter find method1 parameter 160 | int adaMis; 161 | float adaMR; 162 | int adaEdge; 163 | int adaMis2; 164 | float adaMR2; 165 | int adaEdge2; 166 | 167 | bool catWhenrunning; 168 | bool cleanOutGzFormat, trimOutGzformat; 169 | bool inputGzformat; 170 | // filterMeta module 171 | // adapter find method is same as filter module 172 | 173 | // cram reference 174 | string reference; 175 | // stLFR 176 | string barcodeListPath; 177 | string barcodeRegionStr; 178 | bool notCutNoLFR; 179 | bool inputAsList; 180 | bool tenX; 181 | int barcodeNumInList; 182 | 183 | // bool whether_mGzip; 184 | // static vector threadInfo; 185 | 186 | bool rmdup; 187 | long long approximateReadsNum; 188 | long memSizeUsedInRmdup; 189 | float expectedFalsePositive; 190 | }; 191 | 192 | #endif 193 | -------------------------------------------------------------------------------- /src/global_variable.cpp: -------------------------------------------------------------------------------- 1 | #include "global_variable.h" 2 | 3 | C_general_stat::C_general_stat() 4 | { 5 | read_max_length = 0; 6 | read_length = 0; 7 | reads_number = 0; 8 | base_number = 0; 9 | a_number = 0; 10 | c_number = 0; 11 | g_number = 0; 12 | t_number = 0; 13 | n_number = 0; 14 | // a_ratio,c_ratio,g_ratio,t_ratio,n_ratio=0; 15 | q20_num = 0; 16 | q30_num = 0; 17 | } 18 | C_reads_pos_base_stat::C_reads_pos_base_stat() 19 | { 20 | for (int i = 0; i != READ_MAX_LEN; i++) 21 | { 22 | for (int j = 0; j != 5; j++) 23 | { 24 | position_acgt_content[i][j] = 0; 25 | } 26 | } 27 | } 28 | C_reads_pos_qual_stat::C_reads_pos_qual_stat() 29 | { 30 | for (int i = 0; i != READ_MAX_LEN; i++) 31 | { 32 | position_qual[i] = new uint64_t[MAX_QUAL]; 33 | for (int j = 0; j != MAX_QUAL; j++) 34 | { 35 | position_qual[i][j] = 0; 36 | } 37 | } 38 | } 39 | C_reads_pos_qual_stat::C_reads_pos_qual_stat(C_global_parameter &gp) 40 | { 41 | for (int i = 0; i != READ_MAX_LEN; i++) 42 | { 43 | position_qual[i] = new uint64_t[gp.maxBaseQuality]; 44 | for (int j = 0; j != gp.maxBaseQuality; j++) 45 | { 46 | position_qual[i][j] = 0; 47 | } 48 | } 49 | } 50 | 51 | C_reads_trim_stat::C_reads_trim_stat() 52 | { 53 | for (int i = 0; i != READ_MAX_LEN; i++) 54 | { 55 | hlq[i] = 0; 56 | ht[i] = 0; 57 | ta[i] = 0; 58 | tlq[i] = 0; 59 | tt[i] = 0; 60 | } 61 | } 62 | C_fastq_file_stat::C_fastq_file_stat() 63 | { 64 | gs = C_general_stat(); 65 | // bs=C_reads_pos_base_stat(); 66 | // qs=C_reads_pos_qual_stat(); 67 | // ts=C_reads_trim_stat(); 68 | } 69 | C_fastq_file_stat::C_fastq_file_stat(C_global_parameter &gp) 70 | { 71 | gs = C_general_stat(); 72 | bs = C_reads_pos_base_stat(); 73 | qs = C_reads_pos_qual_stat(gp); 74 | ts = C_reads_trim_stat(); 75 | } 76 | void C_fastq_file_stat::clear() 77 | { 78 | gs = C_general_stat(); 79 | bs = C_reads_pos_base_stat(); 80 | qs = C_reads_pos_qual_stat(); 81 | ts = C_reads_trim_stat(); 82 | } 83 | C_global_variable::C_global_variable() 84 | { 85 | fs = C_filter_stat(); 86 | raw1_stat = C_fastq_file_stat(); 87 | raw2_stat = C_fastq_file_stat(); 88 | trim1_stat = C_fastq_file_stat(); 89 | trim2_stat = C_fastq_file_stat(); 90 | clean1_stat = C_fastq_file_stat(); 91 | clean2_stat = C_fastq_file_stat(); 92 | } 93 | C_global_variable::C_global_variable(C_global_parameter &gp) 94 | { 95 | fs = C_filter_stat(); 96 | raw1_stat = C_fastq_file_stat(gp); 97 | raw2_stat = C_fastq_file_stat(gp); 98 | trim1_stat = C_fastq_file_stat(gp); 99 | trim2_stat = C_fastq_file_stat(gp); 100 | clean1_stat = C_fastq_file_stat(gp); 101 | clean2_stat = C_fastq_file_stat(gp); 102 | } -------------------------------------------------------------------------------- /src/global_variable.h: -------------------------------------------------------------------------------- 1 | #ifndef _GLOBAL_VARIABLE_H 2 | #define _GLOBAL_VARIABLE_H 3 | 4 | #include 5 | #include 6 | #include "global_parameter.h" 7 | // #include 8 | using namespace ::std; 9 | #define READ_MAX_LEN 1000 10 | #define MAX_QUAL 42 11 | #define MIN_QUAL 0 12 | // #define REAL_MAX 50 13 | class C_filter_stat 14 | { 15 | public: 16 | C_filter_stat() 17 | { 18 | in_adapter_list_num = 0; 19 | include_adapter_seq_num = 0; 20 | include_contam_seq_num = 0; 21 | n_ratio_num = 0; 22 | highA_num = 0; 23 | polyX_num = 0; 24 | tile_num = 0; 25 | fov_num = 0; 26 | low_qual_base_ratio_num = 0; 27 | mean_quality_num = 0; 28 | short_len_num = 0; 29 | long_len_num = 0; 30 | over_lapped_num = 0; 31 | no_3_adapter_num = 0; 32 | include_adapter_seq_num1 = 0; 33 | include_adapter_seq_num2 = 0; 34 | int_insertNull_num = 0; 35 | include_adapter_seq_num_overlap = 0; 36 | include_contam_seq_num1 = 0; 37 | include_contam_seq_num2 = 0; 38 | include_contam_seq_num_overlap = 0; 39 | n_ratio_num1 = 0; 40 | n_ratio_num2 = 0; 41 | n_ratio_num_overlap = 0; 42 | highA_num1 = 0; 43 | highA_num2 = 0; 44 | highA_num_overlap = 0; 45 | polyX_num1 = 0; 46 | polyX_num2 = 0; 47 | polyX_num_overlap = 0; 48 | low_qual_base_ratio_num1 = 0; 49 | low_qual_base_ratio_num2 = 0; 50 | low_qual_base_ratio_num_overlap = 0; 51 | mean_quality_num1 = 0; 52 | mean_quality_num2 = 0; 53 | mean_quality_num_overlap = 0; 54 | short_len_num1 = 0; 55 | short_len_num2 = 0; 56 | short_len_num_overlap = 0; 57 | long_len_num1 = 0; 58 | long_len_num2 = 0; 59 | long_len_num_overlap = 0; 60 | include_global_contam_seq_num = include_global_contam_seq_num1 = include_global_contam_seq_num2 = include_global_contam_seq_num_overlap = 0; 61 | polyG_num = polyG_num1 = polyG_num2 = polyG_num_overlap = 0; 62 | readsNumWithstLFRbarcode = 0; 63 | dupReadsNum = 0; 64 | }; 65 | // uint64_t output_reads_num; 66 | uint64_t in_adapter_list_num; 67 | uint64_t include_adapter_seq_num, include_adapter_seq_num1, include_adapter_seq_num2, include_adapter_seq_num_overlap; 68 | uint64_t include_contam_seq_num, include_contam_seq_num1, include_contam_seq_num2, include_contam_seq_num_overlap; 69 | uint64_t include_global_contam_seq_num, include_global_contam_seq_num1, include_global_contam_seq_num2, include_global_contam_seq_num_overlap; 70 | uint64_t n_ratio_num, n_ratio_num1, n_ratio_num2, n_ratio_num_overlap; 71 | uint64_t highA_num, polyX_num; 72 | uint64_t highA_num1, highA_num2, highA_num_overlap; 73 | uint64_t polyX_num1, polyX_num2, polyX_num_overlap; 74 | uint64_t polyG_num; 75 | uint64_t polyG_num1, polyG_num2, polyG_num_overlap; 76 | uint64_t tile_num, fov_num; 77 | uint64_t low_qual_base_ratio_num, low_qual_base_ratio_num1, low_qual_base_ratio_num2, low_qual_base_ratio_num_overlap; 78 | uint64_t mean_quality_num, mean_quality_num1, mean_quality_num2, mean_quality_num_overlap; 79 | uint64_t short_len_num, long_len_num; 80 | uint64_t short_len_num1, short_len_num2, short_len_num_overlap; 81 | uint64_t long_len_num1, long_len_num2, long_len_num_overlap; 82 | uint64_t over_lapped_num; 83 | uint64_t no_3_adapter_num, int_insertNull_num; 84 | uint64_t readsNumWithstLFRbarcode; 85 | set stLFRbarcodeNum; 86 | uint64_t dupReadsNum; 87 | }; 88 | class C_general_stat 89 | { 90 | public: 91 | C_general_stat(); 92 | uint64_t read_max_length; 93 | uint64_t read_length; 94 | uint64_t reads_number; 95 | uint64_t base_number; 96 | uint64_t a_number, c_number, g_number, t_number, n_number; 97 | // unsigned uint64_t a_ratio,c_ratio,g_ratio,t_ratio,n_ratio; 98 | uint64_t q20_num, q30_num; 99 | // unsigned uint64_t q20_ratio,q30_ratio; 100 | }; 101 | 102 | class C_reads_pos_base_stat 103 | { 104 | public: 105 | C_reads_pos_base_stat(); 106 | uint64_t position_acgt_content[READ_MAX_LEN][5]; 107 | // map > position_acgt_content_ratio; 108 | }; 109 | 110 | class C_reads_pos_qual_stat 111 | { 112 | public: 113 | C_reads_pos_qual_stat(); 114 | C_reads_pos_qual_stat(C_global_parameter &gp); 115 | uint64_t *position_qual[READ_MAX_LEN]; 116 | // map > position_qual_ratio; 117 | }; 118 | class C_reads_trim_stat 119 | { 120 | public: 121 | C_reads_trim_stat(); 122 | uint64_t hlq[READ_MAX_LEN], ht[READ_MAX_LEN]; 123 | uint64_t ta[READ_MAX_LEN], tlq[READ_MAX_LEN], tt[READ_MAX_LEN]; 124 | }; 125 | class C_fastq_file_stat 126 | { 127 | public: 128 | C_fastq_file_stat(); 129 | C_fastq_file_stat(C_global_parameter &gp); 130 | C_general_stat gs; 131 | C_reads_pos_base_stat bs; 132 | C_reads_pos_qual_stat qs; 133 | C_reads_trim_stat ts; 134 | void clear(); 135 | }; 136 | class C_global_variable 137 | { 138 | public: 139 | C_global_variable(); 140 | C_global_variable(C_global_parameter &gp); 141 | C_filter_stat fs; 142 | C_fastq_file_stat raw1_stat, raw2_stat, trim1_stat, trim2_stat, clean1_stat, clean2_stat; 143 | }; 144 | #endif 145 | -------------------------------------------------------------------------------- /src/mGzip.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-08-11. 3 | // 4 | #ifdef _USEMGZIP 5 | #include "mGzip.h" 6 | using namespace::std; 7 | bool mGzip::check_mGzip(string filePath) { 8 | bool whether_mGzip=false; 9 | // gzFile in=gzopen(filePath.c_str(),"rb"); 10 | FILE* in=fopen(filePath.c_str(),"rb"); 11 | if(in==NULL){ 12 | cerr<<"Error:fail to open file:"< mGzip::allocate(int threadsNum, vector filesPath) { 42 | vector threadNeededInfo; 43 | for(int fileIndex=0;fileIndex blockStarts; 55 | vector spanLength; 56 | // vector compressSize; 57 | vector rawSize; 58 | vector crc32; 59 | string filename; 60 | int method,flag; 61 | while(getOneBlock(in,method,flag,curOffSet,blockStarts,spanLength,rawSize,crc32,filename)>0){ 62 | totalBlocks++; 63 | } 64 | //allocate blocks to thread 65 | int* blocksNumToThreads=new int[threadsNum]; 66 | for(int i=0;i curFileCrc32; 78 | vector curFileRawBlockSize; 79 | vector curFileSeekOffSetStart; 80 | vector curFileSpanLength; 81 | for(int j=0;j=totalBlocks){ 94 | break; 95 | } 96 | } 97 | curThreadInfo.crc32.push_back(curFileCrc32); 98 | curThreadInfo.rawBlockSize.push_back(curFileRawBlockSize); 99 | curThreadInfo.seekOffSetStart.push_back(curFileSeekOffSetStart); 100 | curThreadInfo.spanLength.push_back(curFileSpanLength); 101 | threadNeededInfo.push_back(curThreadInfo); 102 | } 103 | } 104 | return threadNeededInfo; 105 | } 106 | 107 | int mGzip::getOneBlock(FILE *pFile, int& method, int& flag, long &curOffSet, vector &blockStarts, vector &spanLength, vector &rawSize, 108 | vector &crc32, string &fileName) { 109 | // uLongf testSize=441+30+4; 110 | // unsigned char* readBuf=new unsigned char[testSize]; 111 | // fread(readBuf,1,testSize,pFile); 112 | // uLongf decomLen=1000000; 113 | // Bytef* decom=new Bytef[decomLen]; 114 | // uncompress(decom,&decomLen,readBuf,testSize); 115 | int firstReadSize=14; 116 | char* buf=new char[firstReadSize]; 117 | if(fread(buf,1,firstReadSize,pFile)==firstReadSize){ 118 | if(!(buf[12]=='I' && buf[13]=='G')){ 119 | cerr<<"Error:input is not with mGzip format"<2;i--){ 135 | blockSize+=Byte(buf[i-1])<<(8*(i-3)); 136 | } 137 | delete[] buf; 138 | buf=new char[1]; 139 | //get raw file name 140 | int nextLen=0; 141 | curOffSet+=secReadSize; 142 | bool getFileName=fileName==""?true:false; 143 | while(fread(buf,1,1,pFile)==1){ 144 | nextLen++; 145 | if(Byte(buf[0])==0x00){ 146 | break; 147 | }else{ 148 | if(getFileName) 149 | fileName += char(buf[0]); 150 | } 151 | } 152 | curOffSet+=nextLen; 153 | delete[] buf; 154 | long compressBlockSize=blockSize-firstReadSize-secReadSize-nextLen-8; 155 | blockStarts.push_back(curOffSet); 156 | spanLength.push_back(compressBlockSize); 157 | // 158 | const char* hello="@CL100012597L1C001R002_0/1\n" 159 | "TGAGAACCCAGGGGTGAGCATTGATTCTTTGTTCCCCAACAACCTTCTTC\n" 160 | "+\n" 161 | "FEFBFGFFFGGFFFEFAFFFFEFAFAFF:FFBDDGFFFEFEEDEF2FF-F\n" 162 | "@CL100012597L1C001R002_1/1\n" 163 | "TATGAAACCATATGGGAAGGGAGGAAGCAGGTAGAGTATAGATTAACCAA\n" 164 | "+\n" 165 | "FGFFFFFFFGGFFFEFFFCFDAE:DBFEFFFDFF=GB9'FF1E7D(*F-,\n" 166 | "@CL100012597L1C001R002_4/1\n" 167 | "GACATTTACTGTGGATCCAGCACTATTCCAAGTGCTCTTTAGGCCCCGAG\n" 168 | "+\n" 169 | "GBFGFFFFBFEFGFDFFFBFFFF/59B'104*2&\n" 170 | "@CL100012597L1C001R002_6/1\n" 171 | "GGCCGCAGCTGGGACTTCACTGCTGAGTGGAGGGAGGGCAGCGGGCCACG\n" 172 | "+\n" 173 | "?FFFFFFFFFF:FEFFFF;AEABFECE;E=2B86,E2DA:C7+'F1F'F;\n" 174 | "@CL100012597L1C001R002_7/1\n" 175 | "TGAATCACTAAGACAACTCCAATTCTGTTACTAGAAGGAATTAGTTTGGG\n" 176 | "+\n" 177 | "FGFFFFFFFGFGFDGFGFGEF0EFF;GFEGEF+FFD4/9EE.39FEF-F&\n" 178 | "@CL100012597L1C001R002_8/1\n" 179 | "CTTCCTGTTTTGTAGATCTTGGTCTTCTCATTGTATTCTCACATAGCAGG\n" 180 | "+\n" 181 | "FDFF;FFFFFFFFFFEFFEFF>>FF7FE?@F4FC,E,9>@A=>D1EF>DB\n" 182 | "@CL100012597L1C001R002_9/1\n" 183 | "GGTGCCCTTATAAGAAGCAGCAGCAACACAAAACATCTCTCTCCTTCATG\n" 184 | "+\n" 185 | "FFFFFFEFFFFFFFFFFFEFFFFEFFFE@EFBEA@FFF=0;i--){ 213 | crc+=Byte(buf[i])<<(blockTailLen*i); 214 | } 215 | crc32.push_back(crc); 216 | int rawLength=0; 217 | for(int i=7;i>=4;i--){ 218 | rawLength+=Byte(buf[i])<<((i-4)*blockTailLen); 219 | } 220 | rawSize.push_back(rawLength); 221 | }else{ 222 | delete[] buf; 223 | return -1; 224 | } 225 | delete[] buf; 226 | curOffSet+=blockTailLen; 227 | }else{ 228 | return -1; 229 | } 230 | return 1; 231 | } 232 | #endif -------------------------------------------------------------------------------- /src/mGzip.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-08-11. 3 | // 4 | #ifdef _USEMGZIP 5 | #ifndef SOAPNUKE_MGZIP_H 6 | #define SOAPNUKE_MGZIP_H 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace::std; 12 | //only support SE data. 13 | class threadDataInfo{ 14 | public: 15 | //implicit construct function 16 | threadDataInfo(){ 17 | index=-1; 18 | } 19 | int index; 20 | //If input is a single file, the size would all be 1 21 | vector fileList; 22 | //store the compress and raw size of each block, one thread may process several blocks 23 | vector rawFileName; 24 | vector method; 25 | vector flag; 26 | // vector mtime; 27 | // vector > compressedBlockSize; 28 | vector > crc32; 29 | vector > rawBlockSize; 30 | vector > seekOffSetStart; 31 | vector > spanLength; 32 | }; 33 | 34 | class mGzip { 35 | public: 36 | static bool check_mGzip(string filePath); 37 | static vector allocate(int threadsNum, vector filesPath); 38 | 39 | static int getOneBlock(FILE *pFile, int& method, int& flag, long &curOffSet, vector &blockStarts, vector &length, vector &size, 40 | vector &crc32, string &fileName); 41 | }; 42 | 43 | 44 | #endif //SOAPNUKE_MGZIP_H 45 | #endif -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "process_argv.h" 6 | #include "global_parameter.h" 7 | #include "peprocess.h" 8 | #include "seprocess.h" 9 | #include 10 | #ifdef _PROCESSHTS 11 | #include "processHts.h" 12 | #endif 13 | #include "processStLFR.h" 14 | //#include "mGzip.h" 15 | 16 | //vector C_global_parameter::threadInfo; 17 | int main(int argc,char* argv[]){ 18 | //C_global_variable gv; //global variable, include statistic information 19 | C_global_parameter gp; //global parameter generated by commands 20 | check_module(argc,argv); //check module 21 | global_parameter_initial(argc,argv,gp); //initial global parameter 22 | //C_global_parameter gp=C_global_parameter(argc,argv); 23 | check_parameter(argc,argv,gp); //check global parameter whether correct 24 | //check input format whether mGzip 25 | // gp.whether_mGzip=mGzip::check_mGzip(gp.fq1_path); 26 | // if(gp.whether_mGzip){ 27 | // vector inputFqList; 28 | // if(gp.inputAsList){ 29 | // ifstream inList(gp.fq1_path); 30 | // string line; 31 | // while(getline(inList,line)){ 32 | // inputFqList.push_back(line); 33 | // } 34 | // }else{ 35 | // inputFqList.push_back(gp.fq1_path); 36 | // } 37 | // C_global_parameter::threadInfo=mGzip::allocate(gp.threads_num,inputFqList); 38 | // 39 | // } 40 | if(gp.module_name=="filterHts"){ 41 | #ifdef _PROCESSHTS 42 | processHts new_task(gp); 43 | if(new_task.pe){ 44 | new_task.processPE(); 45 | }else{ 46 | new_task.processSE(); 47 | } 48 | #else 49 | cout<<"Error:filterHts module not installed, please re-make after set USEHTS true in Makefile, details see Install part in Readme"<process(); 56 | }else { 57 | if (!gp.fq2_path.empty()) { //PE data 58 | peProcess new_task(gp); 59 | new_task.process(); 60 | // cout<<"dup number:\t"<readType=readType; 17 | this->filter=filter; 18 | this->lineNumber=lineNumber; 19 | } 20 | string toString(){ 21 | ostringstream concat; 22 | concat< 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "process_argv.h" 17 | #include "global_parameter.h" 18 | #include "global_variable.h" 19 | #include "sequence.h" 20 | #include "BloomFilter.h" 21 | #include "ReverseBloomFilter.h" 22 | #include "rmdup.h" 23 | // #include "Md5.h" 24 | // 0:bf 1:rbf 2:normal 25 | #define RMDUP 2 26 | #define max_thread 72 27 | struct PEstatOption 28 | { 29 | vector *fq1s, *fq2s; 30 | C_fastq_file_stat *stat1, *stat2; 31 | PEstatOption() 32 | { 33 | fq1s = fq2s = NULL; 34 | stat1 = stat2 = NULL; 35 | } 36 | }; 37 | struct PEcalOption 38 | { 39 | C_filter_stat *local_fs; 40 | vector *fq1s, *fq2s; 41 | vector *trim_result1, *trim_result2, *clean_result1, *clean_result2; 42 | PEcalOption() 43 | { 44 | local_fs = NULL; 45 | fq1s = NULL; 46 | fq2s = NULL; 47 | trim_result1 = trim_result2 = clean_result1 = clean_result2 = NULL; 48 | } 49 | ~PEcalOption() 50 | { 51 | } 52 | }; 53 | class peProcess 54 | { 55 | public: 56 | explicit peProcess(C_global_parameter m_gp); 57 | void process(); 58 | void print_stat(); 59 | void update_stat(C_fastq_file_stat &fq1s_stat, C_fastq_file_stat &fq2s_stat, C_filter_stat &fs_stat, string type); 60 | void *stat_pe_fqs(PEstatOption opt, string dataType); 61 | virtual void filter_pe_fqs(PEcalOption *opt); 62 | virtual void filter_pe_fqs(PEcalOption *opt, int index); 63 | int read(vector &pe1, vector &pe2, ifstream &infile1, ifstream &infile2); 64 | void peWrite(vector &pe1, vector &pe2, gzFile out1, gzFile out2); 65 | void peWrite(vector &pe1, vector &pe2, FILE *out1, FILE *out2); 66 | void preOutput(int type, C_fastq &a); 67 | void output_fastqs(string type, vector &fq1, gzFile outfile); 68 | void output_fastqs(string type, vector &fq1, FILE *outfile); 69 | void merge_stat(); 70 | void C_fastq_init(C_fastq &a, C_fastq &b); 71 | 72 | virtual void *sub_thread(int index); 73 | virtual void *sub_thread_rmdup_step1(int index); 74 | void catRmFile(int index, int cycle, string type, bool gzFormat); 75 | void catRmFile(vector indexes, int cycle, string type, bool gzFormat); 76 | void *smallFilesProcess(); 77 | void peStreaming_stat(C_global_variable &local_gv); 78 | void make_tmpDir(); 79 | void remove_tmpDir(); 80 | void create_thread_read(int index); 81 | void create_thread_smalltrimoutputFile(int index, int cycle); 82 | void create_thread_smallcleanoutputFile(int index, int cycle); 83 | void thread_process_reads(int index, int cycle, vector &fq1s, vector &fq2s); 84 | void closeSmallTrimFileHandle(int index); 85 | void closeSmallCleanFileHandle(int index); 86 | void run_cmd(string cmd); 87 | void run_extract_random(); 88 | void *sub_extract(string in, int mo, string out); 89 | void rmTmpFiles(); 90 | void check_disk_available(); 91 | void extractReadsToFile(int cycle, int thread_index, int reads_number, string position, int &output_index, bool gzFormat); 92 | void extractReadsToFile(int cycle, int thread_index, int reads_number, string position, bool gzFormat); 93 | void reArrangeReads(int cycle, bool gzFormat, bool split, int &splitIndex, int &preNum); 94 | void addCleanList(int tmp_cycle, int index); 95 | int dupNum; 96 | mutex checkDup; 97 | BloomFilter *dupDB; 98 | ReverseBloomFilter *RdupDB; 99 | // set checkDupMap; 100 | gzFile dupOut1, dupOut2; 101 | gzFile *dupThreadOut1, *dupThreadOut2; 102 | mutex logLock; 103 | 104 | public: 105 | C_global_parameter gp; 106 | C_global_variable gv; 107 | gzFile *multi_gzfq1, *multi_gzfq2; 108 | FILE **multi_Nongzfq1, **multi_Nongzfq2; 109 | gzFile *gz_trim_out1, *gz_trim_out2; 110 | gzFile *gz_clean_out1, *gz_clean_out2; 111 | FILE **nongz_trim_out1; 112 | FILE **nongz_trim_out2; 113 | FILE **nongz_clean_out1; 114 | FILE **nongz_clean_out2; 115 | ofstream of_log; 116 | off_t *t_start_pos; 117 | off_t *t_end_pos; 118 | int fq1fd, fq2fd; 119 | string tmp_dir; 120 | int limit_end; 121 | 122 | mutex pe_cal_m; 123 | mutex read_m, write_m; 124 | int buffer; 125 | string new_fq1_path, new_fq2_path; 126 | C_filter_stat *local_fs; 127 | C_fastq_file_stat *local_raw_stat1, *local_raw_stat2, *local_trim_stat1, *local_trim_stat2, *local_clean_stat1, *local_clean_stat2; 128 | string *sticky_reads1, *sticky_reads2; 129 | gzFile gz_fq1, gz_fq2; 130 | map pe1_out, pe2_out; 131 | // int queue_buffer; 132 | int bq_check, pair_check; 133 | int cur_cat_cycle; // current cycle of cat small files 134 | vector *readyTrimFiles1, *readyTrimFiles2, *readyCleanFiles1, *readyCleanFiles2; // list of small files in threads 135 | vector *clean_file_readsNum; // reads number of small files in threads 136 | int *sub_thread_done; 137 | int end_sub_thread; 138 | int patch; 139 | uint64_t *threadReadsNum; 140 | uint64_t *totalData; 141 | uint64_t *threadCurReadReadsNumIdx; 142 | vector> threadData; 143 | vector> threadDataNum; 144 | bool *dupFlag; 145 | 146 | private: 147 | int used_threads_num; 148 | }; 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /src/processHts.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-04-08. 3 | // 4 | #ifndef SOAPNUKE_PROCESSHTS_H 5 | #define SOAPNUKE_PROCESSHTS_H 6 | #include 7 | #include 8 | 9 | //#include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "global_parameter.h" 15 | #include "seprocess.h" 16 | #include "peprocess.h" 17 | #include "peFilterTmpOut.h" 18 | 19 | using namespace::std; 20 | #define READBUF 1000 21 | //同时支持bam、cram的读写 22 | //todo 23 | //以后支持写入fastq 24 | class processHts{ 25 | public: 26 | bool pe; 27 | C_global_parameter gp; 28 | seProcess *seP; 29 | peProcess *peP; 30 | string inputCram; 31 | htsFile *in; 32 | string outputFormat; 33 | //多线程相关数据结构 34 | htsFile *cleanOut,*filteredOut; 35 | htsFile** threadIn; 36 | htsFile** threadCleanOut,**threadFilteredOut; 37 | string tmpDir; 38 | int* threadProgress; 39 | int* threadWriteProgress; 40 | mutex writeLock; 41 | bool* threadDone; 42 | BGZF *cleanBam,*filteredBam; 43 | 44 | // cram_fd* cramOut; 45 | bam_hdr_t *header; 46 | bam1_t *aln; 47 | ofstream log; 48 | int8_t* seq_comp_table; 49 | int readsNumInPatch; 50 | //主线程读取数据模式下的每个子线程读取数量 51 | int lineNumPerThread; 52 | int keysNumber; 53 | const htsFormat* inputFormat; 54 | string inputFormatString; 55 | string outFormat; 56 | mutex* blockDataMutex; 57 | mutex writeMutex; 58 | // bamBlock** dataPool; 59 | // bamBlock** dataPool2; 60 | int pool1Stat; 61 | int pool2Stat; 62 | string* seLastID; 63 | public: 64 | explicit processHts(C_global_parameter m_gp); 65 | 66 | // void process(); 67 | 68 | void processSE(); 69 | void processPE(); 70 | 71 | void openHts(); 72 | 73 | void *se_sub_thread(int i); 74 | void *peSingThread(int i); 75 | 76 | 77 | bam1_t** readSEData(vector &pVector); 78 | char *get_read(bam1_t*); 79 | char *reverse(char *str); 80 | 81 | char *get_quality(bam1_t*); 82 | 83 | void filter_se_fqs(SEcalOption opt, bool *filterFlag); 84 | 85 | void writeBackToCram(bam1_t**,bool *filterFlag,int size); 86 | 87 | void writeBam(); 88 | void writeCram(); 89 | 90 | void closeHts(htsFile *fp); 91 | 92 | void prepare(); 93 | 94 | void clean(); 95 | 96 | bam1_t** readPEData(vector &fq1s, vector &fq2s, int *IDstat,bam1_t* lastLine,int &readLineNum); 97 | 98 | void writeBackToCram(bam1_t** data, bool *filterFlag, int size, int *IDstat); 99 | 100 | void check_disk_available(); 101 | 102 | void filter_pe_fqs(PEcalOption *opt,bool* filterFlag); 103 | 104 | void writeSam(); 105 | 106 | void pe_sortedByPos_sub_thread(int index); 107 | 108 | void writeFile(); 109 | 110 | int readPEData(bam1_t** data,int patch); 111 | 112 | void parseRead(bam1_t *data, C_fastq& read); 113 | 114 | void multiThreadsPEprocess(); 115 | void multiThreadsSEprocess(); 116 | 117 | void* peSubThread(vector fq1s,vector fq2s,int start,int end,bool* threadFilter,int index); 118 | 119 | void* seSubThread(bam1_t** data,int start,int end,bool* threadFilter,int index); 120 | 121 | void writeFile(int index,int patch); 122 | 123 | void writeSam(int index, int patch); 124 | 125 | void writeBam(int index, int patch); 126 | 127 | void writeCram(int index, int patch); 128 | 129 | void closeThreadFd(int index); 130 | 131 | void *peDependentIOSubThread(int index); 132 | 133 | bam1_t ** 134 | readPEData(vector &fq1s, vector &fq2s, int *IDstat,int &readLineNum, int index, long long &totalNum); 135 | 136 | void openHts(int index); 137 | 138 | void writeBackToCram(bam1_t **data, bool *filterFlag, int size, int index); 139 | 140 | void catSmallFiles(); 141 | 142 | void catCram(vector smallFiles, htsFile *out); 143 | 144 | void catBam(vector smallFiles, BGZF* fp); 145 | 146 | void *seDependentIOSubThread(int index); 147 | 148 | bam1_t **readSEData(vector &fq1s, int *IDstat, int &readLineNum, int index, long long &totalNum); 149 | 150 | // bamBlock *readPEData(bam1_t *lastLine); 151 | 152 | void* peSubThread2(int index); 153 | 154 | bam1_t **readSEData(int &lineNum); 155 | }; 156 | #endif //SOAPNUKE_PROCESSHTS_H -------------------------------------------------------------------------------- /src/processStLFR.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-07-14. 3 | // 4 | 5 | #include 6 | #include "processStLFR.h" 7 | #include "read_filter.h" 8 | #define READBUF 1000 9 | processStLFR::processStLFR(C_global_parameter m_gp) : peProcess(m_gp) { 10 | /*set barcodeList; 11 | vector barcodeStartPos; 12 | vector barcodeLength;*/ 13 | ifstream bl(m_gp.barcodeListPath); 14 | string line; 15 | int count=0; 16 | while(getline(bl,line)){ 17 | count++; 18 | vector eles; 19 | line_split(line,eles); 20 | 21 | string barcodeSeq=eles[0]; 22 | for(int i=0;i eles; 42 | line_split(m_gp.barcodeRegionStr,',',eles); 43 | if(eles.size()!=3){ 44 | cerr<<"Error:barcode region format error"< tmpMap; 48 | for(vector::iterator ix=eles.begin();ix!=eles.end();ix++){ 49 | vector eles2; 50 | line_split(*ix,'_',eles2); 51 | if(eles2.size()!=2){ 52 | cerr<<"Error:barcode region format error"< bfSize) { 89 | // multiple -= 5; 90 | // if (multiple < 10) { 91 | // cerr << "Error:reads number maybe is too large to do remove duplication" << endl; 92 | // exit(1); 93 | // } 94 | // } 95 | // dupDB = new BloomFilter(guessedReadsNum, multiple); 96 | // dupNum=0; 97 | // } 98 | } 99 | 100 | void processStLFR::filter_pe_fqs(PEcalOption *opt,int index) { 101 | vector::iterator i2=opt->fq2s->begin(); 102 | vector::iterator i_end=opt->fq1s->end(); 103 | bool* dupFilter=new bool[opt->fq1s->size()]; 104 | if(gp.rmdup){ 105 | if(RMDUP!=2) 106 | checkDup.lock(); 107 | memset(dupFilter,false,opt->fq1s->size()); 108 | int iter=0; 109 | for(vector::iterator i=opt->fq1s->begin();i!=i_end;i++){ 110 | string checkSeq=(*i).sequence+(*i2).sequence; 111 | // if(checkDupMap.find(checkSeq)!=checkDupMap.end()){ 112 | // dupNum++; 113 | // }else{ 114 | // checkDupMap.insert(checkSeq); 115 | // } 116 | if(RMDUP==0) { 117 | if (dupDB->query(checkSeq)) { 118 | dupNum++; 119 | dupFilter[iter] = true; 120 | gzwrite(dupOut1, (*i).toString().c_str(), (*i).toString().size()); 121 | gzwrite(dupOut2, (*i2).toString().c_str(), (*i2).toString().size()); 122 | } else { 123 | dupDB->add(); 124 | } 125 | }else if(RMDUP==1){ 126 | if(RdupDB->query(checkSeq)){ 127 | dupNum++; 128 | dupFilter[iter] = true; 129 | gzwrite(dupOut1, (*i).toString().c_str(), (*i).toString().size()); 130 | gzwrite(dupOut2, (*i2).toString().c_str(), (*i2).toString().size()); 131 | }else{ 132 | RdupDB->add(); 133 | } 134 | }else{ 135 | if(dupFlag[threadCurReadReadsNumIdx[index]-opt->fq1s->size()+iter]){ 136 | // dupNum++; 137 | dupFilter[iter] = true; 138 | gzwrite(dupThreadOut1[index], (*i).toString().c_str(), (*i).toString().size()); 139 | gzwrite(dupThreadOut2[index], (*i2).toString().c_str(), (*i2).toString().size()); 140 | } 141 | } 142 | iter++; 143 | i2++; 144 | if(i2==opt->fq2s->end()){ 145 | break; 146 | } 147 | } 148 | if(RMDUP!=2) 149 | checkDup.unlock(); 150 | } 151 | i2=opt->fq2s->begin(); 152 | i_end=opt->fq1s->end(); 153 | int iter=0; 154 | for(vector::iterator i=opt->fq1s->begin();i!=i_end;i++){ 155 | string barcodeCombine=stLFRprocessBarcode(*i,*i2); 156 | C_pe_fastq_filter pe_fastq_filter=C_pe_fastq_filter(*i,*i2,gp); 157 | if(dupFilter[iter]){ 158 | pe_fastq_filter.reads_result.dup=true; 159 | } 160 | iter++; 161 | pe_fastq_filter.setStLFRbarcode(barcodeCombine); 162 | /*int head_hdcut,head_lqcut,tail_hdcut,tail_lqcut,adacut_pos; 163 | int contam_pos; 164 | int global_contam_pos; 165 | int raw_length;*/ 166 | pe_fastq_filter.pe_trim(gp); 167 | if(gp.adapter_discard_or_trim=="trim" || gp.contam_discard_or_trim=="trim" || !gp.trim.empty() || !gp.trimBadHead.empty() || !gp.trimBadTail.empty()){ 168 | (*i).head_hdcut=pe_fastq_filter.fq1.head_hdcut; 169 | (*i).head_lqcut=pe_fastq_filter.fq1.head_lqcut; 170 | (*i).tail_hdcut=pe_fastq_filter.fq1.tail_hdcut; 171 | (*i).tail_lqcut=pe_fastq_filter.fq1.tail_lqcut; 172 | (*i).adacut_pos=pe_fastq_filter.fq1.adacut_pos; 173 | //(*i).contam_pos=pe_fastq_filter.fq1.contam_pos; 174 | //(*i).global_contam_pos=pe_fastq_filter.fq1.global_contam_pos; 175 | //(*i).raw_length=pe_fastq_filter.fq1.raw_length; 176 | (*i2).head_hdcut=pe_fastq_filter.fq2.head_hdcut; 177 | (*i2).head_lqcut=pe_fastq_filter.fq2.head_lqcut; 178 | (*i2).tail_hdcut=pe_fastq_filter.fq2.tail_hdcut; 179 | (*i2).tail_lqcut=pe_fastq_filter.fq2.tail_lqcut; 180 | (*i2).adacut_pos=pe_fastq_filter.fq2.adacut_pos; 181 | //(*i2).contam_pos=pe_fastq_filter.fq2.contam_pos; 182 | //(*i2).global_contam_pos=pe_fastq_filter.fq2.global_contam_pos; 183 | //(*i2).raw_length=pe_fastq_filter.fq2.raw_length; 184 | } 185 | if(!gp.trim_fq1.empty()){ 186 | preOutput(1,pe_fastq_filter.fq1); 187 | preOutput(2,pe_fastq_filter.fq2); 188 | opt->trim_result1->emplace_back(pe_fastq_filter.fq1); 189 | opt->trim_result2->emplace_back(pe_fastq_filter.fq2); 190 | } 191 | if(pe_fastq_filter.pe_discard(opt->local_fs,gp)!=1){ 192 | if(!gp.clean_fq1.empty()){ 193 | preOutput(1,pe_fastq_filter.fq1); 194 | preOutput(2,pe_fastq_filter.fq2); 195 | opt->clean_result1->emplace_back(pe_fastq_filter.fq1); 196 | opt->clean_result2->emplace_back(pe_fastq_filter.fq2); 197 | } 198 | } 199 | i2++; 200 | if(i2==opt->fq2s->end()){ 201 | break; 202 | } 203 | } 204 | delete[] dupFilter; 205 | } 206 | 207 | void *processStLFR::sub_thread(int index) { 208 | if(gp.inputAsList) { 209 | logLock.lock(); 210 | of_log << get_local_time() << "\tthread " << index << " start" << endl; 211 | logLock.unlock(); 212 | // create_thread_read(index); 213 | int thread_cycle = -1; 214 | 215 | ifstream inputList(gp.fq1_path); 216 | ifstream inputList2(gp.fq2_path); 217 | string fq1Path,fq2Path; 218 | char buf1[READBUF], buf2[READBUF]; 219 | C_fastq fastq1, fastq2; 220 | C_fastq_init(fastq1, fastq2); 221 | int thread_read_block = 4 * gp.patchSize * patch; 222 | vector fq1s, fq2s; 223 | // bool inputGzformat = true; 224 | long long file1_line_num(0), file2_line_num(0); 225 | long long block_line_num1(0), block_line_num2(0); 226 | while(1){ 227 | getline(inputList,fq1Path); 228 | getline(inputList2,fq2Path); 229 | if(fq1Path=="" || fq2Path=="") { 230 | if (!fq1s.empty()) { 231 | if (end_sub_thread == 1) { 232 | break; 233 | } 234 | int tmp_cycle = file1_line_num / (thread_read_block * gp.threads_num); 235 | if (tmp_cycle != thread_cycle && tmp_cycle > 0) { 236 | addCleanList(thread_cycle, index); 237 | } 238 | thread_cycle = tmp_cycle; 239 | threadCurReadReadsNumIdx[index]=file1_line_num/4; 240 | thread_process_reads(index, thread_cycle, fq1s, fq2s); 241 | if (limit_end > 0) { 242 | break; 243 | } 244 | } 245 | gzclose(multi_gzfq1[index]); 246 | gzclose(multi_gzfq2[index]); 247 | break; 248 | } 249 | multi_gzfq1[index] = gzopen(fq1Path.c_str(), "rb"); 250 | if (!multi_gzfq1[index]) { 251 | cerr << "Error:cannot open the file," << fq1Path << endl; 252 | exit(1); 253 | } 254 | gzsetparams(multi_gzfq1[index], 2, Z_DEFAULT_STRATEGY); 255 | gzbuffer(multi_gzfq1[index], 2048 * 2048); 256 | multi_gzfq2[index] = gzopen(fq2Path.c_str(), "rb"); 257 | if (!multi_gzfq2[index]) { 258 | cerr << "Error:cannot open the file," << fq2Path << endl; 259 | exit(1); 260 | } 261 | gzsetparams(multi_gzfq2[index], 2, Z_DEFAULT_STRATEGY); 262 | gzbuffer(multi_gzfq2[index], 2048 * 2048); 263 | 264 | gzFile tmpRead = gzopen(fq1Path.c_str(), "rb"); 265 | int spaceNum = 0; 266 | if (gzgets(tmpRead, buf1, READBUF) != NULL) { 267 | string tmpLine(buf1); 268 | while (isspace(tmpLine[tmpLine.size() - 1])) { 269 | spaceNum++; 270 | tmpLine.erase(tmpLine.size() - 1); 271 | } 272 | } 273 | gzclose(tmpRead); 274 | while (1) { 275 | if (gzgets(multi_gzfq1[index], buf1, READBUF) != NULL) { 276 | if ((file1_line_num / thread_read_block) % gp.threads_num == index) { 277 | block_line_num1++; 278 | if (block_line_num1 % 4 == 1) { 279 | fastq1.seq_id.assign(buf1); 280 | fastq1.seq_id.erase(fastq1.seq_id.size() - spaceNum, spaceNum); 281 | } 282 | if (block_line_num1 % 4 == 2) { 283 | fastq1.sequence.assign(buf1); 284 | fastq1.sequence.erase(fastq1.sequence.size() - spaceNum, spaceNum); 285 | } 286 | if (block_line_num1 % 4 == 0) { 287 | fastq1.qual_seq.assign(buf1); 288 | fastq1.qual_seq.erase(fastq1.qual_seq.size() - spaceNum, spaceNum); 289 | } 290 | } 291 | file1_line_num++; 292 | } 293 | if (gzgets(multi_gzfq2[index], buf2, READBUF) != NULL) { 294 | if ((file2_line_num / thread_read_block) % gp.threads_num == index) { 295 | block_line_num2++; 296 | if (block_line_num2 % 4 == 1) { 297 | fastq2.seq_id.assign(buf2); 298 | fastq2.seq_id.erase(fastq2.seq_id.size() - spaceNum, spaceNum); 299 | } else if (block_line_num2 % 4 == 2) { 300 | fastq2.sequence.assign(buf2); 301 | fastq2.sequence.erase(fastq2.sequence.size() - spaceNum, spaceNum); 302 | } else if (block_line_num2 % 4 == 0) { 303 | fastq2.qual_seq.assign(buf2); 304 | fastq2.qual_seq.erase(fastq2.qual_seq.size() - spaceNum, spaceNum); 305 | fq1s.emplace_back(fastq1); 306 | fq2s.emplace_back(fastq2); 307 | 308 | if (fq1s.size() == gp.patchSize) { 309 | if (end_sub_thread == 1) { 310 | break; 311 | } 312 | int tmp_cycle = file2_line_num / (thread_read_block * gp.threads_num); 313 | if (tmp_cycle != thread_cycle && tmp_cycle > 0) { 314 | addCleanList(thread_cycle, index); 315 | } 316 | thread_cycle = tmp_cycle; 317 | threadCurReadReadsNumIdx[index]=file1_line_num/4; 318 | thread_process_reads(index, thread_cycle, fq1s, fq2s); 319 | if (index == 0) { 320 | of_log << get_local_time() << " processed_reads:\t" << file1_line_num / 4 << endl; 321 | } 322 | } 323 | } 324 | } 325 | file2_line_num++; 326 | } else { 327 | break; 328 | } 329 | } 330 | } 331 | if (thread_cycle >= 0) 332 | addCleanList(thread_cycle, index); 333 | check_disk_available(); 334 | sub_thread_done[index] = 1; 335 | logLock.lock(); 336 | of_log << get_local_time() << "\tthread " << index << " done\t" << endl; 337 | logLock.unlock(); 338 | return &bq_check; 339 | }else{ 340 | peProcess::sub_thread(index); 341 | return &bq_check; 342 | } 343 | } 344 | 345 | string processStLFR::stLFRprocessBarcode(C_fastq &fastq1, C_fastq &fastq2) { 346 | if(fastq1.seq_id.find("/1")==string::npos || fastq2.seq_id.find("/2")==string::npos){ 347 | cerr<<"Error:Reads1 and Reads2 ID error in /1 or /2,"< fq1s, fq2s; 417 | // bool inputGzformat = true; 418 | long long file1_line_num(0), file2_line_num(0); 419 | long long block_line_num1(0), block_line_num2(0); 420 | vector seqs; 421 | while(1){ 422 | getline(inputList,fq1Path); 423 | getline(inputList2,fq2Path); 424 | string fq1seq,fq2seq; 425 | if(fq1Path=="" || fq2Path=="") { 426 | if (!seqs.empty()) { 427 | uint64_t* curData=new uint64_t[seqs.size()]; 428 | memset(curData,0,sizeof(uint64_t)*seqs.size()); 429 | for(int i=0;i()(seqs[i]); 431 | // curData[i]=new unsigned char[16]; 432 | // MDString(seqs[i].c_str(),curData[i]); 433 | } 434 | threadData[index].emplace_back(curData); 435 | threadReadsNum[index]+=seqs.size(); 436 | threadDataNum[index].emplace_back(seqs.size()); 437 | seqs.clear(); 438 | if (limit_end > 0) { 439 | break; 440 | } 441 | } 442 | gzclose(multi_gzfq1[index]); 443 | gzclose(multi_gzfq2[index]); 444 | break; 445 | } 446 | multi_gzfq1[index] = gzopen(fq1Path.c_str(), "rb"); 447 | if (!multi_gzfq1[index]) { 448 | cerr << "Error:cannot open the file," << fq1Path << endl; 449 | exit(1); 450 | } 451 | gzsetparams(multi_gzfq1[index], 2, Z_DEFAULT_STRATEGY); 452 | gzbuffer(multi_gzfq1[index], 2048 * 2048); 453 | multi_gzfq2[index] = gzopen(fq2Path.c_str(), "rb"); 454 | if (!multi_gzfq2[index]) { 455 | cerr << "Error:cannot open the file," << fq2Path << endl; 456 | exit(1); 457 | } 458 | gzsetparams(multi_gzfq2[index], 2, Z_DEFAULT_STRATEGY); 459 | gzbuffer(multi_gzfq2[index], 2048 * 2048); 460 | gzFile tmpRead = gzopen(fq1Path.c_str(), "rb"); 461 | int spaceNum = 0; 462 | if (gzgets(tmpRead, buf1, READBUF) != NULL) { 463 | string tmpLine(buf1); 464 | while (isspace(tmpLine[tmpLine.size() - 1])) { 465 | spaceNum++; 466 | tmpLine.erase(tmpLine.size() - 1); 467 | } 468 | } 469 | gzclose(tmpRead); 470 | 471 | while (1) { 472 | if (gzgets(multi_gzfq1[index], buf1, READBUF) != NULL) { 473 | if ((file1_line_num / thread_read_block) % gp.threads_num == index) { 474 | block_line_num1++; 475 | if (block_line_num1 % 4 == 2) { 476 | fq1seq.assign(buf1); 477 | fq1seq.erase(fq1seq.size() - spaceNum,spaceNum); 478 | } 479 | } 480 | file1_line_num++; 481 | } 482 | if (gzgets(multi_gzfq2[index], buf2, READBUF) != NULL) { 483 | if ((file2_line_num / thread_read_block) % gp.threads_num == index) { 484 | block_line_num2++; 485 | if (block_line_num2 % 4 == 2) { 486 | fq2seq.assign(buf2); 487 | fq2seq.erase(fq2seq.size() - spaceNum,spaceNum); 488 | string ligatedStr=fq1seq+fq2seq; 489 | seqs.emplace_back(ligatedStr); 490 | } 491 | if (seqs.size() == gp.patchSize) { 492 | uint64_t* curData=new uint64_t[seqs.size()]; 493 | memset(curData,0,sizeof(uint64_t)*seqs.size()); 494 | for(int i=0;i()(seqs[i]); 496 | // curData[i]=new unsigned char[16]; 497 | // MDString(seqs[i].c_str(),curData[i]); 498 | } 499 | threadData[index].emplace_back(curData); 500 | threadDataNum[index].emplace_back(seqs.size()); 501 | threadReadsNum[index]+=seqs.size(); 502 | seqs.clear(); 503 | if (index == 0) { 504 | of_log << get_local_time() << " processed_reads:\t" << file1_line_num / 4 << endl; 505 | } 506 | } 507 | } 508 | file2_line_num++; 509 | } else { 510 | break; 511 | } 512 | } 513 | } 514 | if (thread_cycle >= 0) 515 | addCleanList(thread_cycle, index); 516 | check_disk_available(); 517 | // sub_thread_done[index] = 1; 518 | logLock.lock(); 519 | of_log << get_local_time() << "\tthread " << index << " done\t" << endl; 520 | logLock.unlock(); 521 | return &bq_check; 522 | }else{ 523 | peProcess::sub_thread_rmdup_step1(index); 524 | return &bq_check; 525 | } 526 | } 527 | void processStLFR::filter_pe_fqs(PEcalOption *opt) { 528 | vector::iterator 529 | i2 530 | = opt->fq2s 531 | ->begin(); 532 | vector::iterator 533 | i_end 534 | = opt->fq1s 535 | ->end(); 536 | // bool* dupFilter=new bool[opt->fq1s->size()]; 537 | // if(gp.rmdup){ 538 | // checkDup.lock(); 539 | // memset(dupFilter,false,opt->fq1s->size()); 540 | // int iter=0; 541 | // for(vector::iterator i=opt->fq1s->begin();i!=i_end;i++){ 542 | // string checkSeq=(*i).sequence+(*i2).sequence; 543 | //// if(checkDupMap.find(checkSeq)!=checkDupMap.end()){ 544 | //// dupNum++; 545 | //// }else{ 546 | //// checkDupMap.insert(checkSeq); 547 | //// } 548 | // if(dupDB->query(checkSeq)){ 549 | // dupFilter[iter]=true; 550 | // gzwrite(dupOut1,(*i).toString().c_str(),(*i).toString().size()); 551 | // gzwrite(dupOut2,(*i2).toString().c_str(),(*i2).toString().size()); 552 | // }else{ 553 | // dupDB->add(); 554 | // } 555 | // iter++; 556 | // i2++; 557 | // if(i2==opt->fq2s->end()){ 558 | // break; 559 | // } 560 | // } 561 | // checkDup.unlock(); 562 | // } 563 | // i2=opt->fq2s->begin(); 564 | // i_end=opt->fq1s->end(); 565 | int 566 | iter 567 | = 0; 568 | for ( 569 | vector::iterator 570 | i 571 | = opt->fq1s 572 | ->begin(); 573 | i 574 | != i_end; 575 | i++ 576 | ) 577 | { 578 | string 579 | barcodeCombine 580 | = stLFRprocessBarcode( 581 | *i 582 | , *i2 583 | ); 584 | C_pe_fastq_filter 585 | pe_fastq_filter 586 | = C_pe_fastq_filter( 587 | *i 588 | , *i2 589 | , gp 590 | ); 591 | // if(dupFilter[iter]){ 592 | // pe_fastq_filter.reads_result.dup=true; 593 | // } 594 | iter++; 595 | pe_fastq_filter.setStLFRbarcode(barcodeCombine); 596 | /*int head_hdcut,head_lqcut,tail_hdcut,tail_lqcut,adacut_pos; 597 | int contam_pos; 598 | int global_contam_pos; 599 | int raw_length;*/ 600 | pe_fastq_filter.pe_trim(gp); 601 | if (gp.adapter_discard_or_trim 602 | == "trim" 603 | || gp.contam_discard_or_trim 604 | == "trim" 605 | || !gp.trim 606 | .empty() 607 | || !gp.trimBadHead 608 | .empty() 609 | || !gp.trimBadTail 610 | .empty()) 611 | { 612 | (*i).head_hdcut 613 | = pe_fastq_filter.fq1 614 | .head_hdcut; 615 | (*i).head_lqcut 616 | = pe_fastq_filter.fq1 617 | .head_lqcut; 618 | (*i).tail_hdcut=pe_fastq_filter.fq1.tail_hdcut; 619 | (*i).tail_lqcut=pe_fastq_filter.fq1.tail_lqcut; 620 | (*i).adacut_pos=pe_fastq_filter.fq1.adacut_pos; 621 | //(*i).contam_pos=pe_fastq_filter.fq1.contam_pos; 622 | //(*i).global_contam_pos=pe_fastq_filter.fq1.global_contam_pos; 623 | //(*i).raw_length=pe_fastq_filter.fq1.raw_length; 624 | (*i2).head_hdcut=pe_fastq_filter.fq2.head_hdcut; 625 | (*i2).head_lqcut=pe_fastq_filter.fq2.head_lqcut; 626 | (*i2).tail_hdcut=pe_fastq_filter.fq2.tail_hdcut; 627 | (*i2).tail_lqcut=pe_fastq_filter.fq2.tail_lqcut; 628 | (*i2).adacut_pos=pe_fastq_filter.fq2.adacut_pos; 629 | //(*i2).contam_pos=pe_fastq_filter.fq2.contam_pos; 630 | //(*i2).global_contam_pos=pe_fastq_filter.fq2.global_contam_pos; 631 | //(*i2).raw_length=pe_fastq_filter.fq2.raw_length; 632 | } 633 | if(!gp.trim_fq1.empty()){ 634 | preOutput(1,pe_fastq_filter.fq1); 635 | preOutput(2,pe_fastq_filter.fq2); 636 | opt->trim_result1->emplace_back(pe_fastq_filter.fq1); 637 | opt->trim_result2->emplace_back(pe_fastq_filter.fq2); 638 | } 639 | if(pe_fastq_filter.pe_discard(opt->local_fs,gp)!=1){ 640 | if(!gp.clean_fq1.empty()){ 641 | preOutput(1,pe_fastq_filter.fq1); 642 | preOutput(2,pe_fastq_filter.fq2); 643 | opt->clean_result1->emplace_back(pe_fastq_filter.fq1); 644 | opt->clean_result2->emplace_back(pe_fastq_filter.fq2); 645 | } 646 | } 647 | i2++; 648 | if(i2==opt->fq2s->end()){ 649 | break; 650 | } 651 | } 652 | // delete[] dupFilter; 653 | } 654 | -------------------------------------------------------------------------------- /src/processStLFR.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-07-14. 3 | // 4 | 5 | #ifndef SOAPNUKE_PROCESSSTLFR_H 6 | #define SOAPNUKE_PROCESSSTLFR_H 7 | #include 8 | #include "peprocess.h" 9 | #include "BloomFilter.h" 10 | class processStLFR: public peProcess{ 11 | // void process(); 12 | public: 13 | explicit processStLFR(C_global_parameter m_gp); 14 | // void filter_pe_fqs(PEcalOption* opt) override; 15 | void filter_pe_fqs(PEcalOption *opt, int index) override; 16 | void filter_pe_fqs(PEcalOption *opt) override ; 17 | void *sub_thread(int index) override; 18 | void* sub_thread_rmdup_step1(int index) override; 19 | private: 20 | std::map barcodeList; 21 | vector barcodeStartPos; 22 | vector barcodeLength; 23 | 24 | string stLFRprocessBarcode(C_fastq &fastq1, C_fastq &fastq2); 25 | // BloomFilter* dupDB; 26 | // mutex checkDup; 27 | //debug parameter 28 | // set checkDupMap; 29 | 30 | 31 | 32 | }; 33 | #endif //SOAPNUKE_PROCESSSTLFR_H 34 | -------------------------------------------------------------------------------- /src/process_argv.h: -------------------------------------------------------------------------------- 1 | #ifndef _PROCESS_ARGV_H 2 | #define _PROCESS_ARGV_H 3 | 4 | #include 5 | #include 6 | // #include "module.h" 7 | #include "global_parameter.h" 8 | #include "gc.h" 9 | using namespace ::std; 10 | 11 | #ifndef PACKAGEVERSION 12 | #define PACKAGEVERSION "2.1" 13 | #endif 14 | #ifndef MINORVERSION 15 | #define MINORVERSION "9" 16 | #endif 17 | void check_module(int argc, char *argv[]); 18 | int global_parameter_initial(int argc, char *argv[], C_global_parameter &gp); 19 | bool check_parameter(int argc, char *argv[], C_global_parameter &gp); 20 | void printUsage(string c_module); 21 | void printVersion(); 22 | void printModule(); 23 | void printHtsUsage(); 24 | void initFromConfigFile(C_global_parameter &gp, char *configFile); 25 | #endif 26 | -------------------------------------------------------------------------------- /src/read_filter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "read_filter.h" 9 | #include "global_parameter.h" 10 | #include "gc.h" 11 | using namespace::std; 12 | 13 | #define MAX_LENGTH 1000 14 | bool check_tile_or_fov(string tile,string& tile_parameter){ 15 | if(tile_parameter.find("C")==string::npos){ 16 | if(tile_parameter.find(",")==string::npos){ 17 | if(tile_parameter.find("-")==string::npos){ 18 | if(tile!=tile_parameter){ 19 | return 0; 20 | }else{ 21 | return 1; 22 | } 23 | }else{ 24 | vector line_eles; 25 | line_split(tile_parameter,'-',line_eles); 26 | if(line_eles.size()!=2){ 27 | cerr<<"Error:input tile parameter format error,"< line_eles; 39 | line_split(tile_parameter,',',line_eles); 40 | for(vector::iterator ix=line_eles.begin();ix!=line_eles.end();ix++){ 41 | if((*ix).find("-")!=string::npos){ 42 | vector line_eles2; 43 | line_split(*ix,'-',line_eles2); 44 | if(line_eles2.size()!=2){ 45 | cerr<<"Error:input tile parameter format error,"<<*ix< line_eles; 70 | line_split(tile_parameter,',',line_eles); 71 | for(vector::iterator ix=line_eles.begin();ix!=line_eles.end();ix++){ 72 | if(*ix==tile){ 73 | return 1; 74 | } 75 | } 76 | return 0; 77 | } 78 | } 79 | } 80 | C_fastq_stat_result stat_read(C_fastq& fq_read,C_global_parameter& gp){ //stat some feature of read,not include adapter-related information 81 | C_fastq_stat_result return_value; 82 | return_value.in_adapter_list=0; 83 | return_value.include_adapter_seq=-1; 84 | fq_read.raw_length=fq_read.sequence.size(); 85 | int seq_id_len=fq_read.seq_id.size(); 86 | if(gp.tile.empty()){ 87 | return_value.read_tile=""; 88 | }else{ 89 | int i=0; 90 | int num=0; 91 | 92 | if(gp.seq_type=="0"){ 93 | for(;i=2) 97 | break; 98 | if(num<2 || i+4>=fq_read.seq_id.size()){ 99 | cerr<<"Warning:input fastq maybe not include tile information\n"<=4) 107 | break; 108 | if(num<4 || i+4>=fq_read.seq_id.size()){ 109 | cerr<<"Warning:input fastq maybe not include tile information\n"<='0' && fq_read.seq_id[i+j+1] <= '9') 115 | { 116 | return_value.read_tile.insert(return_value.read_tile.end(),fq_read.seq_id[i+j+1]); 117 | }else{ 118 | cerr<<"Warning:input fastq maybe not include tile information\n"< adapter_list; 155 | ifstream if_adapter_file(gp.adapter_file.c_str()); 156 | if(!if_adapter_file){ 157 | cerr<<"Error:cannot open file,"<=0){ 182 | break; 183 | } 184 | } 185 | if(ada_pos>=0){ 186 | return_value.include_adapter_seq=1; 187 | fq_read.adacut_pos=fq_read.sequence.size()-ada_pos; 188 | } 189 | string contamSeq=fq_read.pairPos==1?gp.contam1_seq:gp.contam2_seq; 190 | if(contamSeq.find(",")==string::npos){ 191 | fq_read.contam_pos=hasContam(fq_read.sequence,contamSeq,gp); 192 | if(fq_read.contam_pos>=0) 193 | return_value.include_contam=1; 194 | }else{ 195 | vector contam_poses=hasContams(fq_read.sequence,contamSeq,gp); 196 | for(vector::iterator ix=contam_poses.begin();ix!=contam_poses.end();ix++){ 197 | if(*ix>=0){ 198 | return_value.include_contam=1; 199 | if(fq_read.contam_pos!=-1){ 200 | if(*ix<=fq_read.contam_pos){ 201 | fq_read.contam_pos=*ix; 202 | } 203 | }else{ 204 | fq_read.contam_pos=*ix; 205 | } 206 | } 207 | } 208 | } 209 | if(!gp.global_contams.empty()){ 210 | vector global_contam_5_poses=hasGlobalContams(fq_read.sequence,gp); 211 | for(vector::iterator ix=global_contam_5_poses.begin();ix!=global_contam_5_poses.end();ix++){ 212 | //cout<<"5pos:\t"<<*ix<=0){ 214 | return_value.include_global_contam=1; 215 | if(fq_read.global_contam_5pos!=-1){ 216 | if(*ix<=fq_read.global_contam_5pos){ 217 | fq_read.global_contam_5pos=*ix; 218 | } 219 | }else{ 220 | fq_read.global_contam_5pos=*ix; 221 | } 222 | } 223 | } 224 | if(fq_read.global_contam_5pos!=-1 && fq_read.global_contam_5pos<=fq_read.sequence.size()/2){ 225 | string reverse_ref=reversecomplementary(fq_read.sequence); 226 | vector global_contam_3_poses=hasGlobalContams(reverse_ref,gp); 227 | for(vector::iterator ix=global_contam_3_poses.begin();ix!=global_contam_3_poses.end();ix++){ 228 | //cout<<"3pos:\t"<<*ix<=0){ 230 | return_value.include_global_contam=1; 231 | if(fq_read.global_contam_3pos!=-1){ 232 | if(*ix<=fq_read.global_contam_3pos){ 233 | fq_read.global_contam_3pos=*ix; 234 | } 235 | }else{ 236 | fq_read.global_contam_3pos=*ix; 237 | } 238 | } 239 | } 240 | } 241 | if(fq_read.global_contam_5pos>=0 && fq_read.global_contam_3pos>=0){ 242 | if(fq_read.global_contam_5pos=20) 305 | return_value.q20_num++; 306 | if(base_quality>=30) 307 | return_value.q30_num++; 308 | } 309 | return_value.qual_len=(fq_read.qual_seq).size(); 310 | return_value.low_qual_base_ratio=float(return_value.low_qual_base_num)/(fq_read.qual_seq).size(); 311 | return_value.mean_quality=(float)total_base_quality/(fq_read.qual_seq).size(); 312 | return return_value; 313 | } 314 | 315 | bool whether_over_overlapped(C_fastq fastq1,C_fastq fastq2,C_global_parameter& gp){ 316 | //code is similar to SOAPnuke 317 | string seq2 = reversecomplementary(fastq2.sequence); 318 | int mismatch, max_mismatch; 319 | int max_match_length = (fastq1.sequence.size() > fastq2.sequence.size()) ? fastq2.sequence.size() : fastq1.sequence.size(); 320 | for (int i = gp.overlap_length; i <= max_match_length; i++){ 321 | max_mismatch = (int)(gp.peMismatchRatio * (float)i); 322 | mismatch = 0; 323 | for (int j = 0; j < i; j++){ 324 | if (fastq1.sequence[fastq1.sequence.size() - i + j] == 'N' || seq2[j] == 'N') 325 | { 326 | mismatch++; 327 | } 328 | else if (fastq1.sequence[fastq1.sequence.size() - i + j] != seq2[j]) 329 | { 330 | mismatch++; 331 | } 332 | } 333 | if (mismatch <= max_mismatch) 334 | return true; 335 | } 336 | return false; 337 | } 338 | void fastq_trim(C_fastq& read,C_global_parameter& gp){ // 1.index_remove 2.adapter_trim 3.hard_trim 4.qual_trim 339 | 340 | string hard_trim=gp.trim; 341 | string low_qual_head_trim=gp.trimBadHead; 342 | string low_qual_tail_trim=gp.trimBadTail; 343 | bool ht_flag(0),lqt_flag(0),index_flag(0),ada_trim_flag(0),contam_trim_flag(0); 344 | if(!hard_trim.empty()) 345 | ht_flag=1; 346 | if(!low_qual_head_trim.empty() || !low_qual_tail_trim.empty()) 347 | lqt_flag=1; 348 | if(gp.index_remove) 349 | index_flag=1; 350 | if(gp.adapter_discard_or_trim=="trim") 351 | ada_trim_flag=1; 352 | if(gp.contam_discard_or_trim=="trim") 353 | contam_trim_flag=1; 354 | if(!ht_flag && !lqt_flag && !index_flag && !ada_trim_flag && !contam_trim_flag && gp.polyG_tail==-1){ 355 | return; 356 | }else{ 357 | if(index_flag){ //remove index. Code is similar to SOAP nuke 358 | if(gp.seq_type=="0"){ 359 | /* old fastq name: @FCD1PB1ACXX:4:1101:1799:2201#GAAGCACG/2\n"; 360 | cout << "\t new fastq name: @HISEQ:310:C5MH9ANXX:1:1101:3517:2043 2:N:0:TCGGTCAC\n"; 361 | */ 362 | // read.seq_id=read.seq_id.substr(0,read.seq_id.find("#")-0); 363 | string tmpId=""; 364 | bool cpFlag=1; 365 | for(int i=0;i head_eles,tail_eles; 392 | int head_low_qual_threshold(0),head_low_qual_trim_length_limit(0),tail_low_qual_threshold(0),tail_low_qual_trim_length_limit(0); 393 | line_split(low_qual_head_trim,',',head_eles); 394 | line_split(low_qual_tail_trim,',',tail_eles); 395 | if(head_eles.size()!=2 && tail_eles.size()!=2){ 396 | cerr<<"Error:low quality base at end format error,"<=head_ix?head_cut:head_ix; 428 | tail_cut=tail_cut>=tail_ix?tail_cut:tail_ix; 429 | } 430 | if(ada_trim_flag){ 431 | //cout<2 && ada_pos0){ 440 | tail_cut=tail_cut>=read.adacut_pos?tail_cut:read.adacut_pos; 441 | } 442 | } 443 | // if(contam_trim_flag){ 444 | // if(read.global_contam_5pos>=0 && read.sequence.size()-read.global_contam_5pos>tail_cut){ 445 | // tail_cut=read.sequence.size()-read.global_contam_5pos; 446 | // } 447 | // if(read.contam_pos>=0 && read.sequence.size()-read.contam_pos>tail_cut){ 448 | // tail_cut=read.sequence.size()-read.contam_pos; 449 | // } 450 | // if(read.global_contam_3pos>=0 && read.sequence.size()-read.global_contam_3pos>head_cut){ 451 | // head_cut=read.sequence.size()-read.global_contam_3pos; 452 | // } 453 | // } 454 | if(gp.polyG_tail!=-1){ 455 | int polyG_n=polyG_number(read.sequence); 456 | if(polyG_n>=gp.polyG_tail){ 457 | if(polyG_n>tail_cut){ 458 | tail_cut=polyG_n; 459 | } 460 | } 461 | } 462 | if(head_cut+tail_cut>read.sequence.size()){ 463 | read.sequence=""; 464 | read.qual_seq=""; 465 | }else{ 466 | read.sequence=read.sequence.substr(head_cut,read.sequence.size()-head_cut-tail_cut); 467 | read.qual_seq=read.qual_seq.substr(head_cut,read.qual_seq.size()-head_cut-tail_cut); 468 | } 469 | 470 | } 471 | } 472 | int polyG_number(string& ref_sequence){ 473 | int polyG_tail_number(0); 474 | for(int i=ref_sequence.size()-1;i>=0;i--){ 475 | if(ref_sequence[i]=='G' || ref_sequence[i]=='g'){ 476 | polyG_tail_number++; 477 | }else{ 478 | break; 479 | } 480 | } 481 | return polyG_tail_number; 482 | } 483 | vector hasContams(string& ref_sequence,string& contam,C_global_parameter& gp){ 484 | if(gp.ctMatchR.find(",")==string::npos){ 485 | cerr<<"Error:the number of ctMatchR value should equal to that of contam sequences"< contams,mrs; 489 | line_split(contam,',',contams); 490 | line_split(gp.ctMatchR,',',mrs); 491 | if(contams.size()!=mrs.size()){ 492 | cerr<<"Error:the number of ctMatchR value should equal to that of contam sequences,"< return_poses; 496 | for(int i=0;i!=contams.size();i++){ 497 | float tmp_mr=atof(mrs[i].c_str()); 498 | int tmp_pos=hasContam(ref_sequence,contams[i],gp,tmp_mr); 499 | return_poses.emplace_back(tmp_pos); 500 | if(tmp_pos>=0 && tmp_pos= segMatchTemp) 538 | return 0; 539 | } 540 | else{ 541 | if (ref_sequence[c] != 'N'){ 542 | mis++; 543 | maxSegMatch = 0; 544 | if (mis > misMatchTemp) 545 | break; 546 | } 547 | } 548 | } 549 | if (mis <= misMatchTemp) 550 | return 0; 551 | } 552 | 553 | for (r1 = 0; r1 <= readLen - contamLen; ++r1) 554 | { 555 | maxSegMatch = 0; 556 | mis = 0; 557 | 558 | for (int c = 0; c < contamLen; ++c) 559 | { 560 | if (contam[c] == ref_sequence[r1 + c]){ 561 | maxSegMatch ++; 562 | if (maxSegMatch >= segMatchThr) 563 | return r1; 564 | } 565 | else{ 566 | if (ref_sequence[r1 + c] != 'N'){ 567 | mis++; 568 | maxSegMatch = 0; 569 | if (mis > gp.adaMis) 570 | break; 571 | } 572 | } 573 | } 574 | if (mis <= gp.adaMis) 575 | return r1; 576 | } 577 | 578 | for (r1 = 0; r1 < contamLen - gp.adaEdge; ++r1) 579 | { 580 | mis = 0; 581 | maxSegMatch = 0; 582 | misMatchTemp = r1/misGrad; 583 | segMatchTemp = 7 + r1/segGrad; 584 | 585 | for (int c = 0; c < r1+gp.adaEdge; ++c) 586 | { 587 | if (contam[c] == ref_sequence[readLen-r1-gp.adaEdge+c]){ 588 | maxSegMatch++; 589 | if (maxSegMatch >= segMatchTemp) 590 | return readLen-r1-gp.adaEdge; 591 | } 592 | else{ 593 | if (ref_sequence[readLen-r1-gp.adaEdge+c] != 'N'){ 594 | mis++; 595 | maxSegMatch = 0; 596 | if (mis > misMatchTemp) 597 | break; 598 | } 599 | } 600 | } 601 | if (mis <= misMatchTemp) 602 | return readLen-r1-gp.adaEdge; 603 | } 604 | return -1; 605 | } 606 | int hasContam(string& ref_sequence,string& contam,C_global_parameter& gp){ 607 | int readLen=ref_sequence.size(); 608 | int contamLen=contam.size(); 609 | if(contamLen==0){ 610 | return -1; 611 | } 612 | float misGrad = (contamLen-gp.adaEdge)/(gp.adaMis+1); 613 | int r1, mis, maxSegMatch; 614 | int segMatchThr = (int)ceil(contamLen * atof(gp.ctMatchR.c_str())); 615 | float segGrad(0); 616 | if(segMatchThr-7+1==0){ 617 | segGrad=0; 618 | }else{ 619 | segGrad = (contamLen-gp.adaEdge)/(segMatchThr-7+1); 620 | } 621 | int misMatchTemp, segMatchTemp; 622 | for (r1 = 0; r1 < contamLen - gp.adaEdge; ++r1) 623 | { 624 | mis = 0; 625 | maxSegMatch = 0; 626 | misMatchTemp = r1/misGrad; 627 | if(segGrad!=0){ 628 | segMatchTemp = 7 + r1/segGrad; 629 | }else{ 630 | segMatchTemp=7; 631 | } 632 | 633 | 634 | for (int c = 0; c < r1+gp.adaEdge; ++c) 635 | { 636 | if (contam[contamLen-r1-gp.adaEdge+c] == ref_sequence[c]){ 637 | maxSegMatch++; 638 | if (maxSegMatch >= segMatchTemp) 639 | return 0; 640 | } 641 | else{ 642 | if (ref_sequence[c] != 'N'){ 643 | mis++; 644 | maxSegMatch = 0; 645 | if (mis > misMatchTemp) 646 | break; 647 | } 648 | } 649 | } 650 | if (mis <= misMatchTemp) 651 | return 0; 652 | } 653 | 654 | for (r1 = 0; r1 <= readLen - contamLen; ++r1) 655 | { 656 | maxSegMatch = 0; 657 | mis = 0; 658 | 659 | for (int c = 0; c < contamLen; ++c) 660 | { 661 | if (contam[c] == ref_sequence[r1 + c]){ 662 | maxSegMatch ++; 663 | if (maxSegMatch >= segMatchThr) 664 | return r1; 665 | } 666 | else{ 667 | if (ref_sequence[r1 + c] != 'N'){ 668 | mis++; 669 | maxSegMatch = 0; 670 | if (mis > gp.adaMis) 671 | break; 672 | } 673 | } 674 | } 675 | if (mis <= gp.adaMis) 676 | return r1; 677 | } 678 | 679 | for (r1 = 0; r1 < contamLen - gp.adaEdge; ++r1) 680 | { 681 | mis = 0; 682 | maxSegMatch = 0; 683 | misMatchTemp = r1/misGrad; 684 | segMatchTemp = 7 + r1/segGrad; 685 | 686 | for (int c = 0; c < r1+gp.adaEdge; ++c) 687 | { 688 | if (contam[c] == ref_sequence[readLen-r1-gp.adaEdge+c]){ 689 | maxSegMatch++; 690 | if (maxSegMatch >= segMatchTemp) 691 | return readLen-r1-gp.adaEdge; 692 | } 693 | else{ 694 | if (ref_sequence[readLen-r1-gp.adaEdge+c] != 'N'){ 695 | mis++; 696 | maxSegMatch = 0; 697 | if (mis > misMatchTemp) 698 | break; 699 | } 700 | } 701 | } 702 | if (mis <= misMatchTemp) 703 | return readLen-r1-gp.adaEdge; 704 | } 705 | return -1; 706 | } 707 | int adapter_pos(string& ref_sequence,string& adapter,C_global_parameter& gp){ 708 | int adptLen=adapter.size(); 709 | if(adptLen==0){ 710 | return -1; 711 | } 712 | int readLen=ref_sequence.size(); 713 | int minEdge5 = 5; 714 | float misGrad5 = (adptLen-minEdge5)/(gp.adaMis+1); 715 | float misGrad = (adptLen-gp.adaEdge)/(gp.adaMis+1); 716 | int r1, mis, maxSegMatch; 717 | int segMatchThr = (int)ceil(adptLen * gp.adaMR); 718 | int misMatchTemp; 719 | 720 | for (r1 = 1; r1 <= minEdge5; ++r1) 721 | { 722 | mis = 0; 723 | maxSegMatch = 0; 724 | misMatchTemp = (adptLen-r1)/misGrad5; 725 | 726 | for (int c = 0; c < adptLen-r1; ++c) 727 | { 728 | if (adapter[r1+c] == ref_sequence[c]){ 729 | maxSegMatch++; 730 | if (maxSegMatch >= segMatchThr) 731 | return 0; 732 | } 733 | else{ 734 | mis++; 735 | maxSegMatch = 0; 736 | if (mis > misMatchTemp) 737 | break; 738 | } 739 | } 740 | if (mis <= misMatchTemp) 741 | return 0; 742 | } 743 | for (r1 = 0; r1 <= readLen - adptLen; ++r1) 744 | { 745 | maxSegMatch = 0; 746 | mis = 0; 747 | 748 | for (int c = 0; c < adptLen; ++c) 749 | { 750 | if (adapter[c] == ref_sequence[r1 + c]){ 751 | maxSegMatch ++; 752 | if (maxSegMatch >= segMatchThr) 753 | return r1; 754 | } 755 | else{ 756 | mis++; 757 | maxSegMatch = 0; 758 | if (mis > gp.adaMis) 759 | break; 760 | } 761 | } 762 | if (mis <= gp.adaMis) 763 | return r1; 764 | } 765 | for (r1 = 0; r1 < adptLen - gp.adaEdge; ++r1) 766 | { 767 | mis = 0; 768 | maxSegMatch = 0; 769 | misMatchTemp = r1/misGrad; 770 | 771 | for (int c = 0; c < r1+gp.adaEdge; ++c) 772 | { 773 | if (adapter[c] == ref_sequence[readLen-r1-gp.adaEdge+c]){ 774 | maxSegMatch++; 775 | if (maxSegMatch >= segMatchThr) 776 | return readLen-r1-gp.adaEdge; 777 | } 778 | else{ 779 | mis++; 780 | maxSegMatch = 0; 781 | if (mis > misMatchTemp) 782 | break; 783 | } 784 | } 785 | 786 | if (mis <= misMatchTemp) 787 | return readLen-r1-gp.adaEdge; 788 | } 789 | return -1; 790 | } 791 | int sRNA_findAdapter(string sequence,string adapter,C_global_parameter& gp) 792 | { 793 | int startPos = -1; 794 | int readLen = sequence.size(); 795 | int adptLen = adapter.size(); 796 | if(adptLen==0){ 797 | return -1; 798 | } 799 | int a1 = 2; 800 | int r1 = 0; 801 | int len; 802 | int mis; 803 | bool flagType = false; 804 | int misTmp = 0; 805 | int totalMapTmp = 0; 806 | for (r1 = 0; r1 <= readLen - gp.adaRMa;) 807 | { 808 | int len1 = adptLen - a1; 809 | int len2 = readLen - r1; 810 | len = (len1 < len2) ? len1 : len2; 811 | mis = 0; 812 | int map[MAX_LENGTH]; 813 | map[0] = 0; 814 | int totalMap = 0; 815 | for (int c = 0; c < len; c++) 816 | { 817 | if (sequence[r1 + c] =='N'){ 818 | continue; 819 | } 820 | if (adapter[a1 + c] == sequence[r1 + c]) 821 | { 822 | map[mis]++; 823 | totalMap++; 824 | } 825 | else 826 | { 827 | mis++; 828 | map[mis] = 0; 829 | } 830 | } 831 | int misAndMap = mis + totalMap; 832 | float rate =1.0 * mis / totalMap; 833 | if (mis <= gp.adaRMm && misAndMap >= gp.adaRMa && rate <= gp.adaREr) 834 | { 835 | if(flagType) 836 | { 837 | if (mis <= misTmp && totalMap >= totalMapTmp) 838 | { 839 | startPos = r1; 840 | misTmp = mis; 841 | totalMapTmp = totalMap; 842 | } 843 | } 844 | else 845 | { 846 | startPos = r1; 847 | flagType = true; 848 | misTmp = mis; 849 | totalMapTmp = totalMap; 850 | } 851 | } 852 | if (a1 > 0) 853 | { 854 | a1--; 855 | } 856 | else 857 | { 858 | r1++; 859 | } 860 | } 861 | return startPos; 862 | } 863 | bool sRNA_hasAdapter(string sequence, string adapter,C_global_parameter& gp) 864 | { 865 | bool find = false; 866 | int readLen = sequence.size(); 867 | int adptLen = adapter.size(); 868 | if(adptLen==0){ 869 | return find; 870 | } 871 | int a1 = adptLen - gp.adaRCtg; 872 | int r1 = 0; 873 | int len; 874 | int mis; 875 | int readLenSmall = (readLen - gp.adaRCtg < 0) ? 0 : (readLen - gp.adaRCtg); 876 | for (r1 = 0; r1 <= readLenSmall;) 877 | { 878 | int len1 = adptLen - a1; 879 | int len2 = readLen - r1; 880 | len = (len1 < len2) ? len1 : len2; 881 | mis = 0; 882 | int map[MAX_LENGTH]; 883 | map[0] = 0; 884 | int totalMap=0; 885 | for (int c = 0; c < len; c++) 886 | { 887 | if (adapter[a1 + c] == sequence[r1 + c]) 888 | { 889 | map[mis]++; 890 | totalMap++; 891 | } 892 | else 893 | { 894 | mis++; 895 | map[mis] = 0; 896 | } 897 | } 898 | int max_map = 0; 899 | for (int c = 0; c <= mis; c++) 900 | { 901 | if (map[c] > max_map) 902 | { 903 | max_map = map[c]; 904 | } 905 | } 906 | if (mis <= 4 && (max_map >= gp.adaRCtg || readLen < 12) && (1.0 * totalMap / readLen >= gp.adaRAr || 1.0 * totalMap / adptLen >= gp.adaRAr)) 907 | { 908 | find = true; 909 | break; 910 | } 911 | /* if (max_map >= 15){ 912 | find = true; 913 | break; 914 | }*/ 915 | if (a1 > 0) 916 | { 917 | a1--; 918 | } 919 | else 920 | { 921 | r1++; 922 | } 923 | } 924 | 925 | return find; 926 | } 927 | vector hasGlobalContams(string& ref_sequence,C_global_parameter& gp){ 928 | vector return_poses; 929 | vector g_contams,g_mr,g_mm; 930 | line_split(gp.global_contams,',',g_contams); 931 | line_split(gp.g_mrs,',',g_mr); 932 | line_split(gp.g_mms,',',g_mm); 933 | if(g_contams.size()!=g_mr.size() || g_contams.size()!=g_mm.size()){ 934 | cerr<<"Error:the number of global contamination sequences should equal to that of related parameters"<=0){ 947 | if(reverse_pos>=0){ 948 | push_pos=pos=0 && push_pos=0;i--){ 975 | int j_max=cl-i>rl?rl:cl-i; 976 | for(int j=0;j!=j_max;j++){ 977 | if(ref_sequence[j]==global_contam[i+j]){ 978 | if(total_score>total_mismatch_score){ 979 | total_score+=match_score; 980 | overlap++; 981 | }else{ 982 | if(j_max-jtotal_mismatch_score){ 990 | total_score+=mismatch_score; 991 | overlap++; 992 | }else{ 993 | if(j_max-j=lower_score && overlap>=min_match_len){ 999 | return 0; 1000 | } 1001 | } 1002 | } 1003 | //contam sequence is at middle of read sequence 1004 | total_score=-1000; 1005 | overlap=0; 1006 | for(int i=0;i<=rl-cl;i++){ 1007 | for(int j=0;j!=cl;j++){ 1008 | if(ref_sequence[i+j]==global_contam[j]){ 1009 | if(total_score>total_mismatch_score){ 1010 | total_score+=match_score; 1011 | overlap++; 1012 | }else{ 1013 | if(cl-jtotal_mismatch_score){ 1021 | total_score+=mismatch_score; 1022 | overlap++; 1023 | }else{ 1024 | if(cl-j=lower_score && overlap>=min_match_len){ 1030 | return i+j-overlap+1; 1031 | } 1032 | } 1033 | } 1034 | //contam sequence is at tail of read sequence 1035 | total_score=-1000; 1036 | overlap=0; 1037 | int i_min=cl>rl?cl-rl:0; 1038 | for(int i=i_min;i<=cl-min_match_len;i++){ 1039 | for(int j=0;j!=cl-i;j++){ 1040 | if(ref_sequence[rl-(cl-i)+j]==global_contam[j]){ 1041 | if(total_score>total_mismatch_score){ 1042 | total_score+=match_score; 1043 | overlap++; 1044 | }else{ 1045 | total_score=match_score; 1046 | overlap=1; 1047 | if(cl-i-jtotal_mismatch_score){ 1053 | total_score+=mismatch_score; 1054 | overlap++; 1055 | }else{ 1056 | if(cl-i-j=lower_score && overlap>=min_match_len){ 1062 | return rl-cl+i+j-overlap+1; 1063 | } 1064 | } 1065 | } 1066 | return -1; 1067 | } 1068 | 1069 | string reversecomplementary(string& a){ //get reverse complementary sequence 1070 | string b; 1071 | map dna_base_pair; 1072 | dna_base_pair['A']='T'; 1073 | dna_base_pair['T']='A'; 1074 | dna_base_pair['G']='C'; 1075 | dna_base_pair['C']='G'; 1076 | for(string::reverse_iterator ix=a.rbegin();ix!=a.rend();ix++){ 1077 | char tmp_base=toupper(*ix); 1078 | if(tmp_base=='N'){ 1079 | b.insert(b.end(),tmp_base); 1080 | }else if(dna_base_pair.find(tmp_base)==dna_base_pair.end()){ 1081 | cerr<<"Error:unrecognized base,"< 5 | #include 6 | #include 7 | #include "process_argv.h" 8 | #include "sequence.h" 9 | #include "global_parameter.h" 10 | using namespace::std; 11 | 12 | 13 | bool check_tile_or_fov(string tile,string& tile_parameter); 14 | string reversecomplementary(string& a); 15 | C_fastq_stat_result stat_read(C_fastq& fq_read,C_global_parameter& gp); 16 | bool whether_over_overlapped(C_fastq fastq1,C_fastq fastq2,C_global_parameter& gp); 17 | void fastq_trim(C_fastq& read,C_global_parameter& gp); 18 | int polyG_number(string& ref_sequence); 19 | int adapter_pos(string& ref_sequence,string& adapter,C_global_parameter& gp); 20 | int hasContam(string& ref_sequence,string& contam,C_global_parameter& gp); 21 | int hasContam(string& ref_sequence,string& contam,C_global_parameter& gp,float mr); 22 | vector hasContams(string& ref_sequence,string& contam,C_global_parameter& gp); 23 | int sRNA_findAdapter(string sequence,string adapter,C_global_parameter& gp); 24 | bool sRNA_hasAdapter(string sequence, string adapter,C_global_parameter& gp); 25 | int global_contam_pos(string& ref_sequence,string& global_contam,float min_matchRatio,int mismatch_number); 26 | vector hasGlobalContams(string& ref_sequence,C_global_parameter& gp); 27 | #endif -------------------------------------------------------------------------------- /src/rmdup.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by berry on 2020-10-20. 3 | // 4 | 5 | 6 | #include "rmdup.h" 7 | 8 | 9 | rmdup::rmdup(uint64_t* data, uint64_t size) { 10 | this->data=data; 11 | this->size=size; 12 | } 13 | 14 | void rmdup::markDup(bool *dupFlag) { 15 | uint32_t prime=getPrime(); 16 | // cout< tmpset; 20 | uint32_t contentSize=0; 21 | uint32_t multisize=0; 22 | // vector dupIdx,dupIdx2; 23 | // unordered_set tmpset2,dupset; 24 | for(uint64_t i=0;i1) 46 | { 47 | multiIdx[i]=tmpIter; 48 | tmpIter++; 49 | contentSize++; 50 | multisize+=count[i]; 51 | } 52 | } 53 | // cout<1) 60 | { 61 | dataContent[contentIdx]=new uint64_t[count[i]]; 62 | contentIdx++; 63 | } 64 | } 65 | // cout<1) 78 | { 79 | if(multiIdx[idx]>=contentSize) 80 | { 81 | cerr<<"Error:code error"< exists; 89 | // string curStr; 90 | for(uint32_t j=0;j 1) { 112 | if (multiIdx[idx] >= contentSize) { 113 | cerr << "Error:code error" << endl; 114 | exit(1); 115 | } 116 | if (dataContent[multiIdx[idx]][curCount[multiIdx[idx]]] == -1) { 117 | dupFlag[i]=true; 118 | // dupIdx2.push_back(i); 119 | iter++; 120 | } 121 | curCount[multiIdx[idx]]++; 122 | } 123 | } 124 | // cout<::iterator ix=dupIdx.begin();ix!=dupIdx.end();ix++){ 126 | // cout<<*ix<1) 132 | { 133 | if(dataContent[multiIdx[idx]]!=NULL) 134 | { 135 | // for(uint32_t j=0;jpow(2,32)-1?pow(2,32)-1:size; 153 | uint32_t prime=0; 154 | if(size>0&&size<10) 155 | { 156 | return size; 157 | } 158 | // float low=(float)49/50; 159 | // float high=1; 160 | uint32_t curNum=realSize; 161 | while(curNum--) 162 | { 163 | bool isPrime=true; 164 | for(uint32_t j=2;j<=sqrt(curNum);j++) 165 | { 166 | if(curNum%j==0) 167 | { 168 | isPrime=false; 169 | break; 170 | } 171 | } 172 | if(isPrime) 173 | { 174 | prime=curNum; 175 | break; 176 | } 177 | if(prime>0) 178 | { 179 | break; 180 | } 181 | } 182 | if(prime<=0) 183 | { 184 | cerr<<"Error:code error, please contact with "< 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "gc.h" 15 | using namespace::std; 16 | #define AUTHOREMAIL "gongchun@genomics.cn" 17 | class rmdup { 18 | private: 19 | uint64_t* data; 20 | uint64_t size; 21 | uint32_t getPrime(); 22 | public: 23 | rmdup(uint64_t* data,uint64_t size); 24 | ~rmdup(); 25 | void markDup(bool* dupFlag); 26 | uint64_t getlong(unsigned char* str); 27 | string md52string(unsigned char* str); 28 | }; 29 | 30 | 31 | #endif //SOAPNUKE_RMDUP_H 32 | -------------------------------------------------------------------------------- /src/seprocess.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEPROCESS_H 2 | #define _SEPROCESS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "process_argv.h" 11 | #include "global_parameter.h" 12 | #include "global_variable.h" 13 | #include "sequence.h" 14 | #include "BloomFilter.h" 15 | #include 16 | #include 17 | #include "rmdup.h" 18 | 19 | #define max_thread 72 20 | #define RMDUP 2 21 | struct SEstatOption 22 | { 23 | vector* fq1s; 24 | C_fastq_file_stat* stat1; 25 | }; 26 | struct SEcalOption 27 | { 28 | C_filter_stat* se_local_fs; 29 | vector* fq1s; 30 | vector *trim_result1,*clean_result1; 31 | }; 32 | class seProcess{ 33 | public: 34 | explicit seProcess(C_global_parameter m_gp); 35 | void process(); 36 | void print_stat(); 37 | void update_stat(C_fastq_file_stat& fq1s_stat,C_filter_stat& fs_stat,string type); 38 | void* stat_se_fqs(SEstatOption opt,string dataType); 39 | //void add_raw_trim(C_fastq_file_stat& a,C_reads_trim_stat& b); 40 | void filter_se_fqs(SEcalOption opt); 41 | void* sub_thread(int index); 42 | int read(vector& se1,ifstream& infile1); 43 | void seWrite(vector& se1,gzFile out1); 44 | void seWrite(vector& se1,FILE* out1); 45 | //void peRead(); 46 | void preOutput(int type,C_fastq& a); 47 | void output_fastqs(string type,vector &fq1,gzFile outfile); 48 | void output_fastqs(string type,vector &fq1,FILE* outfile); 49 | void merge_stat(); 50 | void C_fastq_init(C_fastq& a); 51 | void seStreaming_stat(C_global_variable& local_gv); 52 | void remove_tmpDir(); 53 | void make_tmpDir(); 54 | void thread_process_reads(int index,int& cycle,vector &fq1s); 55 | void create_thread_read(int index); 56 | void run_extract_random(); 57 | void limit_process_reads(int index,vector &fq1s,gzFile gzfq1); 58 | void check_disk_available(); 59 | void catRmFile(int index,int cycle,string type,bool gzFormat); 60 | void catRmFile(vector indexes,int cycle,string type,bool gzFormat); 61 | void* smallFilesProcess(); 62 | 63 | void create_thread_smalltrimoutputFile( 64 | int index 65 | , int cycle); 66 | 67 | void create_thread_smallcleanoutputFile( 68 | int index 69 | , int cycle); 70 | 71 | void closeSmallTrimFileHandle(int index); 72 | 73 | void closeSmallCleanFileHandle(int index); 74 | 75 | void run_cmd(string cmd); 76 | 77 | void *sub_extract( 78 | string in 79 | , int mo 80 | , string out); 81 | 82 | void rmTmpFiles(); 83 | 84 | void extractReadsToFile( 85 | int cycle 86 | , int thread_index 87 | , int reads_number 88 | , string position 89 | , int &output_index 90 | , bool gzFormat); 91 | 92 | void extractReadsToFile( 93 | int cycle 94 | , int thread_index 95 | , int reads_number 96 | , string position 97 | , bool gzFormat); 98 | 99 | void addCleanList( 100 | int tmp_cycle 101 | , int index); 102 | 103 | void *sub_thread_rmdup_step1(int index); 104 | 105 | void filter_se_fqs( 106 | SEcalOption opt 107 | , int index); 108 | 109 | int 110 | dupNum; 111 | mutex 112 | checkDup; 113 | BloomFilter 114 | *dupDB; 115 | gzFile 116 | dupOut1; 117 | gzFile 118 | *dupThreadOut1; 119 | set 120 | checkDupMap; 121 | mutex 122 | logLock; 123 | //void peOutput(outputOption opt); 124 | public: 125 | C_global_parameter 126 | gp; 127 | C_global_variable 128 | gv; 129 | gzFile 130 | *gz_trim_out1; 131 | gzFile 132 | *gz_clean_out1; 133 | FILE 134 | **nongz_clean_out1; 135 | FILE 136 | **nongz_trim_out1; 137 | ofstream of_log; 138 | string tmp_dir; 139 | gzFile* multi_gzfq1; 140 | FILE** multi_Nongzfq1; 141 | 142 | mutex 143 | se_stat_m, 144 | se_write_m; 145 | C_filter_stat 146 | *se_local_fs; 147 | C_fastq_file_stat 148 | *se_local_raw_stat1, 149 | *se_local_trim_stat1, 150 | *se_local_clean_stat1; 151 | int 152 | se_bq_check; 153 | int 154 | cur_cat_cycle; //current cycle of cat small files 155 | vector 156 | *readyTrimFiles1, 157 | *readyCleanFiles1; //list of small files in threads 158 | vector 159 | *clean_file_readsNum; //reads number of small files in threads 160 | int 161 | *sub_thread_done; 162 | int 163 | end_sub_thread; 164 | int 165 | patch; 166 | uint64_t 167 | *threadReadsNum; 168 | uint64_t 169 | *totalData; 170 | uint64_t 171 | *threadCurReadReadsNumIdx; 172 | vector > 173 | threadData; 174 | vector > 175 | threadDataNum; 176 | bool 177 | *dupFlag; 178 | private: 179 | vector 180 | fq1s; 181 | vector 182 | trim_output_fq1; 183 | vector 184 | clean_output_fq1; 185 | 186 | //C_fastq fastq1; 187 | int 188 | used_threads_num; 189 | string 190 | random_num; 191 | }; 192 | #endif -------------------------------------------------------------------------------- /src/sequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "sequence.h" 8 | #include "global_parameter.h" 9 | #include "read_filter.h" 10 | using namespace::std; 11 | 12 | C_single_fastq_filter::C_single_fastq_filter(C_fastq& a,C_global_parameter& gp){ 13 | read=a; 14 | read_result=stat_read(read,gp); 15 | } 16 | void C_single_fastq_filter::se_trim(C_global_parameter& gp){ 17 | fastq_trim(read,gp); 18 | } 19 | int C_single_fastq_filter::sRNA_discard(C_filter_stat* fs,C_global_parameter& gp){ 20 | int min_value=-1; 21 | if(gp.max_read_length!=-1){ 22 | if(read.sequence.size()>gp.max_read_length){ 23 | fs->long_len_num++; 24 | min_value=1; 25 | return min_value; 26 | //cout<<"max_read_length discard"<=gp.lowQualityBaseRatio){ //check low base quality ratio whether is too high 31 | fs->low_qual_base_ratio_num++; 32 | min_value=1; 33 | return min_value; 34 | //cout<<"low_qual_base_ratio discard"<no_3_adapter_num++; 39 | min_value=1; 40 | return min_value; 41 | }else if(read_result.include_3_adapter<=2){ 42 | fs->int_insertNull_num++; 43 | min_value=1; 44 | return min_value; 45 | } 46 | if(read_result.include_5_adapter){ 47 | fs->include_adapter_seq_num++; 48 | min_value=1; 49 | return min_value; 50 | } 51 | if(gp.highA_ratio!=-1){ 52 | if(read_result.a_ratio>=gp.highA_ratio){ //check highA ratio whether is too high 53 | fs->highA_num++; 54 | min_value=1; 55 | return min_value; 56 | //cout<<"highA_ratio discard"<=gp.polyX_num){ //check polyX ratio whether is too high 62 | fs->polyX_num++; 63 | min_value=1; 64 | return min_value; 65 | //cout<<"polyX_num discard"<short_len_num++; 70 | min_value=1; 71 | return min_value; 72 | //cout<<"min_read_length discard"<dupReadsNum++; 81 | return 1; 82 | } 83 | } 84 | if(!gp.tile.empty()){ //check read tile whether in the given removal tile list 85 | if(check_tile_or_fov(read_result.read_tile,gp.tile)){ 86 | fs->tile_num++; 87 | min_value=1; 88 | return min_value; 89 | } 90 | } 91 | 92 | if(!gp.fov.empty()){ //check read fov whether in the given removal fov list 93 | if(check_tile_or_fov(read_result.read_fov,gp.fov)){ 94 | fs->fov_num++; 95 | min_value=1; 96 | return min_value; 97 | } 98 | } 99 | 100 | if(gp.min_read_length!=-1){ 101 | if(read.sequence.size()short_len_num++; 103 | min_value=1; 104 | return min_value; 105 | //cout<<"min_read_length discard"<gp.max_read_length){ 110 | fs->long_len_num++; 111 | min_value=1; 112 | return min_value; 113 | //cout<<"max_read_length discard"<include_contam_seq_num++; 119 | min_value=1; 120 | return min_value; 121 | } 122 | if(read_result.include_global_contam==1){ 123 | fs->include_global_contam_seq_num++; 124 | min_value=1; 125 | return min_value; 126 | } 127 | } 128 | if(gp.n_ratio!=-1){ 129 | if(read_result.n_ratio>=gp.n_ratio){ //check N base ratio whether is too high 130 | fs->n_ratio_num++; 131 | min_value=1; 132 | return min_value; 133 | //cout<<"n_ratio discard"<=gp.highA_ratio){ //check highA ratio whether is too high 139 | fs->highA_num++; 140 | min_value=1; 141 | return min_value; 142 | //cout<<"highA_ratio discard"<=gp.polyX_num){ //check polyX ratio whether is too high 147 | fs->polyX_num++; 148 | min_value=1; 149 | return min_value; 150 | //cout<<"polyX_num discard"<=gp.lowQualityBaseRatio){ //check low base quality ratio whether is too high 156 | fs->low_qual_base_ratio_num++; 157 | min_value=1; 158 | return min_value; 159 | //cout<<"low_qual_base_ratio discard"<mean_quality_num++; 166 | min_value=1; 167 | return min_value; 168 | //cout<<"mean_quality discard"<include_adapter_seq_num++; 173 | min_value=1; 174 | return min_value; 175 | //cout<<"include_adapter_seq discard"<dupReadsNum++; 203 | return 1; 204 | } 205 | } 206 | if(gp.module_name=="filterStLFR"){ 207 | string barcode=getStLFRbarcode(); 208 | if(barcode!="0_0_0"){ 209 | fs->readsNumWithstLFRbarcode++; 210 | fs->stLFRbarcodeNum.insert(barcode); 211 | } 212 | } 213 | if(!gp.tile.empty()){ //check read tile whether in the given removal tile list 214 | if(check_tile_or_fov(reads_result.fastq1_result.read_tile,gp.tile)){ 215 | fs->tile_num++; 216 | min_value=1; 217 | return min_value; 218 | //cout<<"tile discard"<fov_num++; 227 | min_value=1; 228 | return min_value; 229 | } 230 | } 231 | 232 | if(gp.min_read_length!=-1){ 233 | int v=pe_dis(fq1.sequence.size()0){ 235 | switch(v){ 236 | case 1:fs->short_len_num1++;break; 237 | case 2:fs->short_len_num2++;break; 238 | case 3:fs->short_len_num1++;fs->short_len_num2++;fs->short_len_num_overlap++;break; 239 | default:break; 240 | } 241 | fs->short_len_num++; 242 | return 1; 243 | } 244 | //cout<<"min_read_length discard"<gp.max_read_length,fq2.sequence.size()>gp.max_read_length); 252 | if(v>0){ 253 | switch(v){ 254 | case 1:fs->long_len_num1++;break; 255 | case 2:fs->long_len_num2++;break; 256 | case 3:fs->long_len_num1++;fs->long_len_num2++;fs->long_len_num_overlap++;break; 257 | default:break; 258 | } 259 | fs->long_len_num++; 260 | return 1; 261 | } 262 | //cout<<"max_read_length discard"<0){ 267 | switch(v){ 268 | case 1:fs->include_global_contam_seq_num1++;break; 269 | case 2:fs->include_global_contam_seq_num2++;break; 270 | case 3:fs->include_global_contam_seq_num1++;fs->include_global_contam_seq_num2++;fs->include_global_contam_seq_num_overlap++;break; 271 | default:break; 272 | } 273 | fs->include_global_contam_seq_num++; 274 | return 1; 275 | } 276 | } 277 | if(gp.contam_discard_or_trim=="discard"){ 278 | int v=pe_dis(reads_result.fastq1_result.include_contam==1,reads_result.fastq2_result.include_contam==1); 279 | if(v>0){ 280 | 281 | switch(v){ 282 | case 1:fs->include_contam_seq_num1++;break; 283 | case 2:fs->include_contam_seq_num2++;break; 284 | case 3:fs->include_contam_seq_num1++;fs->include_contam_seq_num2++;fs->include_contam_seq_num_overlap++;break; 285 | default:break; 286 | } 287 | fs->include_contam_seq_num++; 288 | return 1; 289 | } 290 | } 291 | if(gp.n_ratio!=-1){ 292 | int v=pe_dis(reads_result.fastq1_result.n_ratio>=gp.n_ratio,reads_result.fastq2_result.n_ratio>=gp.n_ratio); //check N base ratio whether is too high 293 | if(v>0){ 294 | switch(v){ 295 | case 1:fs->n_ratio_num1++;break; 296 | case 2:fs->n_ratio_num2++;break; 297 | case 3:fs->n_ratio_num1++;fs->n_ratio_num2++;fs->n_ratio_num_overlap++;break; 298 | default:break; 299 | } 300 | fs->n_ratio_num++; 301 | return 1; 302 | } 303 | } 304 | //cout<<"a_ratio\t"<=gp.highA_ratio,reads_result.fastq2_result.a_ratio>=gp.highA_ratio); //check highA ratio whether is too high 307 | if(v>0){ 308 | switch(v){ 309 | case 1:fs->highA_num1++;break; 310 | case 2:fs->highA_num2++;break; 311 | case 3:fs->highA_num1++;fs->highA_num2++;fs->highA_num_overlap++;break; 312 | default:break; 313 | } 314 | fs->highA_num++; 315 | return 1; 316 | } 317 | } 318 | if(gp.polyX_num!=-1){ 319 | int v=pe_dis(reads_result.fastq1_result.contig_base>=gp.polyX_num,reads_result.fastq2_result.contig_base>=gp.polyX_num); //check polyX ratio whether is too high 320 | if(v>0){ 321 | switch(v){ 322 | case 1:fs->polyX_num1++;break; 323 | case 2:fs->polyX_num2++;break; 324 | case 3:fs->polyX_num1++;fs->polyX_num2++;fs->polyX_num_overlap++;break; 325 | default:break; 326 | } 327 | fs->polyX_num++; 328 | return 1; 329 | } 330 | } 331 | //cout<<"lbq\t"<=gp.lowQualityBaseRatio,reads_result.fastq2_result.low_qual_base_ratio>=gp.lowQualityBaseRatio); //check low base quality ratio whether is too high 334 | if(v>0){ 335 | if(reads_result.fastq1_result.low_qual_base_ratio>1 || reads_result.fastq2_result.low_qual_base_ratio>1){ 336 | cerr<<"Error:low quality base ratio stat error,"<low_qual_base_ratio_num1++;break; 342 | case 2:fs->low_qual_base_ratio_num2++;break; 343 | case 3:fs->low_qual_base_ratio_num1++;fs->low_qual_base_ratio_num2++;fs->low_qual_base_ratio_num_overlap++;break; 344 | default:break; 345 | } 346 | fs->low_qual_base_ratio_num++; 347 | return 1; 348 | } 349 | } 350 | //cout<<"mq\t"<0){ 354 | switch(v){ 355 | case 1:fs->mean_quality_num1++;break; 356 | case 2:fs->mean_quality_num2++;break; 357 | case 3:fs->mean_quality_num1++;fs->mean_quality_num2++;fs->mean_quality_num_overlap++;break; 358 | default:break; 359 | } 360 | fs->mean_quality_num++; 361 | return 1; 362 | } 363 | } 364 | if(gp.overlap_length!=-1){ 365 | if(reads_result.over_lapped){ 366 | fs->over_lapped_num++; 367 | min_value=1; 368 | return min_value; 369 | //cout<<"over_lapped discard"<0){ 375 | switch(v){ 376 | case 1:fs->include_adapter_seq_num1++;break; 377 | case 2:fs->include_adapter_seq_num2++;break; 378 | case 3:fs->include_adapter_seq_num1++;fs->include_adapter_seq_num2++;fs->include_adapter_seq_num_overlap++;break; 379 | default:break; 380 | } 381 | fs->include_adapter_seq_num++; 382 | return 1; 383 | } 384 | } 385 | 386 | return min_value; 387 | } 388 | void C_pe_fastq_filter::pe_trim(C_global_parameter& gp){ 389 | fastq_trim(fq1,gp); 390 | fastq_trim(fq2,gp); 391 | } 392 | int C_pe_fastq_filter::pe_dis(bool a,bool b){ 393 | int return_value=0; 394 | if(a) 395 | return_value+=1; 396 | if(b) 397 | return_value+=2; 398 | return return_value; 399 | } 400 | 401 | string C_fastq::toString() { 402 | string completeRead=seq_id+"\n"+sequence+"\n+\n"+qual_seq+"\n"; 403 | return completeRead; 404 | } -------------------------------------------------------------------------------- /src/sequence.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEQUENCE_H 2 | #define _SEQUENCE_H 3 | 4 | #include "global_parameter.h" 5 | #include "global_variable.h" 6 | #include "zlib.h" 7 | #include "process_argv.h" 8 | #include 9 | #include 10 | 11 | class C_sequence_stat_result{ //basic sequence stat information 12 | public: 13 | C_sequence_stat_result():seq_len(0),a_num(0),c_num(0),g_num(0),t_num(0),n_num(0),a_ratio(0),c_ratio(0),g_ratio(0),t_ratio(0),n_ratio(0),contig_base(0),gc_ratio(0){}; 14 | int seq_len; 15 | int a_num,c_num,g_num,t_num,n_num; 16 | float a_ratio,c_ratio,g_ratio,t_ratio,n_ratio; 17 | int contig_base; 18 | float gc_ratio; 19 | }; 20 | class C_fastq_stat_result:public C_sequence_stat_result{ //fastq stat information 21 | public: 22 | C_fastq_stat_result():in_adapter_list(0),include_adapter_seq(-1),include_5_adapter(false),include_3_adapter(-1),include_contam(-1),include_global_contam(-1),qual_len(0),low_qual_base_num(0),low_qual_base_ratio(0),mean_quality(0),q20_num(0),q30_num(0),dup(false){}; 23 | bool in_adapter_list; 24 | int include_adapter_seq; 25 | bool include_5_adapter; //only used in sRNA 26 | int include_3_adapter; //only used in sRNA 27 | int include_contam,include_global_contam; 28 | string read_tile,read_fov; 29 | int qual_len; 30 | int low_qual_base_num; 31 | float low_qual_base_ratio; 32 | float mean_quality; 33 | int q20_num,q30_num; 34 | bool dup; 35 | }; 36 | class C_pe_fastq_stat_result{ //pe fastq stat information 37 | public: 38 | C_pe_fastq_stat_result():over_lapped(1),containStLFRbarcode(false),stLFRbarcode(""),dup(false){}; 39 | C_fastq_stat_result fastq1_result; 40 | C_fastq_stat_result fastq2_result; 41 | bool over_lapped; //pe fastq whether overlapped 42 | bool containStLFRbarcode; 43 | string stLFRbarcode; 44 | bool dup; 45 | }; 46 | 47 | class C_sequence{ //sequence 48 | public: 49 | //void output(); 50 | string sequence; 51 | }; 52 | 53 | class C_fasta:public C_sequence{ //fasta 54 | public: 55 | //void output(); 56 | string seq_name; 57 | }; 58 | 59 | class C_fastq:public C_sequence{ //fastq,include adapter seq and trim information 60 | public: 61 | string seq_id; 62 | string qual_seq; 63 | // string adapter_seq; 64 | // string adapter_seq2; 65 | // string contam_seq; 66 | //string global_contams; 67 | string adapter_orientation,adapter_orientation2; 68 | string head_trim_len,tail_trim_len; 69 | int head_hdcut,head_lqcut,tail_hdcut,tail_lqcut,adacut_pos; 70 | int contam_pos; 71 | int global_contam_5pos,global_contam_3pos; 72 | int raw_length; 73 | int pairPos; 74 | string toString(); 75 | }; 76 | class C_pe_fastq{ //pe fastq 77 | public: 78 | //void output(); 79 | C_fastq fastq1; 80 | C_fastq fastq2; 81 | }; 82 | class C_single_fastq_filter{ //SE fastq filter 83 | public: 84 | C_single_fastq_filter(C_fastq& a,C_global_parameter& gp); 85 | void se_trim(C_global_parameter& gp); 86 | int se_discard(C_filter_stat* fs,C_global_parameter& gp); 87 | int sRNA_discard(C_filter_stat* fs,C_global_parameter& gp); 88 | C_fastq read; 89 | C_fastq_stat_result read_result; 90 | }; 91 | class C_pe_fastq_filter{ //PE fastq filter 92 | public: 93 | C_pe_fastq_filter(C_fastq& a,C_fastq& b,C_global_parameter& gp); 94 | void pe_trim(C_global_parameter& gp); 95 | int pe_discard(C_filter_stat* fs,C_global_parameter& gp); 96 | int pe_dis(bool a,bool b); 97 | C_fastq fq1; 98 | C_fastq fq2; 99 | C_pe_fastq_stat_result reads_result; 100 | //added for stLFR module 101 | void setStLFRbarcode(string bcs){ 102 | reads_result.stLFRbarcode=bcs; 103 | } 104 | string getStLFRbarcode(){ 105 | return reads_result.stLFRbarcode; 106 | } 107 | }; 108 | class C_sRNA_fastq_filter:public C_single_fastq_filter{ //sRNA fastq filter 109 | public: 110 | C_sRNA_fastq_filter(C_fastq& a,C_global_parameter& gp); 111 | void sRNA_trim(C_global_parameter& gp); 112 | int sRNA_discard(C_filter_stat* fs,C_global_parameter& gp); 113 | }; 114 | 115 | 116 | 117 | #endif 118 | --------------------------------------------------------------------------------