diff --git a/POMP-DETECT/CallBackTest.java b/POMP-DETECT/CallBackTest.java new file mode 100644 index 0000000..0fec801 --- /dev/null +++ b/POMP-DETECT/CallBackTest.java @@ -0,0 +1,190 @@ +//package multicore; + +//import spliced.Analyses; +//import spliced.Utilities; + +import java.io.BufferedWriter; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.lang.management.ThreadMXBean; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.*; + +public class CallBackTest { + + private static int NUM_OF_TASKS = 16; + Object result; + int cnt = 0; + long begTest, total_time; + + public CallBackTest() { + begTest = new java.util.Date().getTime(); + total_time = 0; + } + + public void callBack(Object result, List final_list) throws IOException { + this.result = result; + + for (Utilities.Information in : final_list) { + if (Math.abs(in.getLeft_boundary() - in.getRight_boundary()) >= + Utilities.min && Math.abs(in.getLeft_boundary() - in.getRight_boundary()) <= 200000) { + Utilities.informations.add(in); + } + } + + long id = java.lang.Thread.currentThread().getId(); + ThreadMXBean bean = ManagementFactory.getThreadMXBean(); + + if (!bean.isThreadCpuTimeSupported()) { + total_time += 0L; + } + + long t = bean.getThreadCpuTime(id); + + if (t != -1) { + total_time += t; + } + + if (++cnt == NUM_OF_TASKS) { + + try { + System.out.println("SLEEPING STARTED..."); + Thread.sleep(6000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + System.out.println("SLEEPING ENDED..."); + + String file_name = "OUT/predicted_introns.txt"; + String text; + + FileWriter fileWriter = new FileWriter(file_name, false); + BufferedWriter out = new BufferedWriter(fileWriter); + + for (int i = 0; i < Utilities.informations.size(); i++) { + Utilities.Information info = Utilities.informations.get(i); + + text = info.getLeft_boundary() + "\t" + info.getRight_boundary() + "\n"; + + out.write(text); + } + out.close(); + + file_name = "OUT/junctions_information.info"; + + fileWriter = new FileWriter(file_name, true); + out = new BufferedWriter(fileWriter); + + HashMap> hash_map = new HashMap>(); + + for (Utilities.Information junction : Utilities.informations) { + + int read_id = junction.getContig_id(); + int left_boundary = junction.getLeft_boundary(); + int right_boundary = junction.getRight_boundary(); + + + if (hash_map.containsKey(read_id)) { + + List infos = hash_map.get(read_id); + boolean accept = true; + + for (Utilities.Information info : infos) { + int _left = info.getLeft_boundary(); + int _right = info.getRight_boundary(); + + if (Math.abs(left_boundary - _left) <= 10 && Math.abs(right_boundary - _right) <= 10) { + accept = false; + break; + } + } + + if (accept) { + infos.add(junction); + } + + } else { + List infos = new ArrayList(); + infos.add(junction); + hash_map.put(read_id, infos); + } + } + + for (Object o : hash_map.entrySet()) { + Map.Entry entry = (Map.Entry) o; + List infos = (List) entry.getValue(); + + for (Utilities.Information junction : infos) { + + int read_id = junction.getContig_id(); + int left_mismatch = junction.getLeft_mismatch(); + int right_mismatch = junction.getRight_mismatch(); + int left_boundary = junction.getLeft_boundary(); + int right_boundary = junction.getRight_boundary(); + int left_length = junction.getLeft_length(); + int right_length = junction.getRight_length(); + int intron_length = junction.getIntron_length(); + int coverage = junction.isCoverage() ? 1 : 0; + + text = String.valueOf(read_id) + "\t" + String.valueOf(left_mismatch) + "\t" + String.valueOf(right_mismatch) + "\t" + + String.valueOf(left_boundary) + "\t" + String.valueOf(right_boundary) + "\t" + String.valueOf(left_length) + "\t" + + String.valueOf(right_length) + "\t" + String.valueOf(intron_length) + "\t" + String.valueOf(coverage) + "\n"; + + out.write(text); + } + } + + out.close(); + + Double secs = (new java.util.Date().getTime() - begTest) * 0.001; + System.out.println("WALL_CLOCK_RUN_TIME: " + secs + " secs"); + + double time_in_seconds = (double) total_time / 1000000000.0; + System.out.println("CPU_RUN_TIME -> " + time_in_seconds + " secs"); + + System.exit(0); + } + + } + + public void run(Utilities utilities) { + + int nrOfProcessors = Runtime.getRuntime().availableProcessors(); + System.out.println("PROCESSORS: " + nrOfProcessors); + NUM_OF_TASKS = nrOfProcessors; + NUM_OF_TASKS = Utilities.number_of_threads; + + ExecutorService es = Executors.newFixedThreadPool(nrOfProcessors); + int start = 0, end = 0; + + int hold = Utilities.union_list.size() / NUM_OF_TASKS; + + for (int i = 0; i < NUM_OF_TASKS; i++) { + + if (i == 0) { + start = 0; + end = hold; + } else if (i == NUM_OF_TASKS - 1) { + start = end + 1; + end = Utilities.union_list.size() - 1; + } else { + start = end + 1; + end = start + hold; + } + + CallBackTask task = new CallBackTask(i, start, end, utilities); + task.setCaller(this); + es.submit(task); + } + } + + public static void main(String[] args) throws IOException { + Utilities utilities = new Utilities("properties.prop"); + new CallBackTest().run(utilities); + } +}