gatk-3.8/archive/java/src/org/broadinstitute/sting/poolseq/Quad.java

121 lines
3.7 KiB
Java
Raw Normal View History

/*
* Copyright (c) 2010 The Broad Institute
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package org.broadinstitute.sting.playground.gatk.walkers.poolseq;
This commit has a bunch to do with cleaning up the CoverageAndPowerWalker code: implementing some new printing options, but mostly altering the code so it's much more readable and understandable, and much less hacky-looking. ADDED: @Quad: This is just like Pair, except with four fields. In the original CoverageAndPowerWalker I often used a pair of pairs to hold things, which made the code nigh unreadable. @SQuad: An extension of Quad for when you want to store objects of the same type. Let's you simply declare new SQuad<X> rather than new Quad<X,X,X,X> @ReadOffsetQuad: An extension of Quad specifically for holding two lists of reads and two lists of offsets Supports construction from AlignmentContexts and conversion to AlignmentContexts (given a GenomeLoc). There are methods that make it very clear what the code is doing (getSecondRead() rather than the cryptic getThird() ) @PowerAndCoverageWalker: The new version of CoverageAndPowerWalker. If the tests all go well, then I'll remove the old version. New to this version is the ability to give an output file directly to the walker, so that locus information prints to the file, while the final reduce prints to standard out. Bootstrap iterations are now a command line argument rather than a final int; and users can instruct the walker to print out the coverage/power statistics for both the original reads, and those reads whose quality score exceeds a user-defined threshold. CHANGES: @PoolUtils: Altered methods to accept as argumetns, and return, Quad objects. Added a random partition method for bootstrapping. @CoverageAndPowerWalker: Altered methods to work with the new PoolUtils methods. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1602 348d0f76-0448-11de-a6fe-93d51630548a
2009-09-13 09:00:04 +08:00
import org.broadinstitute.sting.utils.collections.Pair;
This commit has a bunch to do with cleaning up the CoverageAndPowerWalker code: implementing some new printing options, but mostly altering the code so it's much more readable and understandable, and much less hacky-looking. ADDED: @Quad: This is just like Pair, except with four fields. In the original CoverageAndPowerWalker I often used a pair of pairs to hold things, which made the code nigh unreadable. @SQuad: An extension of Quad for when you want to store objects of the same type. Let's you simply declare new SQuad<X> rather than new Quad<X,X,X,X> @ReadOffsetQuad: An extension of Quad specifically for holding two lists of reads and two lists of offsets Supports construction from AlignmentContexts and conversion to AlignmentContexts (given a GenomeLoc). There are methods that make it very clear what the code is doing (getSecondRead() rather than the cryptic getThird() ) @PowerAndCoverageWalker: The new version of CoverageAndPowerWalker. If the tests all go well, then I'll remove the old version. New to this version is the ability to give an output file directly to the walker, so that locus information prints to the file, while the final reduce prints to standard out. Bootstrap iterations are now a command line argument rather than a final int; and users can instruct the walker to print out the coverage/power statistics for both the original reads, and those reads whose quality score exceeds a user-defined threshold. CHANGES: @PoolUtils: Altered methods to accept as argumetns, and return, Quad objects. Added a random partition method for bootstrapping. @CoverageAndPowerWalker: Altered methods to work with the new PoolUtils methods. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1602 348d0f76-0448-11de-a6fe-93d51630548a
2009-09-13 09:00:04 +08:00
/**
* Created by IntelliJ IDEA.
* User: chartl
* Date: Sep 11, 2009
* Time: 5:12:29 PM
* To change this template use File | Settings | File Templates.
*/
public class Quad<W,X,Y,Z> {
public W first;
public X second;
public Y third;
public Z fourth;
public Quad() {
first = null;
second = null;
third = null;
fourth = null;
}
public Quad(W w, X x, Y y, Z z) {
first = w;
second = x;
third = y;
fourth = z;
}
public Quad(Pair<W,X> a, Pair<Y,Z> b) {
first = a.getFirst();
second = a.getSecond();
third = b.getFirst();
fourth = b.getSecond();
}
public boolean equals(Object o) {
if(o == null) {
return false;
} else if (! (o instanceof Quad) ) {
return false;
}
Quad other = (Quad) o;
return ( equalToNotNull(this.first,other.first) && equalToNotNull(this.second,other.second)
&& equalToNotNull(this.third,other.third) && equalToNotNull(this.fourth,other.fourth));
}
public int hashCode() {
return getHash(first) ^ getHash(second) ^ getHash(third) ^ getHash(fourth);
}
public String toString() {
return String.format("(%s, %s, %s, %s)", first.toString(), second.toString(),
third.toString(), fourth.toString());
}
This commit has a bunch to do with cleaning up the CoverageAndPowerWalker code: implementing some new printing options, but mostly altering the code so it's much more readable and understandable, and much less hacky-looking. ADDED: @Quad: This is just like Pair, except with four fields. In the original CoverageAndPowerWalker I often used a pair of pairs to hold things, which made the code nigh unreadable. @SQuad: An extension of Quad for when you want to store objects of the same type. Let's you simply declare new SQuad<X> rather than new Quad<X,X,X,X> @ReadOffsetQuad: An extension of Quad specifically for holding two lists of reads and two lists of offsets Supports construction from AlignmentContexts and conversion to AlignmentContexts (given a GenomeLoc). There are methods that make it very clear what the code is doing (getSecondRead() rather than the cryptic getThird() ) @PowerAndCoverageWalker: The new version of CoverageAndPowerWalker. If the tests all go well, then I'll remove the old version. New to this version is the ability to give an output file directly to the walker, so that locus information prints to the file, while the final reduce prints to standard out. Bootstrap iterations are now a command line argument rather than a final int; and users can instruct the walker to print out the coverage/power statistics for both the original reads, and those reads whose quality score exceeds a user-defined threshold. CHANGES: @PoolUtils: Altered methods to accept as argumetns, and return, Quad objects. Added a random partition method for bootstrapping. @CoverageAndPowerWalker: Altered methods to work with the new PoolUtils methods. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1602 348d0f76-0448-11de-a6fe-93d51630548a
2009-09-13 09:00:04 +08:00
public W getFirst() { return first; }
public X getSecond() { return second; }
public Y getThird() { return third; }
public Z getFourth() { return fourth; }
public Pair<W,X> getFirstPair() { return new Pair<W,X>(first,second); }
public Pair<Y,Z> getSecondPair() { return new Pair<Y,Z>(third,fourth); }
public void setFirst(Object o) { first = (W) o; }
public void setSecond(Object o) { second = (X) o; }
public void setThird(Object o) { third = (Y) o; }
public void setFourth(Object o) { fourth = (Z) o; }
private int getHash(Object o) {
int hash = 0;
if(o != null) {
hash = o.hashCode();
}
return hash;
}
private boolean equalToNotNull(Object a, Object b) {
boolean areEqual = false;
if ( a != null && b != null ) {
areEqual = a.equals(b);
} else if (a == null && b == null ) {
areEqual = true;
// todo -- make sure we don't want to check for instanceOf here...
// todo -- maybe this statement should be eliminated
}
return areEqual;
}
}