Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package slidingwindow;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Random;
- public class RunThreads implements Runnable {
- private final double stat;
- private final Integer sims;
- private ArrayList<String> windows = new ArrayList<String>();
- private ArrayList<String> predictions = new ArrayList<String>();
- public RunThreads(ArrayList<String> windows1, ArrayList<String> predictions1, double stat1, Integer sims1){
- this.windows = windows1;
- this.predictions = predictions1;
- this.stat = stat1;
- this.sims = sims1;
- }
- public void run() {
- for(String window: windows) {
- String[] windowParts = window.split("\t");
- Integer firstPart = Integer.parseInt(windowParts[0]);
- Integer secondPart = Integer.parseInt(windowParts[1]);
- Integer firstMean = FindMeanSites(firstPart, stat, predictions, sims);
- Integer secondMean = FindMeanSites(secondPart, stat, predictions, sims);
- Integer slope = (secondMean - firstMean);
- System.out.println(firstPart + "\t" + secondPart + "\t" + slope);
- }
- }
- public Integer FindMeanSites(Integer countReads, Double percentComplete, ArrayList<String> readArray, Integer sims) {
- Integer meanCount = 0;
- Integer simSlope = 0;
- Integer totalSlope = 0;
- for(Integer j = 0; j < sims; j++) {
- long seedValue = System.nanoTime();
- Collections.shuffle(readArray, new Random(seedValue));
- simSlope = GetSiteCount(countReads, percentComplete, readArray);
- totalSlope += simSlope;
- }
- meanCount = totalSlope/sims;
- return meanCount;
- }
- public Integer GetSiteCount(Integer count, Double percent, ArrayList<String> reads) {
- Integer totalCount = 0;
- HashMap<String, String> found = new HashMap<String,String>();
- found.clear();
- Integer k = 0;
- for(Integer j = 0; j < count; j++) {
- long seed = System.nanoTime();
- Random generator = new Random(seed);
- double r = generator.nextDouble();
- if(r <= percent){
- String site = reads.get(k);
- k++;
- if(found.containsKey(site)) {
- } else {
- totalCount++;
- found.put(site, "FOUND");
- }
- }
- }
- return totalCount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement