Guest User

Untitled

a guest
Oct 13th, 2019
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.*;
  2. import java.util.*;
  3. import java.util.regex.*;
  4.  
  5. public class CountCosmicOccurrence {
  6. public static void main(String[] args) throws IOException {
  7. // input format:
  8. // annovar cosmic format
  9. // ID=COSM13127;OCCURENCE=12(stomach),2(endometrium),3(soft_tissue),158(large_intestine),2(pancreas),6(small_intestine)
  10. // the blank line will output 0
  11. // like "lofreq_CTCTUTOvlp_cosmic70"
  12. BufferedReader br = new BufferedReader(new FileReader(args[0]));
  13. String line = null;
  14. Pattern p = Pattern.compile("(\\d+)\\(");
  15. Matcher m = null;
  16. while((line = br.readLine()) != null) {
  17. if(line.equals("")) {
  18. System.out.println(0);
  19. } else {
  20. m = p.matcher(line);
  21. int count = 0;
  22. while(m.find()) {
  23. count += Integer.parseInt(m.group(1));
  24. }
  25. System.out.println(count);
  26. }
  27. }
  28. br.close();
  29. }
  30. }
RAW Paste Data