Clean some deprecated classes/methods usages in htsjdk #707

Merged
merged 8 commits into from Nov 30, 2016
@@ -182,6 +182,15 @@ public static int computeInsertSize(final SAMRecord firstEnd, final SAMRecord se
}
/**
+ * Write the mate info for two SAMRecords. This will always clear/remove any mate cigar tag that is present.
+ * @param rec1 the first SAM record
+ * @param rec2 the second SAM record
+ */
+ public static void setMateInfo(final SAMRecord rec1, final SAMRecord rec2) {
+ setMateInfo(rec1, rec2, false);
+ }
+
+ /**
* Write the mate info for two SAMRecords
* @param rec1 the first SAM record. Must have a non-null SAMFileHeader.
* @param rec2 the second SAM record. Must have a non-null SAMFileHeader.
@@ -270,6 +279,7 @@ else if (rec1.getReadUnmappedFlag() && rec2.getReadUnmappedFlag()) {
* @param rec2 the second SAM record
* @param header the SAM file header
* @param setMateCigar true if we are to update/create the Mate CIGAR (MC) optional tag, false if we are to clear any mate cigar tag that is present.
+ * @deprecated use {@link #setMateInfo(SAMRecord, SAMRecord, boolean)} instead
*/
@Deprecated
public static void setMateInfo(final SAMRecord rec1, final SAMRecord rec2, final SAMFileHeader header, final boolean setMateCigar) {
@@ -281,9 +291,11 @@ public static void setMateInfo(final SAMRecord rec1, final SAMRecord rec2, final
* @param rec1 the first SAM record
* @param rec2 the second SAM record
* @param header the SAM file header
+ * @deprecated use {@link #setMateInfo(SAMRecord, SAMRecord)} instead
*/
+ @Deprecated
public static void setMateInfo(final SAMRecord rec1, final SAMRecord rec2, final SAMFileHeader header) {
- setMateInfo(rec1, rec2, false);
+ setMateInfo(rec1, rec2);
}
/**
@@ -322,26 +334,43 @@ public static void setMateInformationOnSupplementalAlignment( final SAMRecord su
/**
* This method will clear any mate cigar already present.
+ * @deprecated use {@link #setProperPairAndMateInfo(SAMRecord, SAMRecord, List)} instead
@lbergelson

lbergelson Nov 22, 2016

Contributor

You're recommending the version without a boolean but calling the one with it. Could you make it consistent?

@magicDGS

magicDGS Nov 24, 2016

Contributor

I changed the body.

*/
+ @Deprecated
public static void setProperPairAndMateInfo(final SAMRecord rec1, final SAMRecord rec2,
final SAMFileHeader header,
- final List<PairOrientation> exepectedOrientations) {
- setProperPairAndMateInfo(rec1, rec2, header, exepectedOrientations, false);
+ final List<PairOrientation> expectedOrientations) {
+ setProperPairAndMateInfo(rec1, rec2, expectedOrientations);
}
/**
- * @param rec1
- * @param rec2
- * @param header
- * @param exepectedOrientations
* @param addMateCigar true if we are to update/create the Mate CIGAR (MC) optional tag, false if we are to clear any mate cigar tag that is present.
+ * @deprecated use {@link #setProperPairAndMateInfo(SAMRecord, SAMRecord, List, boolean)}
*/
+ @Deprecated
public static void setProperPairAndMateInfo(final SAMRecord rec1, final SAMRecord rec2,
final SAMFileHeader header,
- final List<PairOrientation> exepectedOrientations,
+ final List<PairOrientation> expectedOrientations,
+ final boolean addMateCigar) {
+ setProperPairAndMateInfo(rec1, rec2, expectedOrientations, addMateCigar);
+ }
+
+ /**
+ * This method will clear any mate cigar already present.
+ */
+ public static void setProperPairAndMateInfo(final SAMRecord rec1, final SAMRecord rec2,
+ final List<PairOrientation> expectedOrientations) {
+ setProperPairAndMateInfo(rec1, rec2, expectedOrientations, false);
+ }
+
+ /**
+ * @param addMateCigar true if we are to update/create the Mate CIGAR (MC) optional tag, false if we are to clear any mate cigar tag that is present.
+ */
+ public static void setProperPairAndMateInfo(final SAMRecord rec1, final SAMRecord rec2,
+ final List<PairOrientation> expectedOrientations,
final boolean addMateCigar) {
- setMateInfo(rec1, rec2, header, addMateCigar);
- setProperPairFlags(rec1, rec2, exepectedOrientations);
+ setMateInfo(rec1, rec2, addMateCigar);
+ setProperPairFlags(rec1, rec2, expectedOrientations);
}
public static void setProperPairFlags(final SAMRecord rec1, final SAMRecord rec2, final List<PairOrientation> expectedOrientations) {
@@ -104,16 +104,22 @@ private void initializeKeyIfUninitialized(final K k) {
/**
* Partitions a collection into groups based on a characteristics of that group. Partitions are embodied in a map, whose keys are the
* value of that characteristic, and the values are the partition of elements whose characteristic evaluate to that key.
+ *
+ * @deprecated use java8 .stream().collect(Collectors.groupingBy(()-> function)) instead
*/
- @Deprecated //use java8 .stream().collect(Collectors.groupingBy(()-> function)) instead
+ @Deprecated
public static <K, V> Map<K, Collection<V>> partition(final Collection<V> collection, final Partitioner<V, K> p) {
final MultiMap<K, V> partitionToValues = new MultiMap<>();
for (final V entry : collection) {
partitionToValues.append(p.getPartition(entry), entry);
}
return partitionToValues;
}
- @Deprecated //not needed, use Collectors.groupingBy instead
+
+ /**
+ * @deprecated use Collectors.groupingBy instead
+ */
+ @Deprecated
public static abstract class Partitioner<V, K> {
public abstract K getPartition(final V v);
}
@@ -71,7 +71,7 @@
*/
public class IOUtil {
/**
- * @deprecated Use Defaults.NON_ZERO_BUFFER_SIZE instead.
+ * @deprecated Use {@link Defaults#NON_ZERO_BUFFER_SIZE} instead.
*/
@Deprecated
public static final int STANDARD_BUFFER_SIZE = Defaults.NON_ZERO_BUFFER_SIZE;
@@ -102,9 +102,14 @@ public void addall(final Collection<Interval> intervals) {
}
}
- /** Sorts the internal collection of intervals by coordinate. */
- @Deprecated // Use sorted() instead of sort(). The sort() function modifies the object in-place and
- // is therefore difficult to work with. sorted() returns a new IntervalList that is sorted
+ /**
+ * Sorts the internal collection of intervals by coordinate.
+ *
+ * Note: this function modifies the object in-place and is therefore difficult to work with.
+ *
+ * @deprecated use {@link #sorted()} instead.
+ */
+ @Deprecated
public void sort() {
Collections.sort(this.intervals, new IntervalCoordinateComparator(this.header));
this.header.setSortOrder(SAMFileHeader.SortOrder.coordinate);
@@ -154,19 +159,27 @@ public IntervalList uniqued(final boolean concatenateNames) {
return value;
}
- /** Sorts and uniques the list of intervals held within this interval list. */
- @Deprecated//use uniqued() instead. This function modifies the object in-place and
- // is therefore difficult to work with.
+ /**
+ * Sorts and uniques the list of intervals held within this interval list.
+ *
+ * Note: this function modifies the object in-place and is therefore difficult to work with.
+ *
+ * @deprecated use {@link #uniqued()} instead.
+ */
+ @Deprecated
public void unique() {
unique(true);
}
/**
* Sorts and uniques the list of intervals held within this interval list.
+ *
+ * Note: this function modifies the object in-place and is therefore difficult to work with.
+ *
* @param concatenateNames If false, interval names are not concatenated when merging intervals to save space.
+ * @deprecated use {@link #uniqued(boolean)} instead.
*/
- @Deprecated//use uniqued() instead. This function modifies the object in-place and
- // is therefore difficult to work with
+ @Deprecated
public void unique(final boolean concatenateNames) {
sort();
final List<Interval> tmp = getUniqueIntervals(concatenateNames);
@@ -186,10 +199,12 @@ public void unique(final boolean concatenateNames) {
*
* Note: has the side-effect of sorting the stored intervals in coordinate order if not already sorted.
*
+ * Note: this function modifies the object in-place and is therefore difficult to work with.
+ *
* @return the set of unique intervals condensed from the contained intervals
+ * @deprecated use {@link #uniqued()#getIntervals()} instead.
*/
- @Deprecated//use uniqued().getIntervals() instead. This function modifies the object in-place and
- // is therefore difficult to work with
+ @Deprecated
public List<Interval> getUniqueIntervals() {
return getUniqueIntervals(true);
}
@@ -249,14 +264,14 @@ else if (current.intersects(next) || current.abuts(next)) {
}
/**
- * Merges list of intervals and reduces them like htsjdk.samtools.util.IntervalList#getUniqueIntervals()
- * @param concatenateNames If false, the merged interval has the name of the earlier interval. This keeps name shorter.
- */
- @Deprecated //use uniqued(concatenateNames).getIntervals() or the static version instead to avoid changing the underlying object.
- /**
- * Merges list of intervals and reduces them like htsjdk.samtools.util.IntervalList#getUniqueIntervals()
- * @param concatenateNames If false, the merged interval has the name of the earlier interval. This keeps name shorter.
+ * Merges list of intervals and reduces them like {@link #getUniqueIntervals()}.
+ *
+ * Note: this function modifies the object in-place and is therefore difficult to work with.
+ *
+ * @param concatenateNames If false, the merged interval has the name of the earlier interval. This keeps name shorter.
+ * @deprecated use {@link #uniqued(boolean)#getIntervals()} or {@link #getUniqueIntervals(IntervalList, boolean)} instead.
*/
+ @Deprecated
public List<Interval> getUniqueIntervals(final boolean concatenateNames) {
if (getHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) {
sort();
@@ -36,6 +36,8 @@
* @deprecated use getContig() instead
*/
@Deprecated
- public String getChr();
+ default public String getChr() {
@lbergelson

lbergelson Nov 22, 2016

Contributor

👍

+ return getContig();
+ }
}
@@ -39,11 +39,6 @@ public SimpleFeature(final String contig, final int start, final int end) {
this.end = end;
}
- @Deprecated
- public String getChr() {
- return contig;
- }
-
public String getContig() {
return contig;
}
@@ -51,14 +51,6 @@ public SimpleBEDFeature(int start, int end, String chr) {
this.chr = chr;
}
-
- @Deprecated
- @Override
- public String getChr() {
- return getContig();
- }
-
-
@Override
public String getContig() {
return chr;
@@ -193,12 +193,8 @@ 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(".snp") || featureFile.getName().endsWith(".rod") )
- // return new OldDbSNPCodec();
if (featureFile.getName().endsWith(".geli.calls") || featureFile.getName().endsWith(".geli") )
return new GeliTextCodec();
- //if (featureFile.getName().endsWith(".txt") || featureFile.getName().endsWith(".TXT") )
- // return new SoapSNPCodec();
throw new IllegalArgumentException("Unable to determine correct file type based on the file name, for file -> " + featureFile);
}
}
@@ -118,7 +118,7 @@ public boolean canDecode(final String path) {
Iterator<FEATURE_TYPE> it = reader.iterator();
while ( it.hasNext() ) {
final Feature f = it.next();
- dos.writeUTF(f.getChr());
+ dos.writeUTF(f.getContig());
dos.writeInt(f.getStart());
dos.writeInt(f.getEnd());
}
@@ -83,12 +83,6 @@ public GeliTextFeature(String contig,
this.likelihoods = likelihoods;
}
- /** Return the features reference sequence name, e.g chromosome or contig */
- @Deprecated
- public String getChr() {
- return getContig();
- }
-
@Override
public String getContig() {
return this.contig;
@@ -345,8 +345,8 @@ private static Index createIndex(final File inputFile, final FeatureIterator ite
checkSorted(inputFile, lastFeature, currentFeature);
//should only visit chromosomes once
- final String curChr = currentFeature.getChr();
- final String lastChr = lastFeature != null ? lastFeature.getChr() : null;
+ final String curChr = currentFeature.getContig();
+ final String lastChr = lastFeature != null ? lastFeature.getContig() : null;
if(!curChr.equals(lastChr)){
if(visitedChromos.containsKey(curChr)){
String msg = "Input file must have contiguous chromosomes.";
@@ -369,15 +369,15 @@ private static Index createIndex(final File inputFile, final FeatureIterator ite
}
private static String featToString(final Feature feature){
- return feature.getChr() + ":" + feature.getStart() + "-" + feature.getEnd();
+ return feature.getContig() + ":" + feature.getStart() + "-" + feature.getEnd();
}
private static void checkSorted(final File inputFile, final Feature lastFeature, final Feature currentFeature){
// if the last currentFeature is after the current currentFeature, exception out
- if (lastFeature != null && currentFeature.getStart() < lastFeature.getStart() && lastFeature.getChr().equals(currentFeature.getChr()))
+ if (lastFeature != null && currentFeature.getStart() < lastFeature.getStart() && lastFeature.getContig().equals(currentFeature.getContig()))
throw new TribbleException.MalformedFeatureFile("Input file is not sorted by start position. \n" +
- "We saw a record with a start of " + currentFeature.getChr() + ":" + currentFeature.getStart() +
- " after a record with a start of " + lastFeature.getChr() + ":" + lastFeature.getStart(), inputFile.getAbsolutePath());
+ "We saw a record with a start of " + currentFeature.getContig() + ":" + currentFeature.getStart() +
+ " after a record with a start of " + lastFeature.getContig() + ":" + lastFeature.getStart(), inputFile.getAbsolutePath());
}
@@ -64,13 +64,13 @@ public IntervalIndexCreator(final File inputFile) {
public void addFeature(final Feature feature, final long filePosition) {
// if we don't have a chrIndex yet, or if the last one was for the previous contig, create a new one
- if (chrList.isEmpty() || !chrList.getLast().getName().equals(feature.getChr())) {
+ if (chrList.isEmpty() || !chrList.getLast().getName().equals(feature.getContig())) {
// if we're creating a new chrIndex (not the first), make sure to dump the intervals to the old chrIndex
if (!chrList.isEmpty())
addIntervalsToLastChr(filePosition);
// create a new chr index for the current contig
- chrList.add(new ChrIndex(feature.getChr()));
+ chrList.add(new ChrIndex(feature.getContig()));
intervals.clear();
}
@@ -66,14 +66,14 @@ public LinearIndexCreator(final File inputFile) {
*/
public void addFeature(final Feature feature, final long filePosition) {
// fi we don't have a chrIndex yet, or if the last one was for the previous contig, create a new one
- if (chrList.isEmpty() || !chrList.getLast().getName().equals(feature.getChr())) {
+ if (chrList.isEmpty() || !chrList.getLast().getName().equals(feature.getContig())) {
// if we're creating a new chrIndex (not the first), make sure to dump the blocks to the old chrIndex
if (!chrList.isEmpty())
for (int x = 0; x < blocks.size(); x++) {
blocks.get(x).setEndPosition((x + 1 == blocks.size()) ? filePosition : blocks.get(x + 1).getStartPosition());
chrList.getLast().addBlock(blocks.get(x));
}
- chrList.add(new LinearIndex.ChrIndex(feature.getChr(),binWidth));
+ chrList.add(new LinearIndex.ChrIndex(feature.getContig(),binWidth));
blocks.clear();
// Add the first block
@@ -73,7 +73,7 @@ public TabixIndexCreator(final TabixFormat formatSpec) {
@Override
public void addFeature(final Feature feature, final long filePosition) {
- final String sequenceName = feature.getChr();
+ final String sequenceName = feature.getContig();
final int referenceIndex;
if (sequenceName.equals(currentSequenceName)) {
referenceIndex = sequenceNames.size() - 1;
@@ -342,7 +342,7 @@
* @param other the VariantContext to copy
*/
protected VariantContext(VariantContext other) {
- this(other.getSource(), other.getID(), other.getChr(), other.getStart(), other.getEnd(),
+ this(other.getSource(), other.getID(), other.getContig(), other.getStart(), other.getEnd(),
other.getAlleles(), other.getGenotypes(), other.getLog10PError(),
other.getFiltersMaybeNull(),
other.getAttributes(),
@@ -1653,10 +1653,6 @@ private final Genotype fullyDecodeGenotypes(final Genotype g, final VCFHeader he
// tribble integration routines -- not for public consumption
//
// ---------------------------------------------------------------------------------------------------------
- @Deprecated
- public String getChr() {
- return getContig();
- }
@Override
public String getContig() {
@@ -84,7 +84,7 @@ public int compare(final VariantContext firstVariantContext, final VariantContex
// present. This error checking should already have been done in the constructor but it's left
// in as defence anyway.
final int contigCompare =
- this.contigIndexLookup.get(firstVariantContext.getChr()) - this.contigIndexLookup.get(secondVariantContext.getChr());
+ this.contigIndexLookup.get(firstVariantContext.getContig()) - this.contigIndexLookup.get(secondVariantContext.getContig());
return contigCompare != 0
? contigCompare
: firstVariantContext.getStart() - secondVariantContext.getStart();
@@ -59,7 +59,7 @@
static {
attributes.put("vc", (VariantContext vc) -> vc);
- attributes.put("CHROM", VariantContext::getChr);
+ attributes.put("CHROM", VariantContext::getContig);
attributes.put("POS", VariantContext::getStart);
attributes.put("TYPE", (VariantContext vc) -> vc.getType().toString());
attributes.put("QUAL", (VariantContext vc) -> -10 * vc.getLog10PError());
Oops, something went wrong.