1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.format.keyword;
26
27 import java.io.BufferedReader;
28 import java.io.FileNotFoundException;
29 import java.io.FileReader;
30 import java.io.IOException;
31 import java.io.Reader;
32 import java.util.ArrayList;
33
34 import org.utgenome.format.keyword.GenomeKeywordEntry.KeywordAlias;
35 import org.xerial.util.StringUtil;
36 import org.xerial.util.log.Logger;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 public class KeywordAliasReader {
52
53 private static Logger _logger = Logger.getLogger(KeywordAliasReader.class);
54
55 private BufferedReader reader;
56 private int lineCount = 0;
57
58 public KeywordAliasReader(String file) throws FileNotFoundException {
59 this(new FileReader(file));
60 }
61
62 public KeywordAliasReader(Reader in) {
63 this.reader = new BufferedReader(in);
64 }
65
66
67
68
69
70
71
72 public KeywordAlias next() throws IOException {
73 String line = reader.readLine();
74 lineCount++;
75 if (line == null)
76 return null;
77
78 if (line.startsWith("#"))
79 return next();
80
81 String[] split = line.split("[\t ]+");
82 if (split.length < 2) {
83 _logger.warn(String.format("line %d has no alias: %s", lineCount, line));
84 return next();
85 }
86 else {
87 ArrayList<String> keywords = new ArrayList<String>();
88 for (int i = 1; i < split.length; ++i) {
89 keywords.add(split[i]);
90 }
91 return new KeywordAlias(split[0], StringUtil.join(keywords, " "));
92 }
93
94 }
95
96 }