5285 |
24 Mar 10 |
nicklas |
1 |
|
5285 |
24 Mar 10 |
nicklas |
2 |
/* |
5285 |
24 Mar 10 |
nicklas |
$Id $ |
5285 |
24 Mar 10 |
nicklas |
4 |
|
5285 |
24 Mar 10 |
nicklas |
Copyright (C) 2010 Nicklas Nordborg |
5285 |
24 Mar 10 |
nicklas |
6 |
|
5285 |
24 Mar 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5285 |
24 Mar 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5285 |
24 Mar 10 |
nicklas |
9 |
|
5285 |
24 Mar 10 |
nicklas |
BASE is free software; you can redistribute it and/or |
5285 |
24 Mar 10 |
nicklas |
modify it under the terms of the GNU General Public License |
5285 |
24 Mar 10 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5285 |
24 Mar 10 |
nicklas |
of the License, or (at your option) any later version. |
5285 |
24 Mar 10 |
nicklas |
14 |
|
5285 |
24 Mar 10 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5285 |
24 Mar 10 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5285 |
24 Mar 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5285 |
24 Mar 10 |
nicklas |
GNU General Public License for more details. |
5285 |
24 Mar 10 |
nicklas |
19 |
|
5285 |
24 Mar 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5285 |
24 Mar 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5285 |
24 Mar 10 |
nicklas |
22 |
*/ |
5285 |
24 Mar 10 |
nicklas |
23 |
import java.io.BufferedReader; |
5285 |
24 Mar 10 |
nicklas |
24 |
import java.io.File; |
5285 |
24 Mar 10 |
nicklas |
25 |
import java.io.IOException; |
5285 |
24 Mar 10 |
nicklas |
26 |
import java.io.InputStreamReader; |
5285 |
24 Mar 10 |
nicklas |
27 |
import java.io.PrintWriter; |
5285 |
24 Mar 10 |
nicklas |
28 |
|
5285 |
24 Mar 10 |
nicklas |
29 |
/** |
5285 |
24 Mar 10 |
nicklas |
A simple program that expects a BFS metadata file |
5285 |
24 Mar 10 |
nicklas |
as input. If a [files] section is found it will add |
5285 |
24 Mar 10 |
nicklas |
a couple of extra file entries to it. |
5285 |
24 Mar 10 |
nicklas |
It accepts one parameter on the command line: |
5285 |
24 Mar 10 |
nicklas |
34 |
|
5285 |
24 Mar 10 |
nicklas |
nosdata: Remove the [sdata] section and a all file |
5285 |
24 Mar 10 |
nicklas |
entries in the files section. |
5285 |
24 Mar 10 |
nicklas |
37 |
|
5285 |
24 Mar 10 |
nicklas |
@author nicklas |
5285 |
24 Mar 10 |
nicklas |
@since 2.15 |
5285 |
24 Mar 10 |
nicklas |
40 |
*/ |
5285 |
24 Mar 10 |
nicklas |
41 |
public class BfsExtraFileGenerator |
5285 |
24 Mar 10 |
nicklas |
42 |
{ |
5285 |
24 Mar 10 |
nicklas |
43 |
public static void main(String[] args) |
5285 |
24 Mar 10 |
nicklas |
44 |
{ |
5285 |
24 Mar 10 |
nicklas |
45 |
String cmd = args.length > 0 ? args[0] : null; |
5285 |
24 Mar 10 |
nicklas |
46 |
boolean nosdata = "nosdata".equals(cmd); |
5285 |
24 Mar 10 |
nicklas |
47 |
|
5285 |
24 Mar 10 |
nicklas |
48 |
try |
5285 |
24 Mar 10 |
nicklas |
49 |
{ |
5285 |
24 Mar 10 |
nicklas |
50 |
BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); |
5285 |
24 Mar 10 |
nicklas |
51 |
String line = in.readLine(); |
5285 |
24 Mar 10 |
nicklas |
52 |
boolean skipSection = false; |
5285 |
24 Mar 10 |
nicklas |
53 |
|
5285 |
24 Mar 10 |
nicklas |
54 |
while (line != null) |
5285 |
24 Mar 10 |
nicklas |
55 |
{ |
5285 |
24 Mar 10 |
nicklas |
56 |
if (skipSection) |
5285 |
24 Mar 10 |
nicklas |
57 |
{ |
5285 |
24 Mar 10 |
nicklas |
// Skip lines until a new section is found |
5285 |
24 Mar 10 |
nicklas |
59 |
if (line.startsWith("[")) |
5285 |
24 Mar 10 |
nicklas |
60 |
{ |
5285 |
24 Mar 10 |
nicklas |
61 |
skipSection = false; |
5285 |
24 Mar 10 |
nicklas |
62 |
} |
5285 |
24 Mar 10 |
nicklas |
63 |
else |
5285 |
24 Mar 10 |
nicklas |
64 |
{ |
5285 |
24 Mar 10 |
nicklas |
65 |
line = null; |
5285 |
24 Mar 10 |
nicklas |
66 |
} |
5285 |
24 Mar 10 |
nicklas |
67 |
} |
5285 |
24 Mar 10 |
nicklas |
68 |
|
5285 |
24 Mar 10 |
nicklas |
69 |
if ("[files]".equals(line)) |
5285 |
24 Mar 10 |
nicklas |
70 |
{ |
5285 |
24 Mar 10 |
nicklas |
// Print out extra files |
5285 |
24 Mar 10 |
nicklas |
72 |
line = |
5285 |
24 Mar 10 |
nicklas |
73 |
"[files]\n" + |
5285 |
24 Mar 10 |
nicklas |
74 |
"x-file1\tfile1.txt\n" + |
5285 |
24 Mar 10 |
nicklas |
75 |
"x-file2\tfile2.txt"; |
5285 |
24 Mar 10 |
nicklas |
76 |
skipSection = nosdata; |
5285 |
24 Mar 10 |
nicklas |
77 |
} |
5285 |
24 Mar 10 |
nicklas |
78 |
else if ("[sdata]".equals(line)) |
5285 |
24 Mar 10 |
nicklas |
79 |
{ |
5285 |
24 Mar 10 |
nicklas |
80 |
skipSection = nosdata; |
5285 |
24 Mar 10 |
nicklas |
81 |
if (skipSection) line = null; |
5285 |
24 Mar 10 |
nicklas |
82 |
} |
5285 |
24 Mar 10 |
nicklas |
83 |
if (line != null) System.out.println(line); |
5285 |
24 Mar 10 |
nicklas |
84 |
line = in.readLine(); |
5285 |
24 Mar 10 |
nicklas |
85 |
} |
5285 |
24 Mar 10 |
nicklas |
86 |
|
5285 |
24 Mar 10 |
nicklas |
87 |
createFile("file1.txt"); |
5285 |
24 Mar 10 |
nicklas |
88 |
createFile("file2.txt"); |
5285 |
24 Mar 10 |
nicklas |
89 |
} |
5285 |
24 Mar 10 |
nicklas |
90 |
catch (Throwable t) |
5285 |
24 Mar 10 |
nicklas |
91 |
{ |
5285 |
24 Mar 10 |
nicklas |
92 |
t.printStackTrace(); |
5285 |
24 Mar 10 |
nicklas |
93 |
System.exit(1); |
5285 |
24 Mar 10 |
nicklas |
94 |
} |
5285 |
24 Mar 10 |
nicklas |
95 |
} |
5285 |
24 Mar 10 |
nicklas |
96 |
|
5285 |
24 Mar 10 |
nicklas |
97 |
private static void createFile(String name) |
5285 |
24 Mar 10 |
nicklas |
98 |
throws IOException |
5285 |
24 Mar 10 |
nicklas |
99 |
{ |
5285 |
24 Mar 10 |
nicklas |
100 |
File f = new File(name); |
5285 |
24 Mar 10 |
nicklas |
101 |
PrintWriter pw = new PrintWriter(f); |
5285 |
24 Mar 10 |
nicklas |
102 |
for (int i = 0; i < 100; ++i) |
5285 |
24 Mar 10 |
nicklas |
103 |
{ |
5285 |
24 Mar 10 |
nicklas |
104 |
pw.println(Math.random()); |
5285 |
24 Mar 10 |
nicklas |
105 |
} |
5285 |
24 Mar 10 |
nicklas |
106 |
pw.close(); |
5285 |
24 Mar 10 |
nicklas |
107 |
} |
5285 |
24 Mar 10 |
nicklas |
108 |
|
5285 |
24 Mar 10 |
nicklas |
109 |
} |