├── .gitignore
├── LICENSE
├── README.md
├── bin
├── README.md
├── cellcomp
├── onecomp
├── reoa
├── reoa_linux64_gomp3
└── reoa_linux64_gomp4
├── src
├── Makefile
├── README.md
├── bino.h
├── binomial.c
├── cellcomp
├── fisher.c
├── hypergeom.c
├── main.c
├── main.h
├── onecomp
├── pcg_basic.c
├── pcg_basic.h
├── random_sample.c
├── reoa.c
├── reoa.h
├── stat.c
└── stat.h
└── test
├── README.md
├── cellcomp_case.dat
├── cellcomp_control.dat
├── onecomp_control.dat
└── onecomp_treated.dat
/.gitignore:
--------------------------------------------------------------------------------
1 | # Object files
2 | *.o
3 | *.ko
4 | *.obj
5 | *.elf
6 |
7 | # Precompiled Headers
8 | *.gch
9 | *.pch
10 |
11 | # Libraries
12 | *.lib
13 | *.a
14 | *.la
15 | *.lo
16 |
17 | # Shared objects (inc. Windows DLLs)
18 | *.dll
19 | *.so
20 | *.so.*
21 | *.dylib
22 |
23 | # Executables
24 | *.exe
25 | *.out
26 | *.app
27 | *.i*86
28 | *.x86_64
29 | *.hex
30 |
31 | # Debug files
32 | *.dSYM/
33 | *.su
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Update on Nov 12, 2022
2 | Users are advised to use the updated RankCompV3 algorithm (https://github.com/pathint/RankCompV3.jl) which is implemented with Julia.
3 |
4 | # Relative Expression Ordering Analysis (REOA) package
5 |
6 | This program implements the original RankComp and the RankCompV2 algorithms to detect the dysregulated genes. It is applicable to gene expression, methylation and other gene microarray data sets. Both large-scale cohort and individual samples or small-scale cell-line samples with two or three technical replicates can be analyzed.
7 |
8 |
9 |
10 | Besides the main program, `reoa`, this package also includes several derivative programs which apply the method to specific scenarios.
11 |
12 | 1. *CellComp*.
13 | The `cellcomp` program is applicable to small-scale cell-line data which include only a few (e.g. two or three) technical replicates. See [below](https://github.com/pathint/reoa#small-scale-cell-line-data-with-two-or-three-technical-replicates) for usage.
14 |
15 | 2. *OneComp*.
16 | The `onecomp` program is applicable to the datasets with only one case sample and possibly one control sample. See [below](https://github.com/pathint/reoa/blob/master/README.md#datasets-with-only-one-control-sample-and-one-case-sample) for usage.
17 |
18 |
19 | If you publish results from using this program, please cite the following publications.
20 |
21 | Xiangyu Li, Hao Cai, Xianlong Wang, Lu Ao, You Guo, Jun He, Yunyan Gu, Lishuang Qi, Qingzhou Guan, Xu Lin, Zheng Guo.
22 | A rank-based algorithm of differential expression analysis for small cell line data with statistical control.
23 | Briefings in Bioinformatics, Volume 20, Issue 2, March 2019, Pages 482–491, https://doi.org/10.1093/bib/bbx135.
24 |
25 | Hongwei Wang, Qiang Sun, Wenyuan Zhao, Lishuang Qi, Yunyan Gu, Pengfei Li, Mengmeng Zhang, Yang Li, Shu-Lin Liu, and Zheng Guo. (**2015**). Individual-level analysis of differential expression of genes and pathways for personalized medicine. *Bioinformatics*. 31(1):62-8. [DOI:10.1093/bioinformatics/btu522](http://dx.doi.org/10.1093/bioinformatics/btu522).
26 |
27 |
28 | ## Algorithm
29 |
30 | ### Significantly Stable Gene Pairs
31 | A pair of genes, {*a*, *b*}, is considered as statistically stable if they hold the same order relationship (*a* < *b* or *a* >*b*) in most of the samples. Binomial distribution is used to calculate the *P* value under the null hypothesis (a and b does not have a stable order relation) for the large-scale samples. The [Benjamini–Hochberg procedure](https://en.wikipedia.org/wiki/False_discovery_rate) is used to control the false discovery rate (FDR) at level alpha, which is 0.05 by default. For small-scale samples, such as technical replicates in the cell-line studies, the exception number is used to screen the stable pairs. For example, if the exception number is set as 0, the pair holds the same order relation in all the samples.
32 |
33 | *Note on Notation Abuse*: *a*, *b* are used to represent both genes and the expression values (or methylation level etc) of the genes. Readers should be able to discern what the notations represent with no trouble.
34 |
35 | ### Concordant and Reversal Gene Pairs
36 | If a pair of genes, {*a*, *b*}, is significantly stable in both the normal group and the disease group and the orders are the same (either *a* < *b* or *a* > *b*), the pair is a concordant pair. Likewise, if a pair is stable in both groups, but the orders are different (*a* < *b* in one group, but *a* > *b* in the other group), the pair is called reversal pair. Concordant and reversal gene pairs are the basic data to detect dysregulated genes.
37 |
38 |
39 | ### Dysregulated Genes, the RankCompV2 Algorithm
40 | Whether a gene is dysregulated or not in a disease cohort compared with normal cohort is identified through the original RankComp algorithm or through the improved RankCompV2 algorithm. Here is a brief description on the algorithms. Interested users are advised to read the related papers.
41 |
42 | All the tested genes are going to be classified into three possible regulation directions, up-regulated, down-regulated and non-dysregulated.
43 |
44 | For one gene, *a*, we count the numbers of genes whose expression (or methylation etc) levels are higher and lower than this gene in the normal cohort and in the disease cohort. The counting is carried out for the concordant and reversal gene pairs only. Thus, we obtain the following contingency table.
45 |
46 | Group | Number of genes whose expression levels are higher than *a* | Number of genes whose expression levels are less than *a*
47 | ---- | ------------ | -------------
48 | Normal | *n*g | *n*l
49 | Disease |*d*g | *d*l
50 |
51 | [Fisher exact test](https://en.wikipedia.org/wiki/Fisher's_exact_test) is then used to calculate the *P* value under the null hypothesis which states that the number of genes whose expression levels are higher or lower than the tested gene has no association with disease state (absence or presence). The [Benjamini–Hochberg procedure](https://en.wikipedia.org/wiki/False_discovery_rate) is used to control the false discovery rate (FDR) at level alpha, which is 0.05 by default. If the null hypothesis is rejected, the gene *a* is identified as a potential dysregulated gene (DEG). The dysregulation direction is judged by comparing *n*g / *n*l with *d*g / *d*l (equivalently, *n*g / (*n*g + *n*l) vs. *d*g / ( *d*g + *d*l)).
52 |
53 | The above describes the first step in both the algorithms. In this step, all the genes are considered as non-DEGs when the contingency table is constructed. After the gene states are assigned, we repeat the above steps to further filter potential DEGs. However, the counting to build the contingency tables does not include all stable pairs. Whether a stable pair, either concordant or reversal, is included depends on the dysregulation direction of the partner gene in the pair. For a stable pair {*a*, *b*}, only if gene *b* is assigned as non-dysregulated gene, the pair is counted for the construction of the contingency table of gene *a*. (Initially, all the genes are assumed to be non-dysregulated, that is to say all the stable pairs will be used to construct the table in the initial cycle.) After the contingency tables are renewed, Fisher exact test with FDR control are called for the null hypothesis test again. This iteration continues until the number of DEGs does not change significantly anymore.
54 |
55 | ### Dysregulated Genes, the original RankComp Algorithm
56 | In the original RankComp algorithm, the later iterations use a different strategy to renew the contingency tables. We redo the counting based on the reversal pairs only. For gene *a*, we count the number of genes whose expression level is greater than that of *a* in the normal group but becomes less than that of *a* in the disease group and the number of genes whose expression level is less than that of *a* in the normal group but becomes greater than that of *a* in the disease group. The numbers are labeled as *g2l* and *l2g*, respectively. For a reversal pair, *a* < *b* in the normal group and *a* > *b* in the disease group, if *a* is up-regulated, *a* will not be counted as *g2l* for *b* and if *b* is down-regulated, *b* is not counted as *l2g* for *a*. The recounted values *g2l* and *l2g*, and the values of *n*g and *n*l from the first step, are used to construct the above contingency tables. Fisher exact test is again used to identify the dysregulated genes.
57 |
58 | ## Usage
59 | The online help can be invoked by running the progrom with `-h` or `--help` option.
60 | ```
61 | reoa -h
62 | ```
63 | or
64 | ```
65 | reoa --help
66 | ```
67 | The input data sets should be given as text-based data matrix data files. One file contains the microarray value matrix of one group of samples. The number of rows corresponds to the total number of gene probes and the number of columns corresponds to the sample size. The values should be tab or space delimited. If multiple data sets are given as input, the number of genes should be the same.
68 |
69 | The output gene pairs or dysregulated genes are given by the indices (starting from 0) of the genes. If the verbose option (`-v` or `--verbose`) is turn on, extensive amount of output will be printed out. Please read the standard (screen) output for the names of the output files and the content format.
70 |
71 | The most important option is `-j` (`--job`) which sets up the job type. Job types 0-2 identify stable gene pairs and dysregulated genes. Job types 3-4 generate simulation data sets and identify dysregulated genes in the simulated data sets. Job types 5-6 calculate the concordance scores between two samples in one data set.
72 |
73 | For most of job types, multiple data sets can be given. Three comparison modes are avaiable for selecting stable pairs and identifying dysregulated genes and related jobs. The choice can be made through the `-p` (`--pair`) option.
74 |
75 | The choice of algorithm is specified by the `-a` (`--algorithm`) option.
76 |
77 | For the small-scale samples, such as cell line technical replicates, exception numbers should be used to select stable pairs instead of FDR levels. And the exception number is usually set as 0. Furthermore, the option of `-q` (`--equals`) should be set as 0 as well.
78 |
79 | The default sample type is 'cohort'. For individual-type samples, the option `-s` (`--sample`) should be set as 1. Each sample (column) in a data set is analyzed separately.
80 |
81 | See the folder `test` for test cases.
82 |
83 | ## Application Scenarios
84 |
85 | ### Small-Scale Cell Line Data with Two or Three Technical Replicates
86 | For the small-scale cell line expriments with only a few (e.g. two or three) technical replicates, please use the program `cellcomp` to detect differentially expressed genes (DEGs).
87 |
88 | Example. (The sample expression files are available under the `test` folder.)
89 | ```
90 | cellcomp cellcomp_control.dat cellcomp_case.dat
91 | ```
92 | Detailed usage information for `cellcomp` is as follows.
93 |
94 | #### NAME
95 | cellcomp, a bash script driver for application of reoa
96 | to small-scale data set with only a few technical replicates
97 | #### SYNOPSIS
98 | cellcomp [-h|-V]
99 | cellcomp [OPTIONS] control_file case_file
100 | #### DESCRIPTION
101 | CellComp (cellcomp) is a program to apply the RanComp and
102 | RankCompV2 algorithms to detect differentially expressed
103 | genes (DEGs) in small-scale cell line experiments. In such
104 | experiments, the gene expression profiles contain only two
105 | or three technical replicates and most conventional methods
106 | lack statistical power when applied to such small-scale data
107 | sets. The RankComp and RanCompV2 are based on the analysis of
108 | within-sample relative expression orderings (REOs) of gene pairs.
109 | See the references more details.
110 | #### OPTIONS
111 | -h, --help, --usage
112 | Show this message
113 | -V, --version
114 | Show program version
115 | -a, --algorithm = ALGORITHM
116 | Choice of algorithm. Default: 0
117 | 0 - RankCompV2 only
118 | 1 - Original RankComp only
119 | 2 - Both RankComp and RankCompV2
120 | -f, --fdr = FDR
121 | False discovery rate (FDR) level. Default: 0.05
122 | -c, --cycles = CYCLES
123 | Maximum iteration cycles. Default: 128
124 | -t, --threshold = THRESHOLD
125 | Convergence criterion. Default: 50
126 | (Maximum fluctuation in number of DEGs)
127 | -v, --verbose
128 | Output extra information
129 |
130 | ### Datasets with Only One Control Sample and One Case Sample
131 | Under this application scenario, background gene pairs, which show stable REOs in many normal samples, must be obtained before-hand. This can be achieved by applying `reoa` to the merged normal samples of a particular tissue or a cell line from the same or different data sources. The program `onecomp` first customizes the background gene pairs by filtering out those pairs with reversed REOs in the control sample(s) of the current dataset, then detects the DEGs in a case sample with the filtered background gene pairs.
132 |
133 | #### NAME
134 | onecomp, a bash script driver for application of reoa
135 | to detect dysregulated genes in one treated sample
136 | given a list of stable gene pairs and one paired control
137 | sample.
138 |
139 | #### SYNOPSIS
140 | onecomp [-h|-V]
141 | onecomp [OPTIONS] pair_file control_file treated_file
142 |
143 | #### DESCRIPTION
144 | OneComp (onecomp) is a program to apply the original RankComp
145 | and RankCompV2 algorithms to detect differentially expressed
146 | genes (DEGs) in one treated sample given the paired control
147 | sample and a list of predetermined gene pairs with stable REOs.
148 | The control sample is used to customize the gene pair list
149 | and 'paired' here does not necessarily mean the expermental
150 | design but a compatiable corresponding relation between the two.
151 | The 'control_file' and 'treated_file contains the expression
152 | profiles of a group of control samples and a group of treated
153 | samples. They should have the same number of rows (gene probes)
154 | and the same number of columns (number of samples). The i-th
155 | column of 'control_file' and the i-th column of 'treated_file'
156 | constitue one paired sample and they are processed by the algo.
157 | independent of the other columns.
158 | The pair_file contains the list of predetermined gene pairs which
159 | are given by the gene probe indices (0-based) which have the same
160 | order as the expression files (control_file or treated_file).
161 | The RankComp and RanCompV2 are based on the analysis of
162 | within-sample relative expression orderings (REOs) of gene pairs.
163 | See the references more details.
164 |
165 | #### OPTIONS
166 | -h, --help, --usage
167 | Show this message
168 | -V, --version
169 | Show program version
170 | -a, --algorithm = VALUE
171 | Choice of algorithm. Default: 0
172 | 0 - RankCompV2 only
173 | 1 - Original RankComp only
174 | 2 - Both RankComp and RankCompV2
175 | -m, --mode = VALUE
176 | Choice of filter mode. Default: 0
177 | 0 - Use one control sample to filter the pairs to detect DEGs
178 | in the corresponding treated sample
179 | 1 - Use all the control samples to filter the pairs to detect
180 | DEGs in each treated samples
181 | -f, --fdr = FDR
182 | False discovery rate (FDR) level. Default: 0.05
183 | -c, --cycles = CYCLES
184 | Maximum iteration cycles. Default: 128
185 | -t, --threshold = THRESHOLD
186 | Convergence criterion. Default: 50
187 | (Maximum fluctuation in number of DEGs)
188 | -v, --verbose
189 | Output extra information
190 |
191 |
192 |
193 | ## Install
194 | There are two possible ways to install the program.
195 |
196 | 1. *Install from the Precompiled Execulables*.
197 | Just copy the binary file to the folder where the executables are located, such as `/usr/local/bin`, and rename the binary file as `reoa`. It is recommended to use `reoa_linux64_gomp4` which has the OpenMP 4.0 support. See `README.md` under `bin` for further details.
198 |
199 | 2. *Compile from the Source Files*.
200 | Under the `src` folder, run `make` command to compile the sources and run `make install` to install the executables. The latter operation may require adminstation privilege (aka. `root`). (If `make install` does not work, just copy the compiled `reoa` file and other executables to `/usr/local/bin` or other executable folder). If the compilation does not finish successfully, you may need to change the settings in `Makefile` manually. See `README.md` under `src` for further details.
201 |
202 | ## License
203 | This program is free software; it is released under the GNU GENERAL PUBLIC LICENSE Version 3.
204 |
205 | ## Contact Us
206 |
207 | If you would like to receive updates from us regarding bug fixes, patches, feature updates or if you would like to contact us, please write to [1353023@qq.com](1353023@qq.com) or contact us via QQ or WeChat: 1353023.
208 |
209 |
--------------------------------------------------------------------------------
/bin/README.md:
--------------------------------------------------------------------------------
1 | ## Install from the Binary Executables
2 |
3 | 1. Copy the executable (`reoa*`) file to the folder where your PATH can find, such as `/usr/local/bin/` and rename it as `reoa`. Copy the scripts (`cellcomp` and others) to the folder where your PATH can find.
4 | 2. Make sure the files have the executable permission. If it does not, use `chmod 755 reoa` to make the modification.
5 | 3. Try it! For example, running the following command will return the usage of the programs.
6 |
7 | ```
8 | cp reoa_linux64_gomp4 /usr/local/bin/reoa
9 | cp ../src/cellcomp /usr/local/bin/cellcomp
10 | reoa -h
11 | cellcomp -h
12 | onecomp -h
13 | ```
14 |
15 | ## About the Binary Files
16 | 1. `reoa_linux64_gomp3` is compiled with gcc-4.7.3 with OpenMP Application Program Interface v3.0 enabled.
17 | 2. `reoa_linux64_gomp4` is compiled with gcc-4.9.3 with OpenMP Application Program Interface v4.0 enabled. It requires the installation of OpenMP (`libgomp`) v4.0. The difference between the two is that the later has SIMD enabled.
18 | 3. `cellcomp` and `onecomp` are Bash scripts which call the `reoa` executable to do the actual calculations. The scripts require the presence of GNU `getopt` function.
19 |
20 |
--------------------------------------------------------------------------------
/bin/cellcomp:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ##############################
4 | # Xianlong Wang, Jan 17, 2017
5 | # Driver for REOA
6 | ##############################
7 |
8 | # Defaults
9 | # ALGORITHM, default RankCompV2
10 | ALGORITHM=0
11 | # FDR level, 5%
12 | FDR=0.05
13 | # CYCLES, maximum cycles for filtering
14 | CYCLES=128
15 | # THRESHOLD, convergence criterion
16 | THRESHOLD=50
17 | # VERBOSE output
18 | VERBOSE=NO
19 |
20 | pgm=reoa
21 | version="revison 0.1. 2017-01-17"
22 | if ! hash $pgm 2>/dev/null; then
23 | echo The main executable "$pgm" is not found. Please check \$PATH
24 | exit 1
25 | fi
26 |
27 | function usage
28 | {
29 | echo "NAME"
30 | echo " cellcomp, a bash script driver for application of $pgm"
31 | echo " to small-scale data set with only a few technical replicates"
32 | echo "SYNOPSIS"
33 | echo " cellcomp [-h|-V]"
34 | echo " cellcomp [OPTIONS] control_file case_file"
35 | echo "DESCRIPTION"
36 | echo " CellComp (cellcomp) is a program to apply the RanComp and "
37 | echo " RankCompV2 algorithms to detect differentially expressed "
38 | echo " genes (DEGs) in small-scale cell line experiments. In such "
39 | echo " experiments, the gene expression profiles contain only two "
40 | echo " or three technical replicates and most conventional methods"
41 | echo " lack statistical power when applied to such small-scale data"
42 | echo " sets. The RankComp and RanCompV2 are based on the analysis of"
43 | echo " within-sample relative expression orderings (REOs) of gene pairs."
44 | echo " See the references more details."
45 | echo "OPTIONS"
46 | echo " -h, --help, --usage"
47 | echo " Show this message"
48 | echo " -V, --version"
49 | echo " Show program version"
50 | echo " -a, --algorithm = ALGORITHM"
51 | echo " Choice of algorithm. Default: 0"
52 | echo " 0 - RankCompV2 only"
53 | echo " 1 - Original RankComp only"
54 | echo " 2 - Both RankComp and RankCompV2"
55 | echo " -f, --fdr = FDR"
56 | echo " False discovery rate (FDR) level. Default: 0.05"
57 | echo " -c, --cycles = CYCLES"
58 | echo " Maximum iteration cycles. Default: 128"
59 | echo " -t, --threshold = THRESHOLD"
60 | echo " Convergence criterion. Default: 50 "
61 | echo " (Maximum fluctuation in number of DEGs)"
62 | echo " -v, --verbose"
63 | echo " Output extra information"
64 | echo
65 | }
66 |
67 | function eecho(){
68 | echo "# $*"
69 | }
70 |
71 | function get_row(){
72 | wc -l $1 |awk '{print $1}'
73 | }
74 |
75 | function get_col(){
76 | head -1 $1 | wc -w
77 | }
78 |
79 | # Parsing options
80 | # WARNING: option value is not validated.
81 | # NOTE: This requires GNU getopt.
82 | OPTIONS=`getopt -o a:f:c:t:vhV --long algorithm:,fdr:,cycles:,threshold:,verbose,help,usage,version -n "$pgm" -- "$@"`
83 | eval set -- "$OPTIONS"
84 |
85 | #while [[ $# -gt 1 ]]
86 | while true;
87 | do
88 | case "$1" in
89 | -h|--help|--usage)
90 | usage
91 | exit 0
92 | ;;
93 | -V|--version)
94 | echo $pgm $version
95 | exit 0
96 | ;;
97 | -a|--algorithm)
98 | ALGORITHM="$2"
99 | shift 2 # past argument
100 | ;;
101 | -f|--fdr)
102 | FDR="$2"
103 | shift 2 # past argument
104 | ;;
105 | -c|--cycles)
106 | CYCLES="$2"
107 | shift 2 # past argument
108 | ;;
109 | -t|--threshold)
110 | THRESHOLD="$2"
111 | shift 2 # past argument
112 | ;;
113 | -v|--verbose)
114 | VERBOSE=YES
115 | shift
116 | ;;
117 | -- )
118 | shift
119 | break
120 | ;;
121 | *)
122 | break
123 | ;;
124 | esac
125 | done
126 |
127 | if [ $# -lt 2 ]; then
128 | usage
129 | exit 1
130 | fi
131 |
132 | # check input files
133 | file1=$1
134 | file2=$2
135 |
136 | if [ ! -r $file1 ]; then
137 | echo "ERROR: input data file $file1 is not readable"
138 | exit 1
139 | else
140 | row1=`get_row $file1`
141 | col1=`get_col $file1`
142 | fi
143 |
144 | if [ ! -r $file2 ]; then
145 | echo "ERROR: input data file $file2 is not readable"
146 | exit 1
147 | else
148 | row2=`get_row $file2`
149 | col2=`get_col $file2`
150 | fi
151 |
152 | if [[ $row1 -ne $row2 ]]; then
153 | echo "ERROR: $file1 and $file2 do not have have the same number of rows."
154 | echo "ERROR: please check or do preprocessing if necessary."
155 | fi
156 |
157 | if [[ $VERBOSE == YES ]]; then
158 | cmd="$pgm -v -j 2 -s 0 -q 0 -a $ALGORITHM -f $FDR --cycles $CYCLES --cycles_orig 2 --convergence $THRESHOLD 2 $row1 $file1 $file2 $col1 $col2 0 0 "
159 | else
160 | cmd="$pgm -j 2 -s 0 -q 0 -a $ALGORITHM -f $FDR --cycles $CYCLES --cycles_orig 2 --convergence $THRESHOLD 2 $row1 $file1 $file2 $col1 $col2 0 0 "
161 | fi
162 | echo $cmd
163 | # do the actual work
164 | eecho "Start at `date`"
165 | $cmd
166 | eecho "Finish at `date`"
167 |
--------------------------------------------------------------------------------
/bin/onecomp:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ##############################
4 | # Xianlong Wang, Feb. 14, 2017
5 | # Driver for REOA: OneComp
6 | ##############################
7 |
8 | # Defaults
9 | # ALGORITHM, default RankCompV2
10 | ALGORITHM=0
11 | #MODE, default paired contro-treat sample
12 | MODE=0
13 | # FDR level, 5%
14 | FDR=0.05
15 | # CYCLES, maximum cycles for filtering
16 | CYCLES=128
17 | # CYCLES_ORIG, maximum cycles for filtering
18 | # original RankComp algo.
19 | CYCLES_ORIG=2
20 | # THRESHOLD, convergence criterion
21 | THRESHOLD=50
22 | # VERBOSE output
23 | VERBOSE=NO
24 |
25 | pgm=reoa
26 | version="revison 0.1 2017-02-14"
27 | if ! hash $pgm 2>/dev/null; then
28 | echo The main executable "$pgm" is not found. Please check \$PATH
29 | exit 1
30 | fi
31 |
32 | function usage
33 | {
34 | echo "NAME"
35 | echo " onecomp, a bash script driver for application of $pgm"
36 | echo " to detect dysregulated genes in one treated sample"
37 | echo " given a list of stable gene pairs and one paired control"
38 | echo " sample."
39 | echo "SYNOPSIS"
40 | echo " onecomp [-h|-V]"
41 | echo " onecomp [OPTIONS] pair_file control_file treated_file"
42 | echo "DESCRIPTION"
43 | echo " OneComp (onecomp) is a program to apply the original RankComp "
44 | echo " and RankCompV2 algorithms to detect differentially expressed "
45 | echo " genes (DEGs) in one treated sample given the paired control "
46 | echo " sample and a list of predetermined gene pairs with stable REOs."
47 | echo " The control sample is used to customize the gene pair list"
48 | echo " and 'paired' here does not necessarily mean the expermental"
49 | echo " design but a compatiable corresponding relation between the two."
50 | echo " The 'control_file' and 'treated_file contains the expression"
51 | echo " profiles of a group of control samples and a group of treated"
52 | echo " samples. They should have the same number of rows (gene probes) "
53 | echo " and the same number of columns (number of samples). The i-th"
54 | echo " column of 'control_file' and the i-th column of 'treated_file' "
55 | echo " constitue one paired sample and they are processed by the algo."
56 | echo " independent of the other columns."
57 | echo " The pair_file contains the list of predetermined gene pairs which"
58 | echo " are given by the gene probe indices (0-based) which have the same"
59 | echo " order as the expression files (control_file or treated_file)."
60 | echo " The RankComp and RanCompV2 are based on the analysis of"
61 | echo " within-sample relative expression orderings (REOs) of gene pairs."
62 | echo " See the references more details."
63 | echo "OPTIONS"
64 | echo " -h, --help, --usage"
65 | echo " Show this message"
66 | echo " -V, --version"
67 | echo " Show program version"
68 | echo " -a, --algorithm = VALUE"
69 | echo " Choice of algorithm. Default: 0"
70 | echo " 0 - RankCompV2 only"
71 | echo " 1 - Original RankComp only"
72 | echo " 2 - Both RankComp and RankCompV2"
73 | echo " -m, --mode = VALUE"
74 | echo " Choice of filter mode. Default: 0"
75 | echo " 0 - Use one control sample to filter the pairs to detect DEGs"
76 | echo " in the corresponding treated sample"
77 | echo " 1 - Use all the control samples to filter the pairs to detect"
78 | echo " DEGs in each treated samples"
79 | echo " -f, --fdr = FDR"
80 | echo " False discovery rate (FDR) level. Default: 0.05"
81 | echo " -c, --cycles = CYCLES"
82 | echo " Maximum iteration cycles. Default: 128"
83 | echo " -t, --threshold = THRESHOLD"
84 | echo " Convergence criterion. Default: 50 "
85 | echo " (Maximum fluctuation in number of DEGs)"
86 | echo " -v, --verbose"
87 | echo " Output extra information"
88 | echo
89 | }
90 |
91 | function eecho(){
92 | echo "# $*"
93 | }
94 |
95 | function get_row(){
96 | wc -l $1 |awk '{print $1}'
97 | }
98 |
99 | function get_col(){
100 | head -1 $1 | wc -w
101 | }
102 |
103 | # Parsing options
104 | # WARNING: option value is not validated.
105 | # NOTE: This requires GNU getopt.
106 | OPTIONS=`getopt -o a:f:c:t:m:vhV --long algorithm:,fdr:,cycles:,threshold:,mode:,verbose,help,usage,version -n "$pgm" -- "$@"`
107 | eval set -- "$OPTIONS"
108 |
109 | #while [[ $# -gt 1 ]]
110 | while true;
111 | do
112 | case "$1" in
113 | -h|--help|--usage)
114 | usage
115 | exit 0
116 | ;;
117 | -V|--version)
118 | echo $pgm $version
119 | exit 0
120 | ;;
121 | -a|--algorithm)
122 | ALGORITHM="$2"
123 | shift 2 # past argument
124 | ;;
125 | -f|--fdr)
126 | FDR="$2"
127 | shift 2 # past argument
128 | ;;
129 | -c|--cycles)
130 | CYCLES="$2"
131 | shift 2 # past argument
132 | ;;
133 | -t|--threshold)
134 | THRESHOLD="$2"
135 | shift 2 # past argument
136 | ;;
137 | -m|--mode)
138 | MODE="$2"
139 | shift 2 # past argument
140 | ;;
141 | -v|--verbose)
142 | VERBOSE=YES
143 | shift
144 | ;;
145 | -- )
146 | shift
147 | break
148 | ;;
149 | *)
150 | break
151 | ;;
152 | esac
153 | done
154 |
155 | if [ $# -lt 3 ]; then
156 | usage
157 | exit 1
158 | fi
159 |
160 | # check input files
161 | file1=$1
162 | file2=$2
163 | file3=$3
164 |
165 | if [ ! -r $file1 ]; then
166 | echo "ERROR: input data file $file1 is not readable"
167 | exit 1
168 | else
169 | row1=`get_row $file1`
170 | col1=`get_col $file1`
171 | fi
172 |
173 | if [ ! -r $file2 ]; then
174 | echo "ERROR: input data file $file2 is not readable"
175 | exit 1
176 | else
177 | row2=`get_row $file2`
178 | col2=`get_col $file2`
179 | fi
180 |
181 | if [ ! -r $file3 ]; then
182 | echo "ERROR: input data file $file3 is not readable"
183 | exit 1
184 | else
185 | row3=`get_row $file3`
186 | col3=`get_col $file3`
187 | fi
188 |
189 | if [[ $row2 -ne $row3 ]]; then
190 | echo "ERROR: $file2 and $file3 do not have have the same number of rows."
191 | echo "ERROR: please check or do preprocessing if necessary."
192 | exit 1
193 | fi
194 |
195 | if [[ $col1 -ne 2 ]]; then
196 | echo "WARNING: $file1 does not seem a list of gene pairs."
197 | echo "WARNING: Please check or do preprocessing if necessary."
198 | fi
199 |
200 | if [[ $col2 -ne $col3 ]]; then
201 | echo "WARNING: $file2 and $file3 do not have have the same number of column."
202 | echo "WARNING: Only the first few common columns will be processed."
203 | echo "WARNING: Please check or do preprocessing if necessary."
204 | fi
205 |
206 | if [[ $VERBOSE == YES ]]; then
207 | cmd="$pgm -v -j 7 -l $row1 -c $file1 -a $ALGORITHM -p $MODE -f $FDR --cycles $CYCLES --cycles_orig $CYCLES_ORIG --convergence $THRESHOLD 2 $row2 $file2 $file3 $col2 $col3"
208 | else
209 | cmd="$pgm -j 7 -l $row1 -c $file1 -a $ALGORITHM -p $MODE -f $FDR --cycles $CYCLES --cycles_orig $CYCLES_ORIG --convergence $THRESHOLD 2 $row2 $file2 $file3 $col2 $col3"
210 | fi
211 | echo $cmd
212 | # do the actual work
213 | eecho "Start at `date`"
214 | $cmd
215 | eecho "Finish at `date`"
216 |
--------------------------------------------------------------------------------
/bin/reoa:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pathint/reoa/1437c3340be67c0c40175468d72cd0ea0c1294c9/bin/reoa
--------------------------------------------------------------------------------
/bin/reoa_linux64_gomp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pathint/reoa/1437c3340be67c0c40175468d72cd0ea0c1294c9/bin/reoa_linux64_gomp3
--------------------------------------------------------------------------------
/bin/reoa_linux64_gomp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pathint/reoa/1437c3340be67c0c40175468d72cd0ea0c1294c9/bin/reoa_linux64_gomp4
--------------------------------------------------------------------------------
/src/Makefile:
--------------------------------------------------------------------------------
1 | ifeq ($(OS),Windows_NT)
2 | CCFLAGS += -D WIN32
3 | ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
4 | CCFLAGS += -D AMD64
5 | else
6 | ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
7 | CCFLAGS += -D AMD64
8 | endif
9 | ifeq ($(PROCESSOR_ARCHITECTURE),x86)
10 | CCFLAGS += -D IA32
11 | endif
12 | endif
13 | else
14 | UNAME_S := $(shell uname -s)
15 | prefix := /usr/local
16 | ifeq ($(UNAME_S),Linux)
17 | CCFLAGS += -D LINUX
18 | CC = gcc
19 | CFLAGS = -O2 -Wall -fopenmp
20 | INCLUDES = -I. -I/usr/lib64/gcc/x86_64-pc-linux-gnu/4.9.3/include
21 | endif
22 | ifeq ($(UNAME_S),Darwin)
23 | CCFLAGS += -D OSX
24 | CC = gcc-mp-5
25 | CFLAGS = -O2 -Wall -fopenmp
26 | INCLUDES = -I. -I/opt/local/lib/gcc5/gcc/x86_64-apple-darwin15/5.2.0/include
27 | endif
28 | UNAME_P := $(shell uname -p)
29 | ifeq ($(UNAME_P),x86_64)
30 | CCFLAGS += -D AMD64
31 | endif
32 | ifneq ($(filter %86,$(UNAME_P)),)
33 | CCFLAGS += -D IA32
34 | endif
35 | ifneq ($(filter arm%,$(UNAME_P)),)
36 | CCFLAGS += -D ARM
37 | endif
38 | endif
39 |
40 |
41 | LIBS = -lm -lgomp
42 |
43 | SRCS = pcg_basic.c stat.c binomial.c fisher.c hypergeom.c random_sample.c \
44 | reoa.c main.c
45 |
46 |
47 | LFLAGS =
48 |
49 | OBJS = $(SRCS:.c=.o)
50 |
51 | TARGETS := fisher hypergeom binomial random_sample \
52 | reoa
53 |
54 |
55 | .PHONY: depend clean install
56 |
57 | all: $(TARGETS)
58 | @echo Building all executables
59 |
60 | binomial: pcg_basic.o stat.o binomial.o
61 | $(CC) $(LFLAGS) $(LIBS) -o $@ $^
62 |
63 | fisher: pcg_basic.o stat.o fisher.o
64 | $(CC) $(LFLAGS) $(LIBS) -o $@ $^
65 |
66 | hypergeom: pcg_basic.o stat.o hypergeom.o
67 | $(CC) $(LFLAGS) $(LIBS) -o $@ $^
68 |
69 | random_sample: pcg_basic.o stat.o random_sample.o
70 | $(CC) $(LFLAGS) $(LIBS) -o $@ $^
71 |
72 | reoa: pcg_basic.o stat.o reoa.o main.o
73 | $(CC) $(LFLAGS) $(LIBS) -o $@ $^
74 |
75 | install: reoa
76 | test -d $(prefix) || mkdir $(prefix)
77 | test -d $(prefix)/bin || mkdir $(prefix)/bin
78 | install -m 0755 reoa $(prefix)/bin
79 | install -m 0755 cellcomp $(prefix)/bin
80 | install -m 0755 onecomp $(prefix)/bin
81 |
82 | # this is a suffix replacement rule for building .o's from .c's
83 | # it uses automatic variables $<: the name of the prerequisite of
84 | # the rule(a .c file) and $@: the name of the target of the rule (a .o file)
85 | # (see the gnu make manual section about automatic variables)
86 | .c.o:
87 | $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@
88 |
89 | clean:
90 | $(RM) *.o *~ $(TARGETS)
91 |
92 | depend: $(SRCS)
93 | makedepend $(INCLUDES) $^
94 |
95 | # DO NOT DELETE THIS LINE -- make depend needs it
96 |
--------------------------------------------------------------------------------
/src/README.md:
--------------------------------------------------------------------------------
1 | ## Install from the Source Files
2 | 1. Run the command `make` under this folder (`src`).
3 | 2. Run the command `make install` to install the package. The default installation folder is `/usr/local/bin`. This requires `root` privilege. Alternatively, you may manually copy the executables (`reoa`, `cellcomp` and `onecomp`) to the folder where your PATH can find, such as `/usr/local/bin/`.
4 | 3. Make sure the files have the correct executable permission (e.g. 755). If it does not, use `chmod 755 reoa` to make the modification.
5 | 4. Besides the main program `reoa` and specific scenario application scripts (`cellcomp` and `onecomp`), four additional utility programs, `binomial`, `hypergeom`, `fisher` and `random_sample`, should be also generated. They are used to test the statistical functions implemented in the package.
6 | 5. Try it! For example, running the following command will return the usage of the program.
7 |
8 | ```
9 | reoa -h
10 | cellcomp -h
11 | onecomp -h
12 | ```
13 |
14 |
15 | ## Trouble Shooting
16 | 1. Make sure you have the basic compiling tools installed on your system, such as `gcc`, `as` and `make`.
17 | 2. Try to replace `gcc`, `CCFLAGS`, and `INCLUDES` in the `Makefile` to fit your system settings if you fail with the default settings. Then run the `make` command.
18 | 3. On macOS, the compiler in `Makefile` is set as `gcc-mp-5`, and `INCLUDES` is set as `-I/opt/local/lib/gcc5/gcc/x86_64-apple-darwin15/5.2.0/include`. You may need to edit them to fit your system. The default `clang` compiler on macOS seems does not support OpenMP v4.0. Therefore, you need to install `gcc` first or `clang-openmp` using `brew`.
19 | 4. Alternatively, you may install the binary executable directly which are available under the `bin` folder. Please choose the appropriate version that fits your system.
20 | 5. Windows users should be able to compile the source code using **Cygwin** or other similar cross-platform tools.
21 |
22 |
--------------------------------------------------------------------------------
/src/binomial.c:
--------------------------------------------------------------------------------
1 | /**************************************************************************
2 | * stat.c: Basic Statistics Functions
3 | *
4 | * Xianlong Wang, Ph.D.
5 | * University of Electronic Science and Technology of China.
6 | * Email: Wang.Xianlong@139.com
7 | *
8 | * Initialization. Nov. 11, 2016.
9 | **************************************************************************/
10 |
11 | #include
12 | #include
13 | #include "stat.h"
14 |
15 |
16 | int main(int argc, char* argv[]) {
17 | if(argc<3){
18 | printf("ERROR: Two few agruments!\n");
19 | printf("Usage: %s n m\n", argv[0]);
20 | printf("where m and n are non-negative integer numbers,\n");
21 | printf("n is the total number of trials,\n");
22 | printf("m is the number of one of two possible outcomes which have the same proportions (p = 50%%) in the underlying population.\n");
23 | return -1;
24 | }
25 | int n = atoi(argv[1]);
26 | int m = atoi(argv[2]);
27 | if(n<2||m<0||m>n/2||n>255){
28 | printf("ERROR: Out-of-range Numbers!!\n");
29 | }
30 | else{
31 | printf("The one-tailed binomial test P value is %.15g\n", bino_p(n, m));
32 | }
33 | return 0;
34 | }
35 |
--------------------------------------------------------------------------------
/src/cellcomp:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ##############################
4 | # Xianlong Wang, Jan 17, 2017
5 | # Driver for REOA
6 | ##############################
7 |
8 | # Defaults
9 | # ALGORITHM, default RankCompV2
10 | ALGORITHM=0
11 | # FDR level, 5%
12 | FDR=0.05
13 | # CYCLES, maximum cycles for filtering
14 | CYCLES=128
15 | # THRESHOLD, convergence criterion
16 | THRESHOLD=50
17 | # VERBOSE output
18 | VERBOSE=NO
19 |
20 | pgm=reoa
21 | version="revison 0.1. 2017-01-17"
22 | if ! hash $pgm 2>/dev/null; then
23 | echo The main executable "$pgm" is not found. Please check \$PATH
24 | exit 1
25 | fi
26 |
27 | function usage
28 | {
29 | echo "NAME"
30 | echo " cellcomp, a bash script driver for application of $pgm"
31 | echo " to small-scale data set with only a few technical replicates"
32 | echo "SYNOPSIS"
33 | echo " cellcomp [-h|-V]"
34 | echo " cellcomp [OPTIONS] control_file case_file"
35 | echo "DESCRIPTION"
36 | echo " CellComp (cellcomp) is a program to apply the RanComp and "
37 | echo " RankCompV2 algorithms to detect differentially expressed "
38 | echo " genes (DEGs) in small-scale cell line experiments. In such "
39 | echo " experiments, the gene expression profiles contain only two "
40 | echo " or three technical replicates and most conventional methods"
41 | echo " lack statistical power when applied to such small-scale data"
42 | echo " sets. The RankComp and RanCompV2 are based on the analysis of"
43 | echo " within-sample relative expression orderings (REOs) of gene pairs."
44 | echo " See the references more details."
45 | echo "OPTIONS"
46 | echo " -h, --help, --usage"
47 | echo " Show this message"
48 | echo " -V, --version"
49 | echo " Show program version"
50 | echo " -a, --algorithm = ALGORITHM"
51 | echo " Choice of algorithm. Default: 0"
52 | echo " 0 - RankCompV2 only"
53 | echo " 1 - Original RankComp only"
54 | echo " 2 - Both RankComp and RankCompV2"
55 | echo " -f, --fdr = FDR"
56 | echo " False discovery rate (FDR) level. Default: 0.05"
57 | echo " -c, --cycles = CYCLES"
58 | echo " Maximum iteration cycles. Default: 128"
59 | echo " -t, --threshold = THRESHOLD"
60 | echo " Convergence criterion. Default: 50 "
61 | echo " (Maximum fluctuation in number of DEGs)"
62 | echo " -v, --verbose"
63 | echo " Output extra information"
64 | echo
65 | }
66 |
67 | function eecho(){
68 | echo "# $*"
69 | }
70 |
71 | function get_row(){
72 | wc -l $1 |awk '{print $1}'
73 | }
74 |
75 | function get_col(){
76 | head -1 $1 | wc -w
77 | }
78 |
79 | # Parsing options
80 | # WARNING: option value is not validated.
81 | # NOTE: This requires GNU getopt.
82 | OPTIONS=`getopt -o a:f:c:t:vhV --long algorithm:,fdr:,cycles:,threshold:,verbose,help,usage,version -n "$pgm" -- "$@"`
83 | eval set -- "$OPTIONS"
84 |
85 | #while [[ $# -gt 1 ]]
86 | while true;
87 | do
88 | case "$1" in
89 | -h|--help|--usage)
90 | usage
91 | exit 0
92 | ;;
93 | -V|--version)
94 | echo $pgm $version
95 | exit 0
96 | ;;
97 | -a|--algorithm)
98 | ALGORITHM="$2"
99 | shift 2 # past argument
100 | ;;
101 | -f|--fdr)
102 | FDR="$2"
103 | shift 2 # past argument
104 | ;;
105 | -c|--cycles)
106 | CYCLES="$2"
107 | shift 2 # past argument
108 | ;;
109 | -t|--threshold)
110 | THRESHOLD="$2"
111 | shift 2 # past argument
112 | ;;
113 | -v|--verbose)
114 | VERBOSE=YES
115 | shift
116 | ;;
117 | -- )
118 | shift
119 | break
120 | ;;
121 | *)
122 | break
123 | ;;
124 | esac
125 | done
126 |
127 | if [ $# -lt 2 ]; then
128 | usage
129 | exit 1
130 | fi
131 |
132 | # check input files
133 | file1=$1
134 | file2=$2
135 |
136 | if [ ! -r $file1 ]; then
137 | echo "ERROR: input data file $file1 is not readable"
138 | exit 1
139 | else
140 | row1=`get_row $file1`
141 | col1=`get_col $file1`
142 | fi
143 |
144 | if [ ! -r $file2 ]; then
145 | echo "ERROR: input data file $file2 is not readable"
146 | exit 1
147 | else
148 | row2=`get_row $file2`
149 | col2=`get_col $file2`
150 | fi
151 |
152 | if [[ $row1 -ne $row2 ]]; then
153 | echo "ERROR: $file1 and $file2 do not have have the same number of rows."
154 | echo "ERROR: please check or do preprocessing if necessary."
155 | fi
156 |
157 | if [[ $VERBOSE == YES ]]; then
158 | cmd="$pgm -v -j 2 -s 0 -q 0 -a $ALGORITHM -f $FDR --cycles $CYCLES --cycles_orig $CYCLES --convergence $THRESHOLD 2 $row1 $file1 $file2 $col1 $col2 0 0 "
159 | else
160 | cmd="$pgm -j 2 -s 0 -q 0 -a $ALGORITHM -f $FDR --cycles $CYCLES --cycles_orig 2 --convergence $THRESHOLD 2 $row1 $file1 $file2 $col1 $col2 0 0 "
161 | fi
162 | echo $cmd
163 | # do the actual work
164 | eecho "Start at `date`"
165 | $cmd
166 | eecho "Finish at `date`"
167 |
--------------------------------------------------------------------------------
/src/fisher.c:
--------------------------------------------------------------------------------
1 | /**************************************************************************
2 | * stat.c: Basic Statistics Functions
3 | *
4 | * Xianlong Wang, Ph.D.
5 | * University of Electronic Science and Technology of China.
6 | * Email: Wang.Xianlong@139.com
7 | *
8 | * Initialization. Nov. 11, 2016.
9 | **************************************************************************/
10 |
11 | #include
12 | #include
13 | #include "stat.h"
14 |
15 |
16 | int main(int argc, char* argv[]) {
17 | if(argc<5){
18 | printf("ERROR: Two few agruments!\n");
19 | printf("Usage: %s a b c d\n", argv[0]);
20 | printf("where a, b, c and d are four non-negative integer numbers,\n");
21 | printf("a and b are observed frequencies for two outcomes in one group, e.g. the control group,\n");
22 | printf("c and d are observed frequencies for two outcomes in the other group, e.g., the treatment group.\n");
23 | return -1;
24 | }
25 | int a = atoi(argv[1]);
26 | int b = atoi(argv[2]);
27 | int c = atoi(argv[3]);
28 | int d = atoi(argv[4]);
29 | if(a<0||b<0||c<0||d<0){
30 | printf("ERROR: Non-negative integeters only!\n");
31 | }
32 | else{
33 | printf("The two-tailed Fisher exact test P value is %.15g\n", fisher_test(a, b, c, d));
34 | //printf("Right tail value is %d\n", right_tail(a, b, c, d));
35 | }
36 | return 0;
37 | }
38 |
--------------------------------------------------------------------------------
/src/hypergeom.c:
--------------------------------------------------------------------------------
1 | /**************************************************************************
2 | * stat.c: Basic Statistics Functions
3 | *
4 | * Xianlong Wang, Ph.D.
5 | * University of Electronic Science and Technology of China.
6 | * Email: Wang.Xianlong@139.com
7 | *
8 | * Initialization. Nov. 11, 2016.
9 | **************************************************************************/
10 |
11 | #include
12 | #include
13 | #include "stat.h"
14 |
15 |
16 | int main(int argc, char* argv[]) {
17 | if(argc<5){
18 | printf("ERROR: Two few agruments!\n");
19 | printf("Usage: %s a b c d\n", argv[0]);
20 | printf("where a, b, c and d are four non-negative integer numbers,\n");
21 | printf("a and b are observed frequencies for two outcomes in one group, e.g. the control group,\n");
22 | printf("c and d are observed frequencies for two outcomes in the other group, e.g., the treatment group.\n");
23 | return -1;
24 | }
25 | int a = atoi(argv[1]);
26 | int b = atoi(argv[2]);
27 | int c = atoi(argv[3]);
28 | int d = atoi(argv[4]);
29 | if(a<0||b<0||c<0||d<0){
30 | printf("ERROR: Non-negative integeters only!\n");
31 | }
32 | else{
33 | printf("The one-tailed hypergeometric test P value is %.15g\n", hypergeo_test(a, b, c, d));
34 | }
35 | return 0;
36 | }
37 |
--------------------------------------------------------------------------------
/src/main.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #define STABLE "stable_pairs_"
5 | #define CONCORDANT "concordant_pairs_"
6 | #define REVERSED "reversed_pairs_"
7 | #define UP "up_regulated_"
8 | #define DOWN "down_regulated_"
9 | #define UP_ORIG "up_orig_algo_"
10 | #define DOWN_ORIG "down_orig_algo_"
11 | #define GENE_STATE "gene_state_"
12 | #define SIMULATION "simulation_"
13 | #define SIMILARITY "similarity_"
14 | #define BAYESIAN "bayesian_"
15 | #define SAMPLED_GENES "sampled_genes_"
16 | #define EXT ".dat"
17 |
18 | static struct option long_options[] =
19 | {
20 | {"verbose", no_argument, NULL, 'v'},
21 | {"Version", no_argument, NULL, 'V'},
22 | {"help", no_argument, NULL, 'h'},
23 | {"epsilon", required_argument, NULL, 'e'},
24 | {"equals", required_argument, NULL, 'q'},
25 | {"fdr", required_argument, NULL, 'f'},
26 | {"sample", required_argument, NULL, 's'},
27 | {"job", required_argument, NULL, 'j'},
28 | {"pair", required_argument, NULL, 'p'},
29 | {"platform",required_argument, NULL, 'P'},
30 | {"changes", required_argument, NULL, 'c'},
31 | {"lines", required_argument, NULL, 'l'},
32 | {"plines", required_argument, NULL, 'L'},
33 | {"time", required_argument, NULL, 't'},
34 | {"algorithm",required_argument,NULL, 'a'},
35 | {"cycles", required_argument, NULL, 'm'},
36 | {"cycles_orig",required_argument, NULL, 'o'},
37 | {"convergence",required_argument, NULL, 'n'},
38 | {"memory", required_argument, NULL, 'M'},
39 | {NULL, no_argument, NULL, 0}
40 | };
41 |
42 | static const char *opt_string = "e:q:f:s:j:p:P:c:l:L:t:a:m:o:n:M:vVh?";
43 |
44 | float MEMORY_USAGE = -1.;
45 |
46 | // could be better
47 | static void display_usage(FILE *f, const char *program_name);
48 | static void display_version(FILE *f, const char *program_name);
49 |
50 | char *my_itoa(int value, char *str);
51 | char *make_file_name(char *stem, int index, char *ext, char *fname);
52 | char *make_file_name2(char *stem, int i1, char *in, int i2, char *ext, char *fn);
53 | char *make_file_name3(char *stem, int i1, char *in1, int i2, char *in2, int i3, char *ext, char *fn);
54 |
55 | int read_changes(const char *file_name, int n_changes, struct CHANGE changes[n_changes]);
56 | int read_data(char *file, int n_genes, int sample_size, DATATYPE_VALUE *data);
57 | int extract_column(unsigned int n, unsigned int m, DATATYPE_VALUE data[n*m],
58 | unsigned int c, DATATYPE_VALUE column[n]);
59 |
60 | int select_stable_pairs(int n_files,
61 | char *files[n_files],
62 | int sample_sizes[n_files],
63 | float fdr[n_files],
64 | int n_genes ,
65 | int max_equals
66 | );
67 |
68 | int select_consistent_pairs(int n_files,
69 | char *files[n_files],
70 | int sample_sizes[n_files],
71 | float fdr[n_files],
72 | int n_genes ,
73 | int max_equals,
74 | char job,
75 | char pair_mode,
76 | float alpha,
77 | int max_cycles,
78 | int ori_cycles,
79 | int max_threshold,
80 | char algorithm
81 | );
82 |
83 | int select_consistent_pairs_ind(int n_files,
84 | char *files[n_files],
85 | int sample_sizes[n_files],
86 | float fdr[n_files],
87 | int n_genes ,
88 | int max_equals,
89 | char job,
90 | char pair_mode,
91 | float alpha,
92 | int max_cycles,
93 | int ori_cycles,
94 | int max_threshold,
95 | char algorithm
96 | );
97 |
98 | int gen_simulation_data(int times,
99 | char *fname,
100 | int size,
101 | int n_genes,
102 | int n_changes,
103 | char *cname,
104 | char *simu_names[times+1],
105 | int max_equals,
106 | char job,
107 | float alpha,
108 | int max_cycles,
109 | int ori_cycles,
110 | int max_threshold,
111 | char algorithm
112 | );
113 |
114 | int calculate_similarity(DATATYPE_GENESIZE n,
115 | DATATYPE_SAMPLESIZE m,
116 | char *file_name,
117 | char *out_name
118 | );
119 |
120 | /*Job Type 6 */
121 | int calculate_simi_three(DATATYPE_GENESIZE n,
122 | DATATYPE_SAMPLESIZE m,
123 | char *file_name,
124 | char *out_name
125 | );
126 |
127 | int calc_sample_similarity(int n_files,
128 | char *files[n_files],
129 | int sample_sizes[n_files],
130 | int n_genes,
131 | char job
132 | );
133 |
--------------------------------------------------------------------------------
/src/onecomp:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | ##############################
4 | # Xianlong Wang, Feb. 14, 2017
5 | # Driver for REOA: OneComp
6 | ##############################
7 |
8 | # Defaults
9 | # ALGORITHM, default RankCompV2
10 | ALGORITHM=0
11 | #MODE, default paired contro-treat sample
12 | MODE=0
13 | # FDR level, 5%
14 | FDR=0.05
15 | # CYCLES, maximum cycles for filtering
16 | CYCLES=128
17 | # CYCLES_ORIG, maximum cycles for filtering
18 | # original RankComp algo.
19 | CYCLES_ORIG=2
20 | # THRESHOLD, convergence criterion
21 | THRESHOLD=50
22 | # VERBOSE output
23 | VERBOSE=NO
24 |
25 | pgm=reoa
26 | version="revison 0.1 2017-02-14"
27 | if ! hash $pgm 2>/dev/null; then
28 | echo The main executable "$pgm" is not found. Please check \$PATH
29 | exit 1
30 | fi
31 |
32 | function usage
33 | {
34 | echo "NAME"
35 | echo " onecomp, a bash script driver for application of $pgm"
36 | echo " to detect dysregulated genes in one treated sample"
37 | echo " given a list of stable gene pairs and one paired control"
38 | echo " sample."
39 | echo "SYNOPSIS"
40 | echo " onecomp [-h|-V]"
41 | echo " onecomp [OPTIONS] pair_file control_file treated_file"
42 | echo "DESCRIPTION"
43 | echo " OneComp (onecomp) is a program to apply the original RankComp "
44 | echo " and RankCompV2 algorithms to detect differentially expressed "
45 | echo " genes (DEGs) in one treated sample given the paired control "
46 | echo " sample and a list of predetermined gene pairs with stable REOs."
47 | echo " The control sample is used to customize the gene pair list"
48 | echo " and 'paired' here does not necessarily mean the expermental"
49 | echo " design but a compatiable corresponding relation between the two."
50 | echo " The 'control_file' and 'treated_file contains the expression"
51 | echo " profiles of a group of control samples and a group of treated"
52 | echo " samples. They should have the same number of rows (gene probes) "
53 | echo " and the same number of columns (number of samples). The i-th"
54 | echo " column of 'control_file' and the i-th column of 'treated_file' "
55 | echo " constitue one paired sample and they are processed by the algo."
56 | echo " independent of the other columns."
57 | echo " The pair_file contains the list of predetermined gene pairs which"
58 | echo " are given by the gene probe indices (0-based) which have the same"
59 | echo " order as the expression files (control_file or treated_file)."
60 | echo " The RankComp and RanCompV2 are based on the analysis of"
61 | echo " within-sample relative expression orderings (REOs) of gene pairs."
62 | echo " See the references more details."
63 | echo "OPTIONS"
64 | echo " -h, --help, --usage"
65 | echo " Show this message"
66 | echo " -V, --version"
67 | echo " Show program version"
68 | echo " -a, --algorithm = VALUE"
69 | echo " Choice of algorithm. Default: 0"
70 | echo " 0 - RankCompV2 only"
71 | echo " 1 - Original RankComp only"
72 | echo " 2 - Both RankComp and RankCompV2"
73 | echo " -m, --mode = VALUE"
74 | echo " Choice of filter mode. Default: 0"
75 | echo " 0 - Use one control sample to filter the pairs to detect DEGs"
76 | echo " in the corresponding treated sample"
77 | echo " 1 - Use all the control samples to filter the pairs to detect"
78 | echo " DEGs in each treated samples"
79 | echo " -f, --fdr = FDR"
80 | echo " False discovery rate (FDR) level. Default: 0.05"
81 | echo " -c, --cycles = CYCLES"
82 | echo " Maximum iteration cycles. Default: 128"
83 | echo " -t, --threshold = THRESHOLD"
84 | echo " Convergence criterion. Default: 50 "
85 | echo " (Maximum fluctuation in number of DEGs)"
86 | echo " -v, --verbose"
87 | echo " Output extra information"
88 | echo
89 | }
90 |
91 | function eecho(){
92 | echo "# $*"
93 | }
94 |
95 | function get_row(){
96 | wc -l $1 |awk '{print $1}'
97 | }
98 |
99 | function get_col(){
100 | head -1 $1 | wc -w
101 | }
102 |
103 | # Parsing options
104 | # WARNING: option value is not validated.
105 | # NOTE: This requires GNU getopt.
106 | OPTIONS=`getopt -o a:f:c:t:m:vhV --long algorithm:,fdr:,cycles:,threshold:,mode:,verbose,help,usage,version -n "$pgm" -- "$@"`
107 | eval set -- "$OPTIONS"
108 |
109 | #while [[ $# -gt 1 ]]
110 | while true;
111 | do
112 | case "$1" in
113 | -h|--help|--usage)
114 | usage
115 | exit 0
116 | ;;
117 | -V|--version)
118 | echo $pgm $version
119 | exit 0
120 | ;;
121 | -a|--algorithm)
122 | ALGORITHM="$2"
123 | shift 2 # past argument
124 | ;;
125 | -f|--fdr)
126 | FDR="$2"
127 | shift 2 # past argument
128 | ;;
129 | -c|--cycles)
130 | CYCLES="$2"
131 | shift 2 # past argument
132 | ;;
133 | -t|--threshold)
134 | THRESHOLD="$2"
135 | shift 2 # past argument
136 | ;;
137 | -m|--mode)
138 | MODE="$2"
139 | shift 2 # past argument
140 | ;;
141 | -v|--verbose)
142 | VERBOSE=YES
143 | shift
144 | ;;
145 | -- )
146 | shift
147 | break
148 | ;;
149 | *)
150 | break
151 | ;;
152 | esac
153 | done
154 |
155 | if [ $# -lt 3 ]; then
156 | usage
157 | exit 1
158 | fi
159 |
160 | # check input files
161 | file1=$1
162 | file2=$2
163 | file3=$3
164 |
165 | if [ ! -r $file1 ]; then
166 | echo "ERROR: input data file $file1 is not readable"
167 | exit 1
168 | else
169 | row1=`get_row $file1`
170 | col1=`get_col $file1`
171 | fi
172 |
173 | if [ ! -r $file2 ]; then
174 | echo "ERROR: input data file $file2 is not readable"
175 | exit 1
176 | else
177 | row2=`get_row $file2`
178 | col2=`get_col $file2`
179 | fi
180 |
181 | if [ ! -r $file3 ]; then
182 | echo "ERROR: input data file $file3 is not readable"
183 | exit 1
184 | else
185 | row3=`get_row $file3`
186 | col3=`get_col $file3`
187 | fi
188 |
189 | if [[ $row2 -ne $row3 ]]; then
190 | echo "ERROR: $file2 and $file3 do not have have the same number of rows."
191 | echo "ERROR: please check or do preprocessing if necessary."
192 | exit 1
193 | fi
194 |
195 | if [[ $col1 -ne 2 ]]; then
196 | echo "WARNING: $file1 does not seem a list of gene pairs."
197 | echo "WARNING: Please check or do preprocessing if necessary."
198 | fi
199 |
200 | if [[ $col2 -ne $col3 ]]; then
201 | echo "WARNING: $file2 and $file3 do not have have the same number of column."
202 | echo "WARNING: Only the first few common columns will be processed."
203 | echo "WARNING: Please check or do preprocessing if necessary."
204 | fi
205 |
206 | if [[ $VERBOSE == YES ]]; then
207 | cmd="$pgm -v -j 7 -l $row1 -c $file1 -a $ALGORITHM -p $MODE -f $FDR --cycles $CYCLES --cycles_orig $CYCLES_ORIG --convergence $THRESHOLD 2 $row2 $file2 $file3 $col2 $col3"
208 | else
209 | cmd="$pgm -j 7 -l $row1 -c $file1 -a $ALGORITHM -p $MODE -f $FDR --cycles $CYCLES --cycles_orig $CYCLES_ORIG --convergence $THRESHOLD 2 $row2 $file2 $file3 $col2 $col3"
210 | fi
211 | echo $cmd
212 | # do the actual work
213 | eecho "Start at `date`"
214 | $cmd
215 | eecho "Finish at `date`"
216 |
--------------------------------------------------------------------------------
/src/pcg_basic.c:
--------------------------------------------------------------------------------
1 | /*
2 | * PCG Random Number Generation for C.
3 | *
4 | * Copyright 2014 Melissa O'Neill
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | *
18 | * For additional information about the PCG random number generation scheme,
19 | * including its license and other licensing options, visit
20 | *
21 | * http://www.pcg-random.org
22 | */
23 |
24 | /*
25 | * This code is derived from the full C implementation, which is in turn
26 | * derived from the canonical C++ PCG implementation. The C++ version
27 | * has many additional features and is preferable if you can use C++ in
28 | * your project.
29 | */
30 |
31 | #include "pcg_basic.h"
32 |
33 | // state for global RNGs
34 |
35 | static pcg32_random_t pcg32_global = PCG32_INITIALIZER;
36 |
37 | // pcg32_srandom(initstate, initseq)
38 | // pcg32_srandom_r(rng, initstate, initseq):
39 | // Seed the rng. Specified in two parts, state initializer and a
40 | // sequence selection constant (a.k.a. stream id)
41 |
42 | void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate, uint64_t initseq)
43 | {
44 | rng->state = 0U;
45 | rng->inc = (initseq << 1u) | 1u;
46 | pcg32_random_r(rng);
47 | rng->state += initstate;
48 | pcg32_random_r(rng);
49 | }
50 |
51 | void pcg32_srandom(uint64_t seed, uint64_t seq)
52 | {
53 | pcg32_srandom_r(&pcg32_global, seed, seq);
54 | }
55 |
56 | // pcg32_random()
57 | // pcg32_random_r(rng)
58 | // Generate a uniformly distributed 32-bit random number
59 |
60 | uint32_t pcg32_random_r(pcg32_random_t* rng)
61 | {
62 | uint64_t oldstate = rng->state;
63 | rng->state = oldstate * 6364136223846793005ULL + rng->inc;
64 | uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
65 | uint32_t rot = oldstate >> 59u;
66 | return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
67 | }
68 |
69 | uint32_t pcg32_random()
70 | {
71 | return pcg32_random_r(&pcg32_global);
72 | }
73 |
74 |
75 | // pcg32_boundedrand(bound):
76 | // pcg32_boundedrand_r(rng, bound):
77 | // Generate a uniformly distributed number, r, where 0 <= r < bound
78 |
79 | uint32_t pcg32_boundedrand_r(pcg32_random_t* rng, uint32_t bound)
80 | {
81 | // To avoid bias, we need to make the range of the RNG a multiple of
82 | // bound, which we do by dropping output less than a threshold.
83 | // A naive scheme to calculate the threshold would be to do
84 | //
85 | // uint32_t threshold = 0x100000000ull % bound;
86 | //
87 | // but 64-bit div/mod is slower than 32-bit div/mod (especially on
88 | // 32-bit platforms). In essence, we do
89 | //
90 | // uint32_t threshold = (0x100000000ull-bound) % bound;
91 | //
92 | // because this version will calculate the same modulus, but the LHS
93 | // value is less than 2^32.
94 |
95 | uint32_t threshold = -bound % bound;
96 |
97 | // Uniformity guarantees that this loop will terminate. In practice, it
98 | // should usually terminate quickly; on average (assuming all bounds are
99 | // equally likely), 82.25% of the time, we can expect it to require just
100 | // one iteration. In the worst case, someone passes a bound of 2^31 + 1
101 | // (i.e., 2147483649), which invalidates almost 50% of the range. In
102 | // practice, bounds are typically small and only a tiny amount of the range
103 | // is eliminated.
104 | for (;;) {
105 | uint32_t r = pcg32_random_r(rng);
106 | if (r >= threshold)
107 | return r % bound;
108 | }
109 | }
110 |
111 |
112 | uint32_t pcg32_boundedrand(uint32_t bound)
113 | {
114 | return pcg32_boundedrand_r(&pcg32_global, bound);
115 | }
116 |
117 |
--------------------------------------------------------------------------------
/src/pcg_basic.h:
--------------------------------------------------------------------------------
1 | /*
2 | * PCG Random Number Generation for C.
3 | *
4 | * Copyright 2014 Melissa O'Neill
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | *
18 | * For additional information about the PCG random number generation scheme,
19 | * including its license and other licensing options, visit
20 | *
21 | * http://www.pcg-random.org
22 | */
23 |
24 | /*
25 | * This code is derived from the full C implementation, which is in turn
26 | * derived from the canonical C++ PCG implementation. The C++ version
27 | * has many additional features and is preferable if you can use C++ in
28 | * your project.
29 | */
30 |
31 | #ifndef PCG_BASIC_H_INCLUDED
32 | #define PCG_BASIC_H_INCLUDED 1
33 |
34 | #include
35 |
36 | #if __cplusplus
37 | extern "C" {
38 | #endif
39 |
40 | struct pcg_state_setseq_64 { // Internals are *Private*.
41 | uint64_t state; // RNG state. All values are possible.
42 | uint64_t inc; // Controls which RNG sequence (stream) is
43 | // selected. Must *always* be odd.
44 | };
45 | typedef struct pcg_state_setseq_64 pcg32_random_t;
46 |
47 | // If you *must* statically initialize it, here's one.
48 |
49 | #define PCG32_INITIALIZER { 0x853c49e6748fea9bULL, 0xda3e39cb94b95bdbULL }
50 |
51 | // pcg32_srandom(initstate, initseq)
52 | // pcg32_srandom_r(rng, initstate, initseq):
53 | // Seed the rng. Specified in two parts, state initializer and a
54 | // sequence selection constant (a.k.a. stream id)
55 |
56 | void pcg32_srandom(uint64_t initstate, uint64_t initseq);
57 | void pcg32_srandom_r(pcg32_random_t* rng, uint64_t initstate,
58 | uint64_t initseq);
59 |
60 | // pcg32_random()
61 | // pcg32_random_r(rng)
62 | // Generate a uniformly distributed 32-bit random number
63 |
64 | uint32_t pcg32_random(void);
65 | uint32_t pcg32_random_r(pcg32_random_t* rng);
66 |
67 | // pcg32_boundedrand(bound):
68 | // pcg32_boundedrand_r(rng, bound):
69 | // Generate a uniformly distributed number, r, where 0 <= r < bound
70 |
71 | uint32_t pcg32_boundedrand(uint32_t bound);
72 | uint32_t pcg32_boundedrand_r(pcg32_random_t* rng, uint32_t bound);
73 |
74 | #if __cplusplus
75 | }
76 | #endif
77 |
78 | #endif // PCG_BASIC_H_INCLUDED
79 |
--------------------------------------------------------------------------------
/src/random_sample.c:
--------------------------------------------------------------------------------
1 | /**************************************************************************
2 | * stat.c: Basic Statistics Functions
3 | *
4 | * Xianlong Wang, Ph.D.
5 | * University of Electronic Science and Technology of China.
6 | * Email: Wang.Xianlong@139.com
7 | *
8 | * Initialization. Nov. 11, 2016.
9 | **************************************************************************/
10 |
11 | #include
12 | #include
13 | #include "stat.h"
14 |
15 |
16 | int main(int argc, char* argv[]) {
17 | if(argc<3){
18 | printf("ERROR: Two few agruments!\n");
19 | printf("Usage: %s population_size sample_size\n", argv[0]);
20 | printf(" sample_size should be less than population_size and both should be non-negative integers.\n");
21 | exit(-1);
22 | }
23 | unsigned int n = atoi(argv[1]);
24 | unsigned int m = atoi(argv[2]);
25 | if(m>n||m==0||n==0){
26 | printf("ERROR: population size is less than sample size or one of them is 0!!\n");
27 | exit(-1);
28 | }
29 | unsigned int *sample;
30 | sample = malloc(sizeof(unsigned int)*m);
31 | int status;
32 | status = random_sample(n, m, sample);
33 | if(status==0){
34 | unsigned int i;
35 | for(i=0;i=MEMBLOCK*count_memblock)
83 | {
84 | count_memblock += 1;
85 | new_array = realloc(pairs[ithread], sizeof(struct pair)*MEMBLOCK*count_memblock);
86 | if(new_array) //avoid memory leak
87 | pairs[ithread] = new_array;
88 | else
89 | {
90 | fprintf(stderr, "# Memory is not allocated on thread %d.\n", ithread);
91 | exit(-1);
92 | }
93 | } //end if
94 |
95 | count=0; count0=0;
96 |
97 | #pragma omp simd
98 | for(k=0;k[j]
107 | {
108 | //insert to the pairs
109 | pairs[ithread][count_pairs[ithread]].h = i;
110 | pairs[ithread][count_pairs[ithread]].l = j;
111 | pairs[ithread][count_pairs[ithread]].count = count;
112 | count_pairs[ithread] += 1;
113 | exceptions[ithread][count] += 1;
114 | } //end if
115 | else if(m-count<=max && count0<=max0) // [i] <[j]
116 | {
117 | //insert to the pairs
118 | pairs[ithread][count_pairs[ithread]].h = j;
119 | pairs[ithread][count_pairs[ithread]].l = i;
120 | pairs[ithread][count_pairs[ithread]].count = m-count;
121 | count_pairs[ithread] += 1;
122 | //could be improved
123 | exceptions[ithread][m-count] += 1;
124 | } //end if
125 | }//end for j
126 | }//end for i
127 | }//end parallel
128 | //sum all the counts into exceptions[0]
129 |
130 | DATATYPE_SAMPLESIZE k;
131 | int ithread;
132 | for(k=0;k=MEMBLOCK*count_memblock)
186 | {
187 | count_memblock += 1;
188 | new_array = realloc(pairs[ithread], sizeof(UB8)*MEMBLOCK*count_memblock);
189 | if(new_array) //avoid memory leak
190 | pairs[ithread] = new_array;
191 | else
192 | {
193 | fprintf(stderr, "# Memory is not allocated on thread %d.\n", ithread);
194 | exit(-1);
195 | }
196 | } //end if
197 |
198 | count1 = 0; count01 = 0;
199 | count2 = 0; count02 = 0;
200 |
201 | #pragma omp simd
202 | for(k=0;k=MEMBLOCK*count_memblock)
297 | {
298 | count_memblock += 1;
299 | new_array = realloc(pairs[ithread], sizeof(UB8)*MEMBLOCK*count_memblock);
300 | if(new_array) //avoid memory leak
301 | pairs[ithread] = new_array;
302 | else
303 | {
304 | fprintf(stderr, "# Memory is not allocated on thread %d.\n", ithread);
305 | exit(-1);
306 | }
307 | } //end if
308 |
309 | count = 0; count0 = 0;
310 |
311 | #pragma omp simd
312 | for(k=0;k>22)) & 0x1FFFFF;//clear left bits
376 | j = ((unsigned int)(current >>43)) & 0x1FFFFF;
377 | switch(state)
378 | {
379 | case 1: // [i] > [j] in normal
380 | if (less(column[i], column[j]) == 1) // [i] < [j] in case
381 | state = 9; //1 + 8;
382 | else
383 | if (equal(column[i], column[j]) != 1)
384 | state = 5; // 1 + 4;
385 | break;
386 | case 2:// [i] < [j] in normal
387 | if (less(column[i], column[j]) == 1)// [i] < [j] in case
388 | state = 10; //2 + 8;
389 | else
390 | if (equal(column[i], column[j]) != 1)
391 | state = 6; // 2 + 4;
392 | break;
393 | } // end switch
394 | current = (UB8) state;
395 | current = current | ((UB8) i <<22);
396 | current = current | ((UB8) j <<43);
397 | pairs[ithread][index] = current;
398 | }// end for
399 | } //end parallel
400 |
401 | return EXIT_SUCCESS;
402 | }
403 |
404 | /****************************************************************************
405 | * Filter dys-regulated genes, judge directions, RanComp V2.0
406 | * Input: consistent pairs
407 | * Output: up and down-regulated genes
408 | *****************************************************************************/
409 | #define STATE_INC(i, ngv, nlv, cgv, clv) \
410 | if(states[i] != NULL){ \
411 | states[i]->ng += ngv; \
412 | states[i]->nl += nlv; \
413 | states[i]->cg += cgv; \
414 | states[i]->cl += clv; \
415 | } \
416 | else { \
417 | states[i] = malloc(sizeof(struct gene_state)); \
418 | states[i]->ng = ngv; \
419 | states[i]->nl = nlv; \
420 | states[i]->cg = cgv; \
421 | states[i]->cl = clv; \
422 | states[i]->state = 0; \
423 | }
424 | #define STATE_UPDATE(iv, jv) { \
425 | if (states[j]->state==0) \
426 | states[i]->iv += 1; \
427 | if (states[i]->state==0) \
428 | states[j]->jv += 1; \
429 | }
430 |
431 | int filter_gene_dirs(DATATYPE_GENESIZE n, //number of genes
432 | int nthreads,
433 | UB8 *pairs[nthreads],
434 | DATATYPE_GENESIZE count_pairs[nthreads],
435 | struct gene_state *states[n],
436 | double alpha, //FDR alpha level for regulation direction
437 | int max_cycles,
438 | int conv_threshold
439 | )
440 | {
441 | unsigned int i, j;
442 |
443 | //initialization of gene states
444 | for(i=0; i>22)) & 0x1FFFFF;//clear left bits
452 | unsigned int c2 = ((unsigned int)(current >>43)) & 0x1FFFFF;
453 |
454 | switch(state){
455 | case 5: // 1 + 4, [i]>[j] in both
456 | STATE_INC(c1, 0, 1, 0, 0)
457 | STATE_INC(c2, 1, 0, 0, 0)
458 | STATE_INC(c1, 0, 0, 0, 1)
459 | STATE_INC(c2, 0, 0, 1, 0)
460 | break;
461 | case 10:// 2 + 8, [i]<[j] in both
462 | STATE_INC(c1, 1, 0, 0, 0)
463 | STATE_INC(c2, 0, 1, 0, 0)
464 | STATE_INC(c1, 0, 0, 1, 0)
465 | STATE_INC(c2, 0, 0, 0, 1)
466 | break;
467 | // Stable in the two groups, different direction
468 | case 6: // 2 + 4
469 | STATE_INC(c1, 1, 0, 0, 0)
470 | STATE_INC(c2, 0, 1, 0, 0)
471 | STATE_INC(c1, 0, 0, 0, 1)
472 | STATE_INC(c2, 0, 0, 1, 0)
473 | break;
474 | case 9: // 1 + 8
475 | STATE_INC(c1, 0, 1, 0, 0)
476 | STATE_INC(c2, 1, 0, 0, 0)
477 | STATE_INC(c1, 0, 0, 1, 0)
478 | STATE_INC(c2, 0, 0, 0, 1)
479 | break;
480 | case 0: //other, remove
481 | break;
482 | } //end switch
483 | }//end if
484 | }//end double-for
485 |
486 | //screening for up or down direction using the two-tailed hypergeometric test
487 | int cycles = 0;
488 | double *pvalues;
489 | double p_upper;
490 | int gene_up=BIGNINT, gene_down=BIGNINT, gene_flat=BIGNINT;
491 | int gene_up_pre, gene_down_pre, gene_flat_pre;
492 |
493 | do {
494 | int count = 0;
495 | //two-tailed hypergeometric test
496 | #pragma omp parallel for reduction(+:count)
497 | for(i=0;ip = fisher_test( (int) states[i]->ng, (int) states[i]->nl,
501 | (int) states[i]->cg, (int) states[i]->cl);
502 | count += 1;
503 | } //end if
504 |
505 | // copy p values to pvalues
506 | fprintf(stdout, "# Cycle %d, %d genes have been tested using the Fisher exact test (aka. two-tail hypergeometric test).\n", cycles, count);
507 |
508 | pvalues = malloc(sizeof(double)*count);
509 | count = 0;
510 | for(i=0;ip;
513 |
514 | //FDR control
515 | p_upper = bh_threshold(count, pvalues, alpha);
516 | fprintf(stdout, "# FDR = %f controlled P value threshold, %.17g. \n", alpha, p_upper);
517 | free(pvalues);
518 |
519 | //assign states
520 | gene_up_pre = gene_up;
521 | gene_down_pre = gene_down;
522 | gene_flat_pre = gene_flat;
523 | gene_up = 0;
524 | gene_down = 0;
525 | gene_flat = 0;
526 | #pragma omp parallel for reduction(+:gene_up,gene_down,gene_flat)
527 | for(i=0;ip)ng+1.0e-5)/(states[i]->nl+1.0e-5)) <
531 | ((states[i]->cg+1.0e-5)/(states[i]->cl+1.0e-5)))
532 | {
533 | states[i]->state = 1;
534 | gene_down += 1;
535 | }
536 | else {
537 | states[i]->state = 2;
538 | gene_up += 1;
539 | }
540 | }
541 | else {
542 | states[i]->state = 0;
543 | gene_flat += 1;
544 | }
545 | } //end if for
546 | fprintf(stdout, "# %d genes have been tested as up-regulated.\n", gene_up);
547 | fprintf(stdout, "# %d genes have been tested as down-regulated.\n", gene_down);
548 | fprintf(stdout, "# %d genes have no particular direction.\n", gene_flat);
549 |
550 | //count ng, nl, cg and cl, if gene_state is 0 (flat).
551 | //clear first
552 | #pragma omp parallel for
553 | for(i=0;ing = 0;
556 | states[i]->nl = 0;
557 | states[i]->cg = 0;
558 | states[i]->cl = 0;
559 | }
560 |
561 | #pragma omp parallel
562 | {
563 | int ithread = omp_get_thread_num();
564 | unsigned int index, i, j;
565 | unsigned char state;
566 | UB8 current;
567 | for(index=0;index>22)) & 0x1FFFFF;//clear left bits
572 | j = ((unsigned int)(current >>43)) & 0x1FFFFF;
573 | #pragma omp critical
574 | switch(state){
575 | case 5: // 1 + 4, [i]>[j]
576 | STATE_UPDATE(nl, ng)
577 | STATE_UPDATE(cl, cg)
578 | break;
579 | case 10:// 2 + 8, [i]<[j]
580 | STATE_UPDATE(ng, nl)
581 | STATE_UPDATE(cg, cl)
582 | break;
583 | // Stable in the two groups, different direction
584 | case 6: // 2 + 4
585 | STATE_UPDATE(ng, nl)
586 | STATE_UPDATE(cl, cg)
587 | break;
588 | case 9: // 1 + 8
589 | STATE_UPDATE(nl, ng)
590 | STATE_UPDATE(cg, cl)
591 | break;
592 | } // end switch
593 | }// end for
594 | } //end parallel
595 | cycles +=1;
596 | } while(cyclesconv_threshold|| \
597 | abs(gene_up-gene_up_pre) >conv_threshold|| \
598 | abs(gene_down-gene_down_pre)>conv_threshold));
599 |
600 |
601 | if(abs(gene_flat-gene_flat_pre)<=conv_threshold &&
602 | abs(gene_up-gene_up_pre) <=conv_threshold &&
603 | abs(gene_down-gene_down_pre)<=conv_threshold)
604 | fprintf(stdout, "# Convergence has been reached after %d cycles.\n", cycles);
605 | else
606 | fprintf(stdout, "# Max cycles %d have been exceeded before the convergence.\n", max_cycles);
607 |
608 | return EXIT_SUCCESS;
609 | }//end filter_gene_dirs
610 |
611 | /*******************************
612 | * Modify of filter_gene_dirs for one sample only
613 | * 1) serial mode only;
614 | * 2) filter background gene pairs each iteration avoding the creation of the new filtered pairs
615 | * 3) RankComp V2.0 algorithum
616 | *******************************/
617 | int filter_deg_one(DATATYPE_GENESIZE np, //number of gene pairs
618 | struct pair0 pairs[np],
619 | DATATYPE_GENESIZE ng,
620 | int size,
621 | DATATYPE_VALUE control[ng*size],
622 | DATATYPE_VALUE treated[ng],
623 | struct gene_state *states[ng],
624 | double alpha, //FDR alpha level for regulation direction
625 | int max_cycles,
626 | int conv_threshold
627 | )
628 | {
629 | unsigned int i;
630 |
631 | /* loop over all predetermined pairs */
632 | for(i=0; ip = fisher_test( (int) states[i]->ng, (int) states[i]->nl,
674 | (int) states[i]->cg, (int) states[i]->cl);
675 | count += 1;
676 | } //end if
677 |
678 | // copy p values to pvalues
679 | fprintf(stdout, "# Cycle %d, %d genes have been tested using the Fisher exact test (aka. two-tail hypergeometric test).\n", cycles, count);
680 |
681 | pvalues = malloc(sizeof(double)*count);
682 | count = 0;
683 | for(i=0; ip;
686 |
687 | //FDR control
688 | p_upper = bh_threshold(count, pvalues, alpha);
689 | fprintf(stdout, "# FDR = %f controlled P value threshold, %.17g. \n", alpha, p_upper);
690 | free(pvalues);
691 |
692 | //assign states
693 | gene_up_pre = gene_up;
694 | gene_down_pre = gene_down;
695 | gene_flat_pre = gene_flat;
696 | gene_up = 0;
697 | gene_down = 0;
698 | gene_flat = 0;
699 | for(i=0; ip)ng+1.0e-5)/(states[i]->nl+1.0e-5)) <
703 | ((states[i]->cg+1.0e-5)/(states[i]->cl+1.0e-5)))
704 | {
705 | states[i]->state = 1;
706 | gene_down += 1;
707 | }
708 | else {
709 | states[i]->state = 2;
710 | gene_up += 1;
711 | }
712 | }
713 | else {
714 | states[i]->state = 0;
715 | gene_flat += 1;
716 | }
717 | } //end if for
718 | fprintf(stdout, "# %d genes have been tested as up-regulated.\n", gene_up);
719 | fprintf(stdout, "# %d genes have been tested as down-regulated.\n", gene_down);
720 | fprintf(stdout, "# %d genes have no particular direction.\n", gene_flat);
721 |
722 | //count ng, nl, cg and cl, if gene_state is 0 (flat).
723 | //clear first
724 | for(i=0; ing = 0;
727 | states[i]->nl = 0;
728 | states[i]->cg = 0;
729 | states[i]->cl = 0;
730 | }
731 |
732 | /* new iteration */
733 | /* loop over all predetermined pairs */
734 | for(i=0; istate==0)
748 | {
749 | states[h]->nl += 1;
750 | states[h]->cl += 1;
751 | }
752 | if (states[h]->state==0)
753 | {
754 | states[l]->ng += 1;
755 | states[l]->cg += 1;
756 | }
757 | }
758 | else if (less(treated[h], treated[l]) == 1)
759 | {//reversed pair
760 | if (states[l]->state==0)
761 | {
762 | states[h]->nl += 1;
763 | states[h]->cg += 1;
764 | }
765 | if (states[h]->state==0)
766 | {
767 | states[l]->ng += 1;
768 | states[l]->cl += 1;
769 | }
770 | }
771 | }//end if
772 | }//end for
773 |
774 | cycles +=1;
775 | } while(cyclesconv_threshold|| \
776 | abs(gene_up-gene_up_pre) >conv_threshold|| \
777 | abs(gene_down-gene_down_pre)>conv_threshold));
778 |
779 |
780 | if(abs(gene_flat-gene_flat_pre)<=conv_threshold &&
781 | abs(gene_up-gene_up_pre) <=conv_threshold &&
782 | abs(gene_down-gene_down_pre)<=conv_threshold)
783 | fprintf(stdout, "# Convergence has been reached after %d cycles.\n", cycles);
784 | else
785 | fprintf(stdout, "# Max cycles %d have been exceeded before the convergence.\n", max_cycles);
786 |
787 | return EXIT_SUCCESS;
788 | }//end filter_deg_one
789 |
790 |
791 | /****************************************************************************
792 | * Filter dys-regulated genes, judge directions, RanComp original
793 | * Input: consistent pairs
794 | * Output: up and down-regulated genes
795 | *****************************************************************************/
796 | //Direction up or down?
797 | #define STATE_IN2(i,vi,j,vj) \
798 | if(states[i] != NULL){ \
799 | states[i]->vi += 1; \
800 | } \
801 | else { \
802 | states[i] = malloc(sizeof(struct gene_state2)); \
803 | states[i]->ng = 0; \
804 | states[i]->nl = 0; \
805 | states[i]->g2l = 0; \
806 | states[i]->l2g = 0; \
807 | states[i]->state = 0; \
808 | states[i]->vi += 1; \
809 | } \
810 | if(states[j] != NULL){ \
811 | states[j]->vj += 1; \
812 | } \
813 | else { \
814 | states[j] = malloc(sizeof(struct gene_state2)); \
815 | states[j]->ng = 0; \
816 | states[j]->nl = 0; \
817 | states[j]->g2l = 0; \
818 | states[j]->l2g = 0; \
819 | states[j]->state = 0; \
820 | states[j]->vj += 1; \
821 | }
822 |
823 | int filter_gene_orig(DATATYPE_GENESIZE n, //number of genes
824 | int nthreads,
825 | UB8 *pairs[nthreads],
826 | DATATYPE_GENESIZE count_pairs[nthreads],
827 | struct gene_state2 *states[n],
828 | double alpha, //FDR alpha level for regulation direction
829 | int max_cycles,
830 | int conv_threshold
831 | )
832 | {
833 |
834 | unsigned int i, j;
835 |
836 | //initialization of gene states
837 | for(i=0; i>22)) & 0x1FFFFF;//clear left bits
844 | unsigned int c2 = ((unsigned int)(current >>43)) & 0x1FFFFF;
845 |
846 | switch(state){
847 | case 5: // 1 + 4, [i] > [j]
848 | STATE_IN2(c1, nl, c2, ng)
849 | break;
850 | case 10:// 2 + 8, [i] < [j]
851 | STATE_IN2(c1, ng, c2, nl)
852 | break;
853 | // Stable in the two groups, different direction
854 | case 6: // 2 + 4
855 | STATE_IN2(c1, ng, c2, nl)
856 | STATE_IN2(c1, g2l, c2, l2g)
857 | break;
858 | case 9: // 1 + 8
859 | STATE_IN2(c1, nl, c2, ng)
860 | STATE_IN2(c1, l2g, c2, g2l)
861 | break;
862 | case 0: //other, remove
863 | break;
864 | } //end switch
865 | } //end if
866 |
867 | int cycles = 0;
868 | double *pvalues;
869 | double p_upper;
870 | int gene_up=BIGNINT, gene_down=BIGNINT, gene_flat=BIGNINT;
871 | int gene_up_pre, gene_down_pre, gene_flat_pre;
872 | do {
873 | int count = 0;
874 | //two-tailed hypergeometric test
875 | #pragma omp parallel for reduction(+:count)
876 | for(i=0;ip =fisher_test((int) states[i]->ng, (int) states[i]->nl,
880 | (int) states[i]->ng + states[i]->l2g - states[i]->g2l,
881 | (int) states[i]->nl - states[i]->l2g + states[i]->g2l
882 | );
883 | count += 1;
884 | } //end if
885 |
886 | // copy p values to pvalues
887 | printf("# Cycle %d, %d genes have been tested using the Fisher exact test (aka. two-tail hypergeometric test). \n", cycles, count);
888 |
889 | pvalues = malloc(sizeof(double)*count);
890 | count = 0;
891 | for(i=0;ip;
894 |
895 | //FDR control
896 | p_upper = bh_threshold(count, pvalues, alpha);
897 | printf("# FDR = %f controlled P value threshold, %.17g. \n", alpha, p_upper);
898 | free(pvalues);
899 | //assign states
900 | gene_up_pre = gene_up;
901 | gene_down_pre = gene_down;
902 | gene_flat_pre = gene_flat;
903 | gene_up = 0;
904 | gene_down = 0;
905 | gene_flat = 0;
906 | #pragma omp parallel for reduction(+:gene_up,gene_down,gene_flat)
907 | for(i=0;ip)ng;
913 | b = (double) states[i]->nl;
914 | c = (double) states[i]->ng + states[i]->l2g - states[i]->g2l;
915 | d = (double) states[i]->nl - states[i]->l2g + states[i]->g2l;
916 |
917 | if(((a+1.0e-5)/(b+1.0e-5)) < ((c+1.0e-5)/(d +1.0e-5))) {
918 | states[i]->state = 1;
919 | gene_down += 1;
920 | }
921 | else {
922 | states[i]->state = 2;
923 | gene_up += 1;
924 | }
925 | }
926 | else {
927 | states[i]->state = 0;
928 | gene_flat += 1;
929 | }
930 | } //end if for
931 | printf("# %d genes have been tested as up-regulated.\n", gene_up);
932 | printf("# %d genes have been tested as down-regulated.\n", gene_down);
933 | printf("# %d genes have no particular direction.\n", gene_flat);
934 |
935 | //count ng, nl, cg and cl, if gene_state is 0 (flat).
936 | //clear first
937 | #pragma omp parallel for
938 | for(i=0;ig2l = 0;
941 | states[i]->l2g = 0;
942 | }
943 |
944 | #pragma omp parallel
945 | {
946 | int ithread = omp_get_thread_num();
947 | unsigned int index, i, j;
948 | unsigned char state;
949 | UB8 current;
950 | for(index=0;index>22)) & 0x1FFFFF;//clear left bits
955 | j = ((unsigned int)(current >>43)) & 0x1FFFFF;
956 | #pragma omp critical
957 | switch(state)
958 | {
959 | // Stable in the two groups, different direction
960 | case 6: // 2 + 4, reverse, [i]<[j] -> [i]>[j]
961 | if (states[i]->state !=2) //if i is up-regulated, i is not counted as g2l for j
962 | states[j]->l2g += 1;
963 |
964 | if (states[j]->state !=1) //if j is down-regulated, j is not counted as l2g for i
965 | states[i]->g2l += 1;
966 | break;
967 | case 9: // 1 + 8, reverse [i]>[j] -> [i]<[j]
968 | if (states[i]->state !=1) //if i is down-regulated, i is not counted as l2g for j
969 | states[j]->g2l += 1;
970 |
971 | if (states[j]->state !=2) //if i is up-regulated, i is not counted as g2l for j
972 | states[i]->l2g += 1;
973 | break;
974 | } // end switch
975 | }// end for
976 | }//end parallel
977 | cycles +=1;
978 | } while(cyclesconv_threshold|| \
979 | abs(gene_up-gene_up_pre)>conv_threshold || \
980 | abs(gene_down-gene_down_pre)>conv_threshold));
981 |
982 | if(abs(gene_flat-gene_flat_pre)<=conv_threshold &&
983 | abs(gene_up-gene_up_pre) <=conv_threshold &&
984 | abs(gene_down-gene_down_pre)<=conv_threshold)
985 | printf("# Convergence has been reached after %d cycles.\n", cycles);
986 | else
987 | printf("# Max cycles %d have been exceeded before the convergence.\n", max_cycles);
988 |
989 | return EXIT_SUCCESS;
990 | }// end filter_gene_orig
991 |
992 |
993 | /* Modified filter_deg_one function: Original RankComp Algo. */
994 | int filter_deg_one_orig(DATATYPE_GENESIZE np, //number of gene pairs
995 | struct pair0 pairs[np],
996 | DATATYPE_GENESIZE ng,
997 | int size,
998 | DATATYPE_VALUE control[ng*size],
999 | DATATYPE_VALUE treated[ng],
1000 | struct gene_state2 *states[ng],
1001 | double alpha, //FDR alpha level for regulation direction
1002 | int max_cycles,
1003 | int conv_threshold
1004 | )
1005 | {
1006 | unsigned int i;
1007 |
1008 | /* loop over all predetermined pairs */
1009 | for(i=0; i l --> h < l
1026 | STATE_IN2(h, nl, l, ng)
1027 | STATE_IN2(l, g2l, h, l2g)
1028 | }
1029 | }//end if
1030 | }//end for
1031 |
1032 | /* screening DEGs using the two-tailed hypergeometric test */
1033 | int cycles = 0;
1034 | double *pvalues;
1035 | double p_upper;
1036 | int gene_up=BIGNINT, gene_down=BIGNINT, gene_flat=BIGNINT;
1037 | int gene_up_pre, gene_down_pre, gene_flat_pre;
1038 |
1039 | do {
1040 | int count = 0;
1041 | //two-tailed hypergeometric test
1042 | for(i=0; ip =fisher_test((int) states[i]->ng, (int) states[i]->nl,
1046 | (int) states[i]->ng + states[i]->l2g - states[i]->g2l,
1047 | (int) states[i]->nl - states[i]->l2g + states[i]->g2l
1048 | );
1049 | count += 1;
1050 | } //end if
1051 |
1052 | // copy p values to pvalues
1053 | fprintf(stdout, "# Cycle %d, %d genes have been tested using the Fisher exact test (aka. two-tail hypergeometric test).\n", cycles, count);
1054 |
1055 | pvalues = malloc(sizeof(double)*count);
1056 | count = 0;
1057 | for(i=0; ip;
1060 |
1061 | //FDR control
1062 | p_upper = bh_threshold(count, pvalues, alpha);
1063 | fprintf(stdout, "# FDR = %f controlled P value threshold, %.17g. \n", alpha, p_upper);
1064 | free(pvalues);
1065 |
1066 | //assign states
1067 | gene_up_pre = gene_up;
1068 | gene_down_pre = gene_down;
1069 | gene_flat_pre = gene_flat;
1070 | gene_up = 0;
1071 | gene_down = 0;
1072 | gene_flat = 0;
1073 | for(i=0; ip)ng;
1078 | b = (double) states[i]->nl;
1079 | c = (double) states[i]->ng + states[i]->l2g - states[i]->g2l;
1080 | d = (double) states[i]->nl - states[i]->l2g + states[i]->g2l;
1081 |
1082 | if(((a+1.0e-5)/(b+1.0e-5)) < ((c+1.0e-5)/(d +1.0e-5))) {
1083 | states[i]->state = 1;
1084 | gene_down += 1;
1085 | }
1086 | else {
1087 | states[i]->state = 2;
1088 | gene_up += 1;
1089 | }
1090 | }
1091 | else {
1092 | states[i]->state = 0;
1093 | gene_flat += 1;
1094 | }
1095 | } //end if for
1096 | fprintf(stdout, "# %d genes have been tested as up-regulated.\n", gene_up);
1097 | fprintf(stdout, "# %d genes have been tested as down-regulated.\n", gene_down);
1098 | fprintf(stdout, "# %d genes have no particular direction.\n", gene_flat);
1099 |
1100 | //count ng, nl, cg and cl, if gene_state is 0 (flat).
1101 | //clear first
1102 | for(i=0; ig2l = 0;
1105 | states[i]->l2g = 0;
1106 | }
1107 |
1108 | /* new iteration */
1109 | /* loop over all predetermined pairs */
1110 | for(i=0; i h > l
1122 | //reversed pair
1123 | if (states[l]->state != 2)
1124 | states[h]->l2g += 1;
1125 |
1126 | if (states[h]->state !=1)
1127 | states[l]->g2l += 1;
1128 |
1129 | }//end if
1130 | }//end for
1131 |
1132 | cycles +=1;
1133 | } while(cyclesconv_threshold|| \
1134 | abs(gene_up-gene_up_pre) >conv_threshold|| \
1135 | abs(gene_down-gene_down_pre)>conv_threshold));
1136 |
1137 |
1138 | if(abs(gene_flat-gene_flat_pre)<=conv_threshold &&
1139 | abs(gene_up-gene_up_pre) <=conv_threshold &&
1140 | abs(gene_down-gene_down_pre)<=conv_threshold)
1141 | fprintf(stdout, "# Convergence has been reached after %d cycles.\n", cycles);
1142 | else
1143 | fprintf(stdout, "# Max cycles %d have been exceeded before the convergence.\n", max_cycles);
1144 |
1145 | return EXIT_SUCCESS;
1146 | }//end filter_deg_one
1147 |
1148 |
1149 | #define STATE_IN3(i, cgv, clv, g2lv, l2gv) \
1150 | if(states[i] != NULL){ \
1151 | states[i]->cg += cgv; \
1152 | states[i]->cl += clv; \
1153 | states[i]->g2l += g2lv; \
1154 | states[i]->l2g += l2gv; \
1155 | } \
1156 | else { \
1157 | states[i] = malloc(sizeof(struct gene_state3)); \
1158 | states[i]->cg = cgv; \
1159 | states[i]->cl = clv; \
1160 | states[i]->g2l = g2lv; \
1161 | states[i]->l2g = l2gv; \
1162 | states[i]->state = 0; \
1163 | }
1164 |
1165 | int filter_gene_bayesian(DATATYPE_GENESIZE n, //number of genes
1166 | int nthreads,
1167 | UB8 *pairs[nthreads],
1168 | DATATYPE_GENESIZE count_pairs[nthreads],
1169 | struct gene_state3 *states[n]/*,
1170 | double alpha, //FDR alpha level for regulation direction
1171 | int max_cycles,
1172 | int conv_threshold*/
1173 | )
1174 | {
1175 | DATATYPE_GENESIZE i, j;
1176 |
1177 | //initialization of gene states
1178 | for(i=0;i>22)) & 0x1FFFFF;//clear left bits
1186 | unsigned int c2 = ((unsigned int)(current >>43)) & 0x1FFFFF;
1187 |
1188 | switch(state){
1189 | case 5: // 1 + 4, [i]>[j], cl for i, cg for j
1190 | STATE_IN3(c1, 0, 1, 0, 0)
1191 | STATE_IN3(c2, 1, 0, 0, 0)
1192 | break;
1193 | case 10:// 2 + 8, [i]<[j], cg for i and cl for j
1194 | STATE_IN3(c1, 1, 0, 0, 0)
1195 | STATE_IN3(c2, 0, 1, 0, 0)
1196 | break;
1197 | // Stable in the two groups, different direction
1198 | case 6: // 2 + 4, [i]<[j] to [i]>[j], g2l for i, l2g for j
1199 | STATE_IN3(c1, 0, 0, 1, 0)
1200 | STATE_IN3(c2, 0, 0, 0, 1)
1201 | break;
1202 | case 9: // 1 + 8, [i]>[j] to [i]<[j], l2g for i, g2l for j
1203 | STATE_IN3(c1, 0, 0, 0, 1)
1204 | STATE_IN3(c2, 0, 0, 1, 0)
1205 | break;
1206 | case 0: //other, remove
1207 | break;
1208 | } //end switch
1209 | }//end if
1210 | }//end double-for
1211 |
1212 | return EXIT_SUCCESS;
1213 | }//end filter_gene_dirs
1214 |
1215 |
1216 |
1217 |
1218 | int gen_random_sample( DATATYPE_GENESIZE n, //number of genes
1219 | DATATYPE_SAMPLESIZE m, //sample size
1220 | DATATYPE_VALUE normal[n*m], //data matrix
1221 | DATATYPE_VALUE cases[n*m], //to be generated
1222 | DATATYPE_GENESIZE n_changes,
1223 | struct CHANGE changes[n_changes],
1224 | FILE *out_file
1225 | )
1226 | {
1227 | DATATYPE_GENESIZE i, total_changes=0, current_group=0, current_sum=0;
1228 |
1229 | for(i=0;in) {
1233 | fprintf(stderr, "ERROR: Number of changes exceed the number of gene genes.\n");
1234 | exit(EXIT_FAILURE);
1235 | }
1236 | DATATYPE_GENESIZE *sample;
1237 | sample = malloc(sizeof(DATATYPE_GENESIZE)*total_changes);
1238 | random_sample(n, total_changes, sample);//initialization is done inside the function
1239 |
1240 | //assign the sample to each category
1241 | DATATYPE_SAMPLESIZE j;
1242 | for(i=0;i
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "stat.h"
8 |
9 | #define DATATYPE_VALUE float
10 | #define DATATYPE_SAMPLESIZE int
11 | #define DATATYPE_GENESIZE unsigned int
12 | #define CONV_THRESHOLD 50
13 | #define MEMBLOCK 1024
14 | #define BIGNINT -1000000
15 | #define MASK_FDR 0b00000001
16 | #define MASK_FILTER 0b00000010
17 | #define MAX_FILES 255
18 | #define MAX_SAMPLESIZE 255
19 | #define DEFAULT_FDR 0.05
20 |
21 | //plain pair
22 | struct pair0 {
23 | DATATYPE_GENESIZE h, l;
24 | };
25 |
26 | //for one sample only
27 | struct pair {
28 | DATATYPE_GENESIZE h, l;
29 | DATATYPE_SAMPLESIZE count;
30 | };
31 |
32 | //for two samples, without count information, after FDR control or exceptions thresholding
33 | struct pair2 {
34 | DATATYPE_GENESIZE i, j;
35 | unsigned char state; //1 for ij; lower bit for sample 1, higer bit for sample 2
36 | //0b00 = 0, i>j in both samples, 0b11=3, ij in sample 2
38 | //0b10 = 2, i>j in sample 1, but i' test, 2-3 for '=' test
81 | // 0 - if count < threshold in normal group (sample 1)
82 | // 1 - if m-count < threshold in normal group (sample 1)
83 | // 2 - if count < threshold in case group (sample 2)
84 | // 3 - if m-count < threshold in case group (sample 2)
85 | // 4 - if count0 < threshold in normal group (sample 1)
86 | // 5 - if count0 < threshold in case group (sample 2)
87 | // 6-13, nx, count of <|> (smaller one) in normal group, capacity 2^8-1 = 255
88 | // 14-21, cx, ibid in case group, sample size 255*2=510
89 | // 22-42, gi, gene index, capacity, 2097151 (2097k) gene number
90 | // 43-63, gj, gene index
91 | typedef long unsigned int UB8;
92 |
93 | bool VERBOSE;
94 | double EPSILON;
95 |
96 | struct CHANGE
97 | {
98 | DATATYPE_GENESIZE n; // number of genes
99 | float level; // change level, Fold-Change (FC)
100 | };
101 |
102 | int less(DATATYPE_VALUE a, DATATYPE_VALUE b);
103 | int equal(DATATYPE_VALUE a, DATATYPE_VALUE b);
104 |
105 | //Stable gene-pair ordering for one sample
106 | int stable_pairs_one(DATATYPE_GENESIZE n, //number of genes
107 | DATATYPE_SAMPLESIZE m, //sample size
108 | DATATYPE_VALUE data[n*m], //data matrix
109 | DATATYPE_SAMPLESIZE max,//threshold, max number of exceptions
110 | DATATYPE_GENESIZE max0, //max allowed number of equal pairs
111 | int nthreads,
112 | struct pair *pairs[nthreads],
113 | DATATYPE_GENESIZE count_pairs[nthreads],
114 | int *exceptions[nthreads]//for FDR control, number of pairs with the specified number of exceptions
115 | );
116 |
117 | //Stable gene-pair ordering for two samples;
118 | //Concordant and reversed pairs
119 | int stable_pairs_two(DATATYPE_GENESIZE n, //number of genes
120 | DATATYPE_SAMPLESIZE m1, //sample size
121 | DATATYPE_VALUE data1[n*m1], //data matrix
122 | DATATYPE_SAMPLESIZE max1,//threshold, max number of exceptions
123 | DATATYPE_SAMPLESIZE m2, //sample size
124 | DATATYPE_VALUE data2[n*m2], //data matrix
125 | DATATYPE_SAMPLESIZE max2,//threshold, max number of exceptions
126 | DATATYPE_GENESIZE max0, //max allowed number of equal pairs
127 | int nthreads,
128 | UB8 *pairs[nthreads],
129 | DATATYPE_GENESIZE count_pairs[nthreads],
130 | int *exceptions1[nthreads],//for FDR control, number of pairs with the specified number of exceptions
131 | int *exceptions2[nthreads]//for FDR control, number of pairs with the specified number of exceptions
132 | );
133 |
134 | /* Stable gene-pair ordering for one sample, using UB8 */
135 | int stable_pairs_one2(DATATYPE_GENESIZE n, //number of genes
136 | DATATYPE_SAMPLESIZE m, //sample size
137 | DATATYPE_VALUE data[n*m], //data matrix
138 | DATATYPE_SAMPLESIZE max,//threshold, max number of exceptions
139 | DATATYPE_GENESIZE max0, //max allowed number of equal pairs
140 | int nthreads,
141 | UB8 *pairs[nthreads],
142 | DATATYPE_GENESIZE count_pairs[nthreads],
143 | int *exceptions[nthreads]//for FDR control, number of pairs with the specified number of exceptions
144 | );
145 |
146 | /* Stable gene-pair ordering for two samples,
147 | * the second sample is one column, individual sample,
148 | * stable pairs for the first sample is already given*/
149 | int stable_pairs_ind(DATATYPE_GENESIZE n, //number of genes
150 | int nthreads,
151 | UB8 *pairs[nthreads],
152 | DATATYPE_GENESIZE count_pairs[nthreads],
153 | DATATYPE_VALUE column[n] //data matrix
154 | );
155 |
156 | int filter_gene_dirs(DATATYPE_GENESIZE n, //number of genes
157 | int nthreads,
158 | UB8 *pairs[nthreads],
159 | DATATYPE_GENESIZE count_pairs[nthreads],
160 | struct gene_state *states[n],
161 | double alpha, //FDR alpha level for regulation direction
162 | int max_cycles,
163 | int conv_threshold
164 | );
165 |
166 | int filter_gene_orig(DATATYPE_GENESIZE n, //number of genes
167 | int nthreads,
168 | UB8 *pairs[nthreads],
169 | DATATYPE_GENESIZE count_pairs[nthreads],
170 | struct gene_state2 *states[n],
171 | double alpha, //FDR alpha level for regulation direction
172 | int max_cycles,
173 | int conv_threshold
174 | );
175 |
176 | int filter_gene_bayesian(DATATYPE_GENESIZE n, //number of genes
177 | int nthreads,
178 | UB8 *pairs[nthreads],
179 | DATATYPE_GENESIZE count_pairs[nthreads],
180 | struct gene_state3 *states[n]/*,
181 | double alpha, //FDR alpha level for regulation direction
182 | int max_cycles,
183 | int conv_threshold*/
184 | );
185 |
186 |
187 | int filter_deg_one(DATATYPE_GENESIZE np, //number of gene pairs
188 | struct pair0 pairs[np],
189 | DATATYPE_GENESIZE ng,
190 | int size,
191 | DATATYPE_VALUE control[ng*size],
192 | DATATYPE_VALUE treated[ng],
193 | struct gene_state *states[ng],
194 | double alpha, //FDR alpha level for regulation direction
195 | int max_cycles,
196 | int conv_threshold
197 | );
198 |
199 | /* Modified filter_deg_one function: Original RankComp Algo. */
200 | int filter_deg_one_orig(DATATYPE_GENESIZE np, //number of gene pairs
201 | struct pair0 pairs[np],
202 | DATATYPE_GENESIZE ng,
203 | int size,
204 | DATATYPE_VALUE control[ng*size],
205 | DATATYPE_VALUE treated[ng],
206 | struct gene_state2 *states[ng],
207 | double alpha, //FDR alpha level for regulation direction
208 | int max_cycles,
209 | int conv_threshold
210 | );
211 |
212 | int gen_random_sample( DATATYPE_GENESIZE n, //number of genes
213 | DATATYPE_SAMPLESIZE m, //sample size
214 | DATATYPE_VALUE normal[n*m], //data matrix
215 | DATATYPE_VALUE cases[n*m], //to be generated
216 | DATATYPE_GENESIZE n_changes,
217 | struct CHANGE changes[n_changes],
218 | FILE *out_file
219 | );
220 |
221 | DATATYPE_GENESIZE similarity_between_two_cols( DATATYPE_GENESIZE n, //number of genes
222 | DATATYPE_VALUE col1[n], // first column data
223 | DATATYPE_VALUE col2[n] // second column
224 | );
225 |
--------------------------------------------------------------------------------
/src/stat.c:
--------------------------------------------------------------------------------
1 | /**************************************************************************
2 | * stat.c: Basic Statistics Functions
3 | *
4 | * Xianlong Wang, Ph.D.
5 | * University of Electronic Science and Technology of China.
6 | * Email: Wang.Xianlong@139.com
7 | *
8 | * Initialization. Oct. 25, 2016.
9 | **************************************************************************/
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 | //#include
17 | #include "bino.h" // bino_table, Binomial Cumulated Probability Table (Fair Coin)
18 | #include "stat.h"
19 | //PCG Random Number Generator. See http://www.pcg-random.org/
20 | //#include
21 | //#include
22 | //#include "pcg_basic.h"
23 |
24 | //WARNING: OS dependent?
25 | bool entropy_get(void* dest, size_t n)
26 | {
27 | FILE* fd = fopen("/dev/urandom", "r");
28 | if (fd == NULL)
29 | return false;
30 | size_t sz=fread(dest, sizeof(uint64_t), n, fd);
31 | if(sz
77 | // unsigned int random_uint(unsigned int limit) {
78 | // union {
79 | // unsigned int i;
80 | // unsigned char c[sizeof(unsigned int)];
81 | // } u;
82 | //
83 | // do {
84 | // if (!RAND_bytes(u.c, sizeof(u.c))) {
85 | // fprintf(stderr, "Can't get random bytes!\n");
86 | // exit(1);
87 | // }
88 | // } while (u.i < (-limit % limit)); /* u.i < (2**size % limit) */
89 | // return u.i % limit;
90 | // }
91 | //
92 | // /* random double in [0.0, 1.0) */
93 | // double random_double() {
94 | // union {
95 | // uint64_t i;
96 | // unsigned char c[sizeof(uint64_t)];
97 | // } u;
98 | // if (!RAND_bytes(u.c, sizeof(u.c))) {
99 | // fprintf(stderr, "Error: can't get random bytes!\n");
100 | // exit(1);
101 | // }
102 | // /* 53 bits / 2**53 */
103 | // return (u.i >> 11) * (1.0/9007199254740992.0);
104 | // }
105 |
106 | // direct translation of random.py in python
107 | // return sample_size unique random elements from a population,
108 | // sampling without replacement
109 | int random_sample(unsigned int population_size, unsigned int sample_size,
110 | unsigned int sample[sample_size])
111 | {
112 | if(sample_size>population_size||sample_size<=0){
113 | fprintf(stderr, "ERROR: sample_size is out of range.\n");
114 | exit(1);
115 | }
116 | random_init();
117 | unsigned int set_size = 21;
118 | if(sample_size>5) set_size += (unsigned int) pow(4.0, ceil(log(3*sample_size)/log(4.0)));
119 | unsigned int i, j;
120 | if(population_size<=set_size)
121 | {//pool tracking method
122 | // pool = list(population)
123 | unsigned int *pool;
124 | pool = malloc(sizeof(unsigned int)*population_size);
125 | for(i=0;i (n /2)) return -1;
178 | int i;
179 | if ((n-2) % 2) { //odd
180 | i = (n-3)/2;
181 | return bino_table[(i+2)*(i+1) + i + m];
182 | }
183 | else { // even
184 | i = (n-2)/2;
185 | return bino_table[i*(i+3) + m];
186 | }
187 | }
188 |
189 | //given the sample size and the p value
190 | //return the minimal value for one output to produce p value larger than the given p
191 | int bino_ctrl(int n, double p)
192 | {
193 | int i;
194 | for (i=0; i<(n+1)/2; i++)
195 | if (bino_p(n, i)>p) return i;
196 | return i;
197 | }//end of bio_ctrl
198 |
199 | //comparison function for sorting
200 | int comp_double(const void *a, const void *b) {
201 | double *x = (double *) a;
202 | double *y = (double *) b;
203 | if (*x < *y) return -1;
204 | else if (*x > *y) return 1;
205 | return 0;
206 | }
207 |
208 | int comp_int(const void *a, const void *b) {
209 | return (*(int *)a - *(int *)b);
210 | }
211 | int comp_uint(const void *a, const void *b) {
212 | //return (*(int *)v1 - *(int *)v2);
213 | return (*(unsigned int *)a - *(unsigned int *)b);
214 | }
215 |
216 | // pvalues
217 | double bh_threshold(int n, double pvalues[n], double alpha){
218 | qsort(pvalues, n, sizeof(*pvalues), comp_double);
219 | int i;
220 | for(i=0;i((double)i*alpha/(double)n))
222 | return pvalues[i>0?i-1:0];
223 | return pvalues[n-1];
224 | }
225 |
226 | struct FDR bh_ctrl(int sample_size,
227 | int upper_limit, int counts[upper_limit], int total,
228 | double alpha) {
229 | int i, acc = 0;
230 | double p;
231 | struct FDR result;
232 | for(i=0;i ((double)acc*alpha/(double)total)){
236 | if(i==0) {
237 | result.index = i;
238 | result.p = p;
239 | result.value = p*(double)total/(double)acc;
240 | }
241 | else {
242 | result.index = i-1;
243 | p = bino_p(sample_size, i-1);
244 | result.p = p;
245 | result.value = p*(double)total/(double)(acc-counts[i]);
246 | }
247 | return result;
248 | }
249 | }
250 | result.index = upper_limit -1 ;
251 | p = bino_p(sample_size, upper_limit-1);
252 | result.p = p;
253 | result.value = p*(double)total/(double)acc;
254 | return result;
255 | }
256 |
257 |
258 | struct FDR bh_eval(int sample_size,
259 | int upper_limit, int counts[upper_limit], int total) {
260 | int i, acc = 0, index = upper_limit;
261 | struct FDR result;
262 | for(i=0;i<=upper_limit;i++)
263 | if (counts[i]>0) {
264 | acc += counts[i];
265 | index = i;
266 | }
267 | result.index = index;
268 | result.value = bino_p(sample_size, index)*(double)total/(double)acc;
269 | return result;
270 | }
271 |
272 |
273 | //HyperQuick algorithm
274 | // Aleš Berkopec, HyperQuick algorithm for discrete hypergeometric distribution
275 | // Journal of Discrete Algorithms
276 | // Volume 5, Issue 2, June 2007, Pages 341–347
277 | // http://dx.doi.org/10.1016/j.jda.2006.01.001
278 | #define ACCURACY DBL_EPSILON
279 | // Eq. (6)
280 | long double inv_jm(int n, int x, int N, int m) {
281 | //return (1.0- (long double)x/((long double)m+1.0))/(1.0-((long double)n-1.0-(long double)x)/((long double)N-1.0-(long double)m));
282 | return (long double)(1.0- x/(m+1.0))/(1.0-(n-1.0-x)/(N-1.0-m));
283 | }
284 |
285 | long double hypergeo_p(int n, int x, int N, int M, double eps) {
286 | int k;
287 | long double s = 1.0, ak, bk, ck, epsk, jjm, result;
288 | //printf("Input Values:%d, %d, %d, %d\n", n, x, N, M);
289 | if ( (n==N && x==M)|| M==0||N==0 ) return 1.0;
290 | for (k=x;k<(M-1);k++)
291 | s = s*inv_jm(n, x, N, k) + 1.0;
292 | ak = s;
293 | bk = s;
294 | k = M -1;
295 | epsk = 2.0*eps;
296 | while ((k<(N-(n-x))) && (epsk>eps)) {
297 | ck = ak/bk;
298 | jjm = inv_jm(n, x, N, k);
299 | ak = ak*jjm;
300 | bk = bk*jjm + 1.0;
301 | epsk = (N-(n-x)-1-k)*(ck-ak/bk);
302 | k += 1;
303 | }
304 | result = 1.0 - (ak/bk - epsk/2.0);
305 | return result;
306 | }
307 |
308 | //Hypergeometric test, one tail Fisher exact test
309 | //if both values in a row or column are zero, the p value is 1
310 | double hypergeo_test(int ng, int nl, int cg, int cl){
311 | if(ng<0||ng<0||cg<0||cl<0)
312 | {
313 | printf("ERROR: hypergeometric test - all the values must be nonnegative integers!");
314 | return -1;
315 | };
316 | if(ng+nl==0||cg+cl==0||ng+cg==0||nl+cl==0) return 1.0;
317 |
318 | int N = ng + nl + cg + cl;
319 | int nm = (ngDBL_EPSILON && db >=0 && dc>=0)
350 | {
351 | da += 1.0;
352 | db -= 1.0;
353 | dc -= 1.0;
354 | dd += 1.0;
355 | ratio = ratio*db*dc/((da+1.0)*(dd+1.0));
356 | }
357 | return (int)da+1;
358 | }
359 |
360 | //Fisher exatc test, two-tailed hypergergeometric test
361 | double fisher_test(int ng, int nl, int cg, int cl){
362 | if(ng<0||ng<0||cg<0||cl<0)
363 | {
364 | printf("ERROR: Fisher exact test - all the values must be nonnegative integers!");
365 | return -1;
366 | };
367 | if(ng+nl==0||cg+cl==0||ng+cg==0||nl+cl==0) return 1.0;
368 | int N = ng + nl + cg + cl;
369 | int nm = (ng
2 | #include "pcg_basic.h"
3 | bool entropy_get(void* dest, size_t n);
4 | bool member_of(unsigned int value, unsigned int n, unsigned int data[n]);
5 | bool random_init();
6 | unsigned char random_bin();
7 | uint32_t random_uint();
8 | uint32_t random_bounded(uint32_t bound);
9 | float random_float();
10 | int random_sample(unsigned int population_size, unsigned int sample_size,
11 | unsigned int sample[sample_size]);
12 |
13 | int comp_int(const void *a, const void *b);
14 | int comp_uint(const void *a, const void *b);
15 |
16 | double bino_p(int n, int m);
17 | int bino_ctrl(int n, double p);
18 |
19 | int right_tail(int a, int b, int c, int d);
20 | double hypergeo_test(int ng, int nl, int cg, int cl);
21 | double fisher_test(int ng, int nl, int cg, int cl);
22 |
23 | struct FDR{
24 | int index;
25 | double value;
26 | double p;
27 | };
28 |
29 | double bh_threshold(int n, double pvalues[n], double alpha);
30 |
31 | struct FDR bh_ctrl(int sample_size,
32 | int upper_limit, int counts[upper_limit], int total,
33 | double alpha);
34 |
35 | struct FDR bh_eval(int sample_size,
36 | int upper_limit, int counts[upper_limit], int total);
37 |
--------------------------------------------------------------------------------
/test/README.md:
--------------------------------------------------------------------------------
1 | ## Test Cases
2 |
3 | ### CellComp Test Case
4 | Small-scale cell line data sets (three technical replicates). To test, run the following command.
5 | ```
6 | cellcomp cellcomp_control.dat cellcomp_case.dat
7 | ```
8 | ### OneComp Test Case
9 | Besides the two input files `onecomp_control.dat` and `onecomp_treated.dat` provideded here, there is an additional file `HCT116.txt` which is also required but is too large to be put here. Interested readers may contact the authors for the file. The file `HCT116.txt` contains the background stable gene pairs which were constructed from normal samples with a sufficent large sample size.
10 |
11 | Once the background file is obtained, run the following command to obtain dysregulated genes.
12 | ```
13 | onecomp HCT116.txt onecomp_control.dat onecomp_treated.dat
14 | ```
15 | The above running mode uses the default background gene pair filtering mode: one control sample is used for filtering to detect DEGs in the corresponding case sample.
16 |
17 | The following command, with setting `-m 1`, uses all the control samples to filter the background gene pairs.
18 | ```
19 | onecomp -m 1 HCT116.txt onecomp_control.dat onecomp_treated.dat
20 | ```
21 |
--------------------------------------------------------------------------------