Advertisement
UrNotSorry

Computing GC Content

Jul 21st, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class ComputeGCContent {
  5.    
  6.     private static Double getGCContent(String dna) {
  7.         int gc = 0;
  8.         for (char symbol : dna.toCharArray()) {
  9.             if (symbol == 'G' || symbol == 'C') {
  10.                 gc++;
  11.             }
  12.         }
  13.         return (double) gc / dna.length() * 100;
  14.     }
  15.  
  16.     public static void main(String[] args) throws IOException {
  17.        
  18.         Scanner in = new Scanner(new File("input.txt"));
  19.         PrintWriter out = new PrintWriter(new File("output.txt"));
  20.        
  21.         TreeMap<Double, String> data = new TreeMap<Double, String>();
  22.        
  23.         while (in.hasNextLine()) {
  24.             String id = in.nextLine();
  25.             data.put(getGCContent(in.nextLine()), id);
  26.         }
  27.        
  28.         out.println(data.lastEntry().getValue() + " " + data.lastKey());
  29.        
  30.         in.close();
  31.         out.close();
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement