-
Notifications
You must be signed in to change notification settings - Fork 1
/
CombineFiles.java
86 lines (73 loc) · 2.66 KB
/
CombineFiles.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class CombineFiles
{
public static void main(String[] args) throws IOException
{
/*
String szinputdir = args[0];
String szprefix = args[1];
int numportions = Integer.parseInt(args[2]);
String szoutputdir = args[3];
String szname = args[4];
String szdescription = args[5];
*/
String szinputdir = Constants.PORTIONSDIR;// "PREDICTIONSPORTIONS_UPDATED";
//String szprefix = args[0];//"predicts";
int numportions = Constants.NUMPORTIONS;//10;
String szoutputdir = Constants.COMBINEDDIR;// "COMBINED_UPDATED";
String szlabelfilelist = Constants.LABELLIST;//"labellist.txt";
String szchrom = args[0];//index = "chrorderlist.txt";
//String szname = "CNEP";
//String szdescription = "CNEP test";
File dir = new File(szoutputdir);
if (!dir.exists())
{
if (!dir.mkdirs())
{
throw new IllegalArgumentException(szoutputdir+" does not exist and could not be created!");
}
}
String szLabel;
BufferedReader brlabels = Util.getBufferedReader(szlabelfilelist);
while ((szLabel = brlabels.readLine())!=null)
{
GZIPOutputStream pw = new GZIPOutputStream(new FileOutputStream(szoutputdir+"/"+szLabel+"_"+szchrom+".wig.gz"));
byte[] btheader1 = ("track type=wiggle_0 name=\""+szLabel+"\""+" description=\""+szLabel+"\" visibility=2\n").getBytes();
pw.write(btheader1, 0, btheader1.length);
byte[] btheader2 = ("fixedStep chrom="+szchrom+" start=1 step=1\n").getBytes();
pw.write(btheader2, 0, btheader2.length);
for (int nportion = 0; nportion < numportions; nportion++)
{
BufferedReader br;
File f = new File(szinputdir+"/"+szLabel+"_"+szchrom+"_"+nportion+"_"+numportions+".wig.gz");
if (f.exists())
{
br = Util.getBufferedReader(szinputdir+"/"+szLabel+"_"+szchrom+"_"+nportion+"_"+numportions+".wig.gz");
}
else
{
f = new File(szinputdir+"/"+szLabel+"_"+szchrom+"_"+nportion+"_"+numportions+".wig");
if (f.exists())
{
br = Util.getBufferedReader(szinputdir+"/"+szLabel+"_"+szchrom+"_"+nportion+"_"+numportions+".wig");
}
else
{
throw new IllegalArgumentException("Not found "+szinputdir+"/"+szLabel+"_"+szchrom+"_"+nportion+"_"+numportions+".wig or "+
szinputdir+"/"+szLabel+"_"+szchrom+"_"+nportion+"_"+numportions+".wig.gz");
}
}
String szLine;
while ((szLine = br.readLine())!= null)
{
byte[] btformat =(szLine+"\n").getBytes();
pw.write(btformat,0,btformat.length);
}
}
pw.finish();
pw.close();
}
}
}