NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
alignments_inl.h
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #pragma once
29 
30 namespace nvbio {
31 namespace io {
32 
33 // check whether two alignments are distinct
34 //
36  const uint32 pos1,
37  const bool rc1,
38  const uint32 pos2,
39  const bool rc2,
40  const uint32 dist)
41 {
42  return rc1 != rc2 ?
43  true :
44  pos1 >= pos2 - nvbio::min( pos2, dist ) &&
45  pos1 <= pos2 + dist ? false :
46  true;
47 }
48 
49 // check whether two paired-end alignments are distinct
50 //
52  const uint32 apos1,
53  const uint32 opos1,
54  const bool arc1,
55  const bool orc1,
56  const uint32 apos2,
57  const uint32 opos2,
58  const bool arc2,
59  const bool orc2)
60 {
61  return (arc1 != arc2) || (orc1 != orc2) || (apos1 != apos2) || (opos1 != opos2);
62 }
63 
64 // check whether two paired-end alignments are distinct
65 //
67  const uint32 apos1,
68  const uint32 opos1,
69  const bool arc1,
70  const bool orc1,
71  const uint32 apos2,
72  const uint32 opos2,
73  const bool arc2,
74  const bool orc2,
75  const uint32 dist)
76 {
77  return arc1 != arc2 || orc1 != orc2 ?
78  true :
79  (apos1 >= apos2 - nvbio::min( apos2, dist ) && apos1 <= apos2 + dist) &&
80  (opos1 >= opos2 - nvbio::min( opos2, dist ) && opos1 <= opos2 + dist) ?
81  false :
82  true;
83 }
84 
85 // check whether two alignments are distinct
86 //
87 // NOTE: this uses Alignment::sink() which is only valid during alignment,
88 // as sink() is unioned with ed().
89 //
91  const Alignment& p1,
92  const Alignment& p2,
93  const uint32 dist)
94 {
95  return distinct_alignments(
96  p1.alignment() + p1.sink(),
97  p1.is_rc(),
98  p2.alignment() + p2.sink(),
99  p2.is_rc(),
100  dist );
101 }
102 
103 // check whether two paired-end alignments are distinct
104 //
106  const PairedAlignments& p1,
107  const PairedAlignments& p2)
108 {
109  return distinct_alignments(
110  p1.mate(0).alignment() + p1.mate(0).sink(),
111  p1.mate(1).alignment() + p1.mate(1).sink(),
112  p1.mate(0).is_rc(),
113  p1.mate(1).is_rc(),
114  p2.mate(0).alignment() + p2.mate(0).sink(),
115  p2.mate(1).alignment() + p2.mate(1).sink(),
116  p2.mate(0).is_rc(),
117  p2.mate(1).is_rc() );
118 }
119 // check whether two paired-end alignments are distinct
120 //
122  const PairedAlignments& p1,
123  const PairedAlignments& p2,
124  const uint32 dist)
125 {
126  return distinct_alignments(
127  p1.mate(0).alignment() + p1.mate(0).sink(),
128  p1.mate(1).alignment() + p1.mate(1).sink(),
129  p1.mate(0).is_rc(),
130  p1.mate(1).is_rc(),
131  p2.mate(0).alignment() + p2.mate(0).sink(),
132  p2.mate(1).alignment() + p2.mate(1).sink(),
133  p2.mate(0).is_rc(),
134  p2.mate(1).is_rc(),
135  dist );
136 }
137 
138 } // namespace io
139 } // namespace nvbio