From 76d81d184057a864889e4f869c74d69c1429527d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20G=C3=B3mez-S=C3=A1nchez?= Date: Thu, 24 Nov 2016 14:02:47 +0100 Subject: [PATCH] removed gelitext package and usages --- .../java/htsjdk/tribble/example/CountRecords.java | 3 - .../htsjdk/tribble/gelitext/DiploidGenotype.java | 66 --------- .../htsjdk/tribble/gelitext/GeliTextCodec.java | 117 ---------------- .../htsjdk/tribble/gelitext/GeliTextFeature.java | 148 --------------------- .../java/htsjdk/tribble/gelitext/GeliTextTest.java | 100 -------------- 5 files changed, 434 deletions(-) delete mode 100644 src/main/java/htsjdk/tribble/gelitext/DiploidGenotype.java delete mode 100644 src/main/java/htsjdk/tribble/gelitext/GeliTextCodec.java delete mode 100644 src/main/java/htsjdk/tribble/gelitext/GeliTextFeature.java delete mode 100644 src/test/java/htsjdk/tribble/gelitext/GeliTextTest.java diff --git a/src/main/java/htsjdk/tribble/example/CountRecords.java b/src/main/java/htsjdk/tribble/example/CountRecords.java index 230c1bf3d..3bb8e4160 100644 --- a/src/main/java/htsjdk/tribble/example/CountRecords.java +++ b/src/main/java/htsjdk/tribble/example/CountRecords.java @@ -29,7 +29,6 @@ import htsjdk.tribble.FeatureCodec; import htsjdk.tribble.Tribble; import htsjdk.tribble.bed.BEDCodec; -import htsjdk.tribble.gelitext.GeliTextCodec; import htsjdk.tribble.index.Index; import htsjdk.tribble.index.IndexFactory; import htsjdk.tribble.index.linear.LinearIndex; @@ -193,8 +192,6 @@ public static FeatureCodec getFeatureCodec(File featureFile) { // return new VCFCodec(); if (featureFile.getName().endsWith(".bed") || featureFile.getName().endsWith(".BED") ) return new BEDCodec(); - if (featureFile.getName().endsWith(".geli.calls") || featureFile.getName().endsWith(".geli") ) - return new GeliTextCodec(); throw new IllegalArgumentException("Unable to determine correct file type based on the file name, for file -> " + featureFile); } } diff --git a/src/main/java/htsjdk/tribble/gelitext/DiploidGenotype.java b/src/main/java/htsjdk/tribble/gelitext/DiploidGenotype.java deleted file mode 100644 index f53343270..000000000 --- a/src/main/java/htsjdk/tribble/gelitext/DiploidGenotype.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2013 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 htsjdk.tribble.gelitext; - - -/** - * Class DiploidGenotype - * - * Enum describing all possible combinations of diploid genotype variations; - * AA, AC, etc. - * - * @author aaron - */ -@Deprecated -public enum DiploidGenotype { - AA, AC, AG, AT, CC, CG, CT, GG, GT, TT; - - public static DiploidGenotype toDiploidGenotype(String genotype) { - if (genotype.length() != 2) - throw new DiploidGenotypeException("Genotype string for conversion should be of length 2, we were passed = " + genotype); - genotype = genotype.toUpperCase(); - for (DiploidGenotype g: DiploidGenotype.values()) - if (g.toString().equals(genotype)) return g; - throw new DiploidGenotypeException("Unable to find genotype matching " + genotype); - } - - public boolean isHet() { - return toString().toCharArray()[0] != toString().toCharArray()[1]; - } - - public boolean containsBase(char base) { - return (toString().charAt(0) == base || toString().charAt(1) == base); - } -} - -@Deprecated -class DiploidGenotypeException extends RuntimeException { - DiploidGenotypeException(String s) { - super(s); - } - - DiploidGenotypeException(String s, Throwable throwable) { - super(s, throwable); - } -} \ No newline at end of file diff --git a/src/main/java/htsjdk/tribble/gelitext/GeliTextCodec.java b/src/main/java/htsjdk/tribble/gelitext/GeliTextCodec.java deleted file mode 100644 index 394b5dc78..000000000 --- a/src/main/java/htsjdk/tribble/gelitext/GeliTextCodec.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2013 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 htsjdk.tribble.gelitext; - -import htsjdk.samtools.util.CollectionUtil; -import htsjdk.tribble.AsciiFeatureCodec; -import htsjdk.tribble.Feature; -import htsjdk.tribble.exception.CodecLineParsingException; -import htsjdk.tribble.readers.LineIterator; - -import java.util.Arrays; - - -/** - *

- * A codec for parsing geli text files, which is the text version of the geli binary format. - *

- *

- * GELI text has the following tab-seperated fields: - * contig the contig (string) - * position the position on the contig (long) - * refBase the reference base (char) - * depthOfCoverage the depth of coverage at this position (int) - * maximumMappingQual the maximum mapping quality of a read at this position (int) - * genotype the called genotype (string) - * LODBestToReference the LOD score of the best to the reference (double) - * LODBestToNext the LOD score of the best to the next best genotype (double) - * likelihoods the array of all genotype likelihoods, in ordinal ordering (array of 10 doubles, in ordinal order) - * - * @author aaron - * @deprecated This is deprecated and unsupported. - */ -@Deprecated -public class GeliTextCodec extends AsciiFeatureCodec { - public GeliTextCodec() { - super(GeliTextFeature.class); - } - - public Feature decodeLoc(final String line) { - return decode(line); - } - - @Override - public GeliTextFeature decode(final String line) { - // clean out header lines and comments - if (line.startsWith("#") || line.startsWith("@")) - return null; - - // parse into tokens - final String[] parts = line.trim().split("\\s+"); - return decode(parts); - } - - @Override - public boolean canDecode(String path){ - return path.toLowerCase().endsWith(".geli.calls") || path.toLowerCase().endsWith(".geli"); - } - - @Override - public Object readActualHeader(LineIterator reader) { - return null; - } - - public GeliTextFeature decode(final String[] tokens) { - try { - // check that we got the correct number of tokens in the split - if (tokens.length != 18) - throw new CodecLineParsingException("Invalid GeliTextFeature row found -- incorrect element count. Expected 18, got " + tokens.length + " line = " + CollectionUtil.join(Arrays.asList(tokens), " ")); - - // UPPER case and sort - final char[] x = tokens[5].toUpperCase().toCharArray(); - Arrays.sort(x); - final String bestGenotype = new String(x); - - final double[] genotypeLikelihoods = new double[10]; - for (int pieceIndex = 8, offset = 0; pieceIndex < 18; pieceIndex++, offset++) { - genotypeLikelihoods[offset] = Double.valueOf(tokens[pieceIndex]); - } - return new GeliTextFeature(tokens[0], - Long.valueOf(tokens[1]), - Character.toUpperCase(tokens[2].charAt(0)), - Integer.valueOf(tokens[3]), - Integer.valueOf(tokens[4]), - DiploidGenotype.toDiploidGenotype(bestGenotype), - Double.valueOf(tokens[6]), - Double.valueOf(tokens[7]), - genotypeLikelihoods); - } catch (CodecLineParsingException e) { - e.printStackTrace(); - throw new RuntimeException("Unable to parse line " + CollectionUtil.join(Arrays.asList(tokens), " "), e); - } catch (NumberFormatException e) { - e.printStackTrace(); - throw new RuntimeException("Unable to parse line " + CollectionUtil.join(Arrays.asList(tokens), " "), e); - } - } -} diff --git a/src/main/java/htsjdk/tribble/gelitext/GeliTextFeature.java b/src/main/java/htsjdk/tribble/gelitext/GeliTextFeature.java deleted file mode 100644 index baad1caab..000000000 --- a/src/main/java/htsjdk/tribble/gelitext/GeliTextFeature.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2013 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 htsjdk.tribble.gelitext; - -import htsjdk.tribble.Feature; - -import java.util.Arrays; - - -/** - *

- * Class GeliTextFeature - *

- * This is a feature for the Geli text object, which is the text version of the Geli binary genotyping format. - * - * @author aaron - * @deprecated this is deprecated and no longer supported - */ -@Deprecated -public class GeliTextFeature implements Feature { - - private final String contig; // the contig name - private final long position; // the position on the contig - private final char refBase; // the reference base - private final int depthOfCoverage; // the depth of coverage at this position - private final int maximumMappingQual; // the maximum mapping quality of a read at this position - private final DiploidGenotype genotype; // the called genotype - private final double LODBestToReference; // the LOD score of the best to the reference - private final double LODBestToNext; // the LOD score of the best to the next best genotype - private final double likelihoods[]; // the array of all genotype likelihoods, in ordinal order - - /** - * Create a geli text feature, given: - * - * @param contig the contig - * @param position the position on the contig - * @param refBase the reference base - * @param depthOfCoverage the depth of coverage at this position - * @param maximumMappingQual the maximum mapping quality of a read at this position - * @param genotype the called genotype - * @param LODBestToReference the LOD score of the best to the reference - * @param LODBestToNext the LOD score of the best to the next best genotype - * @param likelihoods the array of all genotype likelihoods, in ordinal ordering - */ - public GeliTextFeature(String contig, - long position, - char refBase, - int depthOfCoverage, - int maximumMappingQual, - DiploidGenotype genotype, - double LODBestToReference, - double LODBestToNext, - double[] likelihoods) { - this.contig = contig; - this.position = position; - this.refBase = refBase; - this.depthOfCoverage = depthOfCoverage; - this.maximumMappingQual = maximumMappingQual; - this.genotype = genotype; - this.LODBestToReference = LODBestToReference; - this.LODBestToNext = LODBestToNext; - this.likelihoods = likelihoods; - } - - @Override - public String getContig() { - return this.contig; - } - - /** Return the start position in 1-based coordinates (first base is 1) */ - public int getStart() { - return (int) this.position; - } - - /** - * Return the end position following 1-based fully closed conventions. The length of a feature is - * end - start + 1; - */ - public int getEnd() { - return (int) this.position; - } - - public char getRefBase() { - return refBase; - } - - public int getDepthOfCoverage() { - return depthOfCoverage; - } - - public int getMaximumMappingQual() { - return maximumMappingQual; - } - - public DiploidGenotype getGenotype() { - return genotype; - } - - public double getLODBestToNext() { - return LODBestToNext; - } - - public double getLODBestToReference() { - return LODBestToReference; - } - - public double[] getLikelihoods() { - return likelihoods; - } - - private static double Epsilon = 0.0001; - public boolean equals(Object o) { - if (!(o instanceof GeliTextFeature)) return false; - GeliTextFeature other = (GeliTextFeature)o; - if (!Arrays.equals(likelihoods,other.likelihoods)) return false; - if (!contig.equals(other.contig)) return false; - if (!(position == other.position)) return false; - if (!(refBase == other.refBase)) return false; - if (!(depthOfCoverage == other.depthOfCoverage)) return false; - if (!(maximumMappingQual == other.maximumMappingQual)) return false; - if (!(genotype == other.genotype)) return false; - if (!(Math.abs(LODBestToReference - other.LODBestToReference) < Epsilon)) return false; - if (!(Math.abs(LODBestToNext - other.LODBestToNext) < Epsilon)) return false; - return true; - } - -} diff --git a/src/test/java/htsjdk/tribble/gelitext/GeliTextTest.java b/src/test/java/htsjdk/tribble/gelitext/GeliTextTest.java deleted file mode 100644 index c670bf182..000000000 --- a/src/test/java/htsjdk/tribble/gelitext/GeliTextTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package htsjdk.tribble.gelitext; - -import htsjdk.tribble.AbstractFeatureReader; -import htsjdk.tribble.FeatureReader; -import htsjdk.tribble.TestUtils; -import htsjdk.tribble.index.Index; -import htsjdk.tribble.index.IndexFactory; -import org.testng.Assert; -import org.testng.annotations.BeforeSuite; -import org.testng.annotations.Test; - -import java.io.File; -import java.io.IOException; -import java.util.Iterator; - - -/** - * @author aaron - *

- * Class GeliTextTest - *

- * test out the geli text source codec and feature - */ -@Deprecated -public class GeliTextTest { - public static final File testFile = new File(TestUtils.DATA_DIR + "testGeliText.txt"); - public static Index index; - private FeatureReader source; - - // setup a new source before each class - - @BeforeSuite - public void beforeTest() { - index = IndexFactory.createLinearIndex(testFile, new GeliTextCodec()); - source = AbstractFeatureReader.getFeatureReader(testFile.getAbsolutePath(), new GeliTextCodec(), index); - } - - @Test - public void testReadAllLines() { - // Query - try { - Iterator iter = source.query("22", 14438070, 14592250); - int count = 0; - while (iter.hasNext()) { - GeliTextFeature feat = iter.next(); - count++; - } - Assert.assertEquals(count, 50); - } catch (IOException e) { - Assert.fail("failed to generate iterator from feature source"); - } - } - - @Test - public void testGetSubRegion() { - // Query - try { - Iterator iter = source.query("22", 14438070, 14539060); // should be the first 41 records - int count = 0; - while (iter.hasNext()) { - GeliTextFeature feat = iter.next(); - count++; - } - Assert.assertEquals(count, 41); - } catch (IOException e) { - Assert.fail("failed to generate iterator from feature source"); - } - } - - @Test - public void testFirstRecord() { - // Query - try { - Iterator iter = source.query("22", 14438070, 14592250); - int count = 0; - - GeliTextFeature feat = iter.next(); - // check the first records contents - // 22 14438070 A 0 0 GG 33.2618 33.2618 0 0 0 0 0 0 0 33.2618 0 0 - Assert.assertTrue("22".equals(feat.getContig())); - Assert.assertEquals(feat.getStart(), 14438070); - Assert.assertEquals('A', feat.getRefBase()); - Assert.assertEquals(feat.getDepthOfCoverage(), 0.0, 0.0001); - Assert.assertEquals(feat.getMaximumMappingQual(), 0.0, 0.0001); - Assert.assertTrue(DiploidGenotype.GG.equals(feat.getGenotype())); - Assert.assertEquals(feat.getDepthOfCoverage(), 0.0, 0.0001); - Assert.assertEquals(feat.getLODBestToReference(), 33.2618, 0.0001); - Assert.assertEquals(feat.getLODBestToNext(), 33.2618, 0.0001); - for (int x = 0; x < feat.getLikelihoods().length; x++) { - if (x == DiploidGenotype.GG.ordinal()) - Assert.assertEquals(feat.getLikelihoods()[x], 33.2618, 0.0001); - else - Assert.assertEquals(feat.getLikelihoods()[x], 0, 0.0001); - } - - } catch (IOException e) { - Assert.fail("failed to generate iterator from feature source"); - } - } -}