Debian Codegraph @

src/dr/app/tools/SpliceBeastFiles.java

raw symbols SCIP
1 /*
2 * SpliceBeastFiles.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.tools;
27
28 import java.io.*;
29 import java.util.*;
30
31 /**
32 * Simple program to splice a set of (probably simulated) beast files containting sequences
33 * with a fixed second half containing some analysis setup. The first half, up to but not
34 * including the line '\t<patterns id="patterns" from="1">' comes from a set of XML numbered
35 * from 1 to 100, the second half is read from a specified file and a new set numbered 1 to
36 * 100 is created.
37 *
38 * @author Andrew Rambaut
39 * @version $Id$
40 */
41 public class SpliceBeastFiles {
42
43 public SpliceBeastFiles(String templateFileName, String inputFileStem, String outputFileStem) {
44 try {
45 List<String> template = new ArrayList<String>();
46
47 BufferedReader reader = new BufferedReader(new FileReader(templateFileName));
48 String line = reader.readLine();
49 while (line != null) {
50 template.add(line);
51 line = reader.readLine();
52 }
53
54 reader.close();
55
56 for (int i = 1; i < 201; i++) {
57 String number = (i < 10? "00" : (i < 100? "0" : "")) + i;
58 reader = new BufferedReader(new FileReader(inputFileStem + number + ".xml"));
59
60 PrintWriter writer = new PrintWriter(outputFileStem + number + ".xml");
61
62 line = reader.readLine();
63 while (line != null && !line.equals("\t<patterns id=\"patterns\" from=\"1\">")) {
64 writer.println(line);
65 line = reader.readLine();
66 }
67
68 for (String line1 : template) {
69 if (line1.contains("$stem")) {
70 line1 = line1.replace("$stem", "sim" + number);
71 }
72 writer.println(line1);
73 }
74
75 writer.close();
76
77 reader.close();
78 }
79 } catch (FileNotFoundException e) {
80 e.printStackTrace();
81 return;
82 } catch (IOException e) {
83 e.printStackTrace();
84 return;
85 }
86 }
87
88 public static void main(String[] argv) {
89 new SpliceBeastFiles(argv[0], argv[1], argv[2]);
90 }
91 }