Skip to content

Commit bc057fe

Browse files
committed
Merge
2 parents aa2588e + 40e8400 commit bc057fe

17 files changed

+501
-1171
lines changed

src/main/java/tudelft/ti2806/pl3/data/Gender.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,19 @@
44
* Created by tombrouws on 15/06/15.
55
*/
66
public enum Gender {
7-
MALE, FEMALE
7+
MALE, FEMALE;
8+
9+
/**
10+
* Parses a string to {@code Gender}.
11+
*
12+
* @param string
13+
* the string to parse
14+
* @return the gender parsed
15+
*/
16+
public static Gender parse(String string) {
17+
if (string.equalsIgnoreCase("Male")) {
18+
return MALE;
19+
}
20+
return FEMALE;
21+
}
822
}

src/main/java/tudelft/ti2806/pl3/data/meta/MetaParser.java

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,68 @@
1616
* Created by tombrouws on 15/06/15.
1717
*/
1818
public class MetaParser {
19-
19+
2020
/**
2121
* Parses a metadata file and puts the information in genomes if they exist.
2222
*
2323
* @param metadata
24-
* the file to parse
24+
* the file to parse
2525
* @param genomeMap
26-
* the map of genomes to put the data in
26+
* the map of genomes to put the data in
2727
* @throws FileNotFoundException
28-
* when the file cannot be found
28+
* when the file cannot be found
2929
*/
3030
public static void parseMeta(File metadata, Map<String, Genome> genomeMap) throws FileNotFoundException {
31-
BufferedReader br = new BufferedReader(new InputStreamReader(
32-
new BufferedInputStream(new FileInputStream(metadata))));
31+
BufferedReader br = new BufferedReader(new InputStreamReader(new BufferedInputStream(new FileInputStream(
32+
metadata))));
33+
parseMeta(br, genomeMap);
34+
try {
35+
br.close();
36+
} catch (IOException e) {
37+
e.printStackTrace();
38+
}
39+
}
40+
41+
/**
42+
* Parses a metadata file and puts the information in genomes if they exist.
43+
*
44+
* @param br
45+
* the {@link BufferedReader} to read from
46+
* @param genomeMap
47+
* the map of genomes to put the data in
48+
*/
49+
private static void parseMeta(BufferedReader br, Map<String, Genome> genomeMap) {
3350
try {
3451
if (br.ready()) {
3552
br.readLine();
3653
}
3754
while (br.ready()) {
3855
String[] data = br.readLine().split("\t");
3956
data[0] = data[0].replaceAll("-", "_");
40-
if (genomeMap.containsKey(data[0])) {
41-
Genome g = genomeMap.get(data[0]);
42-
43-
if (data[1].equals("Negative")) {
44-
g.setHivStatus(false);
45-
} else {
46-
g.setHivStatus(true);
47-
}
48-
g.setAge(Integer.parseInt(data[2]));
49-
50-
if (data[3].equals("Male")) {
51-
g.setGender(Gender.MALE);
52-
} else {
53-
g.setGender(Gender.FEMALE);
54-
}
55-
56-
g.setLocation(data[4]);
57-
g.setIsolationDate(data[5]);
58-
}
57+
readData(data, genomeMap);
5958
}
6059
} catch (IOException e) {
6160
e.printStackTrace();
6261
}
6362
}
63+
64+
/**
65+
* Parses a piece of meta data for a single {@link Genome}.
66+
*
67+
* @param data
68+
* the string array to parse
69+
* @param genomeMap
70+
* the map of genomes to put the data in
71+
*/
72+
private static void readData(String[] data, Map<String, Genome> genomeMap) {
73+
if (!genomeMap.containsKey(data[0])) {
74+
return;
75+
}
76+
Genome g = genomeMap.get(data[0]);
77+
g.setHivStatus(!data[1].equals("Negative"));
78+
g.setAge(Integer.parseInt(data[2]));
79+
g.setGender(Gender.parse(data[3]));
80+
g.setLocation(data[4]);
81+
g.setIsolationDate(data[5]);
82+
}
6483
}

0 commit comments

Comments
 (0)