Download (right-click | Save Link As...) the DNA sequence of an Escherichia coli
ID: 3786323 • Letter: D
Question
Download (right-click | Save Link As...) the DNA sequence of an Escherichia coli (E Coli) bacterial strain, and save it in the root of your project directory.
Write a program thatScans the DNA sequence filename from the standard input (don't print a prompt to the user, just like in the Rock Countdown assignment). Note that the file sent will be an altered version of the file you saved above.
Your project must have a class named Main in a package named ecolicounts.
Reads in the file and prints out the number of A's, C's, G's, and T's in the sequence. The format should look like
#A = 1142136
#C = 1179433
#G = 1176775
#T = 1140877
Explanation / Answer
package ecolicounts;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String args[]) throws FileNotFoundException{
HashMap<Character, Long> characterCountMap = new HashMap<Character, Long>();
Scanner inputScanner = new Scanner(System.in);
String fileName = inputScanner.next();//Takes a string as input
Scanner scanner = new Scanner(new File(fileName));//file name "/home/kumar/Desktop/convert.py"
while(scanner.hasNext()){
String s = scanner.next();
for(int index=0;index<s.length();index++){
Character ch = s.charAt(index);
if(characterCountMap.get(ch) == null) characterCountMap.put(ch, 0l);
characterCountMap.put(ch, characterCountMap.get(ch)+1);
}
}
for(Character ch: characterCountMap.keySet()){
System.out.println("#"+ch+" = "+characterCountMap.get(ch));
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.