
org.snpeff.probablility.bootstrap.ReSampleMapRank Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SnpEff Show documentation
Show all versions of SnpEff Show documentation
Variant annotation and effect prediction package.
The newest version!
package org.snpeff.probablility.bootstrap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
/**
* Re-sample statistic using ranks of scores (scores are double)
*
* @author pablocingolani
*/
public class ReSampleMapRank extends ReSampleInt {
HashMap scoreByName; // All name-score relations
HashMap rankByName;
public ReSampleMapRank(HashMap scoresByName, int sampleSize) {
super(null, sampleSize);
scoreByName = scoresByName;
// Create a list ordered by score
ArrayList names = new ArrayList();
names.addAll(scoresByName.keySet());
Collections.sort(names, new Comparator() {
@Override
public int compare(String arg0, String arg1) {
return scoreByName.get(arg0).compareTo(scoreByName.get(arg1));
}
});
// Populate rank list
rankByName = new HashMap();
scores = new int[names.size()];
double latest = Double.NaN;
int rank = 0;
for( int i = 0; i < names.size(); i++ ) {
String name = names.get(i);
double score = scoresByName.get(name);
if( latest != score ) rank++;
latest = score;
rankByName.put(name, rank);
scores[i] = rank;
}
}
public int score(Collection names) {
int sum = 0;
for( String name : names ) {
if( rankByName.get(name) == null ) throw new RuntimeException("Error: Entry '" + name + "' not found!");
sum += rankByName.get(name);
}
return sum;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy