Advertisement
Guest User

Untitled

a guest
Sep 14th, 2013
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. package slidingwindow;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.HashMap;
  6. import java.util.Random;
  7.  
  8. public class RunThreads implements Runnable {
  9.  
  10.  
  11. private final double stat;
  12. private final Integer sims;
  13. private ArrayList<String> windows = new ArrayList<String>();
  14. private ArrayList<String> predictions = new ArrayList<String>();
  15.  
  16. public RunThreads(ArrayList<String> windows1, ArrayList<String> predictions1, double stat1, Integer sims1){
  17. this.windows = windows1;
  18. this.predictions = predictions1;
  19. this.stat = stat1;
  20. this.sims = sims1;
  21. }
  22.  
  23. public void run() {
  24. for(String window: windows) {
  25. String[] windowParts = window.split("\t");
  26. Integer firstPart = Integer.parseInt(windowParts[0]);
  27. Integer secondPart = Integer.parseInt(windowParts[1]);
  28. Integer firstMean = FindMeanSites(firstPart, stat, predictions, sims);
  29. Integer secondMean = FindMeanSites(secondPart, stat, predictions, sims);
  30. Integer slope = (secondMean - firstMean);
  31. System.out.println(firstPart + "\t" + secondPart + "\t" + slope);
  32. }
  33. }
  34.  
  35. public Integer FindMeanSites(Integer countReads, Double percentComplete, ArrayList<String> readArray, Integer sims) {
  36. Integer meanCount = 0;
  37. Integer simSlope = 0;
  38. Integer totalSlope = 0;
  39. for(Integer j = 0; j < sims; j++) {
  40. long seedValue = System.nanoTime();
  41. Collections.shuffle(readArray, new Random(seedValue));
  42. simSlope = GetSiteCount(countReads, percentComplete, readArray);
  43. totalSlope += simSlope;
  44. }
  45. meanCount = totalSlope/sims;
  46. return meanCount;
  47. }
  48.  
  49. public Integer GetSiteCount(Integer count, Double percent, ArrayList<String> reads) {
  50. Integer totalCount = 0;
  51. HashMap<String, String> found = new HashMap<String,String>();
  52. found.clear();
  53. Integer k = 0;
  54. for(Integer j = 0; j < count; j++) {
  55. long seed = System.nanoTime();
  56. Random generator = new Random(seed);
  57. double r = generator.nextDouble();
  58. if(r <= percent){
  59. String site = reads.get(k);
  60. k++;
  61. if(found.containsKey(site)) {
  62. } else {
  63. totalCount++;
  64. found.put(site, "FOUND");
  65. }
  66. }
  67. }
  68. return totalCount;
  69. }
  70.  
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement