Skip to content

Instantly share code, notes, and snippets.

@masters3d
Created September 27, 2015 04:46
Show Gist options
  • Save masters3d/12f973f262e957b2c998 to your computer and use it in GitHub Desktop.
Save masters3d/12f973f262e957b2c998 to your computer and use it in GitHub Desktop.
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Arrays;
import java.util.List;
//java.lang.AssertionError: expecting:
// <{'A'=0, 'C'=0, 'G'=0, 'T'=0}>
// to contain:
// <[MapEntry[key=A, value=0], MapEntry[key=C, value=0], MapEntry[key=G, value=0], MapEntry[key=T, value=0]]>
// but could not find:
// <[MapEntry[key=A, value=0], MapEntry[key=C, value=0], MapEntry[key=G, value=0], MapEntry[key=T, value=0]]>
public class DNA {
public String strand = "Nothing";
DNA(String strand) {
if (checkValidStand(strand)) {
this.strand = strand;
}
}
public static void main(String[] args) {
DNA newDNA = new DNA("");
// System.out.println(newDNA.strand);
System.out.println(newDNA.nucleotideCounts());
}
private Boolean checkValidStand(String inString) {
return Boolean.TRUE;
// TODO: 9/25/15
// Add Code to make this work
}
public Integer count(Character individual) {
return count(String.valueOf(individual));
}
public Integer count(String individual) {
List<String> items = Arrays.asList(strand.trim().split(individual));
System.out.println(items.toArray()[0]);
if (items.isEmpty()) {
return 0;
} else if (items.toArray()[0] == "" ) {
return 0;
}else {
return items.toArray().length;
}
}
public Map<String, Integer> nucleotideCounts() {
Map<String, Integer> dictReturn = new LinkedHashMap<String, Integer>();
List<String> atgc = Arrays.asList("ACGT".split(""));
//atgc.remove(0);
for (String each: atgc){
if (!each.equals("")) {
Integer result = Arrays.asList(strand.trim().split(each)).size() - 1;
if (strand.contains(each)) {
dictReturn.put(each, result);
} else {
dictReturn.put(each, 0);
}
}
}
return dictReturn;
// TODO: 9/25/15
// Add Code to make this work
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment