Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import java.util.regex.*;
- public class CountCosmicOccurrence {
- public static void main(String[] args) throws IOException {
- // input format:
- // annovar cosmic format
- // ID=COSM13127;OCCURENCE=12(stomach),2(endometrium),3(soft_tissue),158(large_intestine),2(pancreas),6(small_intestine)
- // the blank line will output 0
- // like "lofreq_CTCTUTOvlp_cosmic70"
- BufferedReader br = new BufferedReader(new FileReader(args[0]));
- String line = null;
- Pattern p = Pattern.compile("(\\d+)\\(");
- Matcher m = null;
- while((line = br.readLine()) != null) {
- if(line.equals("")) {
- System.out.println(0);
- } else {
- m = p.matcher(line);
- int count = 0;
- while(m.find()) {
- count += Integer.parseInt(m.group(1));
- }
- System.out.println(count);
- }
- }
- br.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment