File: Marker.java

package info (click to toggle)
beagle 220722-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 9,644 kB
  • sloc: java: 17,045; sh: 55; makefile: 11
file content (185 lines) | stat: -rw-r--r-- 5,604 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 * Copyright (C) 2014-2021 Brian L. Browning
 *
 * This file is part of Beagle
 *
 * Beagle is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Beagle is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package vcf;

/**
 * <p>Interface {@code Marker} represents a genetic marker.
 * </p>
 * <p>All instances of class {@code Marker} are required to be immutable.
 * </p>
 *
 * @author Brian L. Browning {@code <browning@uw.edu>}
 */
public interface Marker extends Comparable<Marker> {

    /**
     * Returns the chromosome.
     * @return the chromosome
     */
    String chrom();

    /**
     * Returns the chromosome index.
     * @return the chromosome index
     */
    int chromIndex();

    /**
     * Returns the chromosome position coordinate.
     * @return the chromosome position coordinate
     */
    int pos();

    /**
     * Returns the number of marker identifiers.
     * @return the number of marker identifiers
     */
    int nIds();

    /**
     * Returns the specified marker identifier.
     * @param index a marker identifier index
     * @return the specified marker identifier
     *
     * @throws IndexOutOfBoundsException if
     * {@code index < 0 || index >= this.nIds()}
     */
    String id(int index);

    /**
     * Returns the first marker identifier if there is at least
     * one identifier in the VCF record ID field, and returns
     * {@code this.chr() + ":" + this.pos()} otherwise.
     *
     * @return a marker identifier
     */
    String id();

    /**
     * Returns the number of alleles for the marker, including the REF
     * allele.
     * @return the number of alleles for the marker, including the REF
     * allele
     */
    int nAlleles();

    /**
     * Returns the minimum number of bits required to store a non-missing
     * allele.
     * @return the minimum number of bits required to store a non-missing
     * allele
     */
    int bitsPerAllele();

    /**
     * Returns the specified allele.  The reference allele has index 0.
     * @param index an allele index
     * @return the specified allele
     *
     * @throws IndexOutOfBoundsException if
     * {@code index < 0 || index >= this.nAlleles()}
     */
    String allele(int index);

    /**
     * Returns the alleles. The {@code k}-th element of the returned array
     * is equal to {@code this.allele(k)}.
     * @return the alleles
     */
    String[] alleles();

    /**
     * Returns the number of distinct genotypes, which equals
     * {@code this.nAlleles()*(1 + this.nAlleles())/2}.
     *
     * @return the number of distinct genotypes
     */
    int nGenotypes();

    /**
     * Returns the INFO END field, or -1 if there is no INFO END field.
     *
     * @return the INFO END field, or -1 if there is no INFO END field
     */
    int end();

    /**
     * Returns {@code true} if the specified object is a
     * {@code Marker} with the same chromosome,
     * position, allele lists, and INFO END field, and
     * returns {@code false} otherwise.  Equality does not
     * depend on value of the VCF record ID field.
     *
     * @param obj object to be compared with {@code this} for equality
     *
     * @return {@code true} if the specified object is a
     * {@code Marker} with the same chromosome,
     * position, and allele lists, and INFO END field
     */
    @Override
    boolean equals(Object obj);

    /**
     * <p>Returns the hash code value for this object. The hash code does not
     * depend on value of the VCF record ID field.
     * The hash code is defined by the following calculation:
     * </p>
     * <pre>
     *   int hash = 5;
     *   hash = 29 * hash + this.chromIndex();
     *   hash = 29 * hash + this.pos();
     *   for (int j=0, n=this.nAlleles(); j&lt;n; ++j) {
     *       hash = 29 * hash + alleles[j].hashCode();
     *   }
     *   hash = 29 * hash + end();
     * </pre>
     *
     * @return the hash code value for this marker
     */
    @Override
    int hashCode();

    /**
     * Compares this marker with the specified marker
     * for order, and returns a negative integer, 0, or a positive integer
     * depending on whether this marker is less than, equal to,
     * or greater than the specified marker.  Comparison is
     * on chromosome index, position, allele identifier lists, and end value
     * in that order.  Allele identifier lists are compared for
     * lexicographical order, and alleles are compared using the
     * {@code String compareTo()} method.
     *
     * @param other the {@code Marker} to be compared
     * @return a negative integer, 0, or a positive integer
     * depending on whether this marker is less than, equal,
     * or greater than the specified marker
     */
    @Override
    int compareTo(Marker other);

    /**
     * Returns a string equal to the first five tab-delimited fields
     * of a VCF record corresponding to this marker.
     *
     * @return a string equal to the first five tab-delimited fields
     * of a VCF record corresponding to this marker
     */
    @Override
    String toString();
}