annotate NGSrich_0.5.5/src/converters/Read2Wig.java @ 0:89ad0a9cca52 default tip

Uploaded
author pfrommolt
date Mon, 21 Nov 2011 08:12:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
1 package converters;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
2
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
3 import java.io.File;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
4 import java.io.FileNotFoundException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
5 import java.io.FileWriter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
6 import java.io.IOException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
7 import java.util.Scanner;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
8
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
9 import datastructures.GenomeFrame;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
10 import datastructures.ReadFrame;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
11 import datastructures.ReducedReadLine;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
12 import exceptions.ChromosomeFormatException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
13 import exceptions.ChromosomeNotFoundException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
14 import exceptions.RangeFormatException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
15 import exceptions.RangeLimitNotFoundException;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
16
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
17 import middlewares.Misc;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
18
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
19 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
20 * <P>This is a converter class, wich convert a reduced alignment file with the
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
21 * following format:</P>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
22 * <TABLE>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
23 * <TR>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
24 * <TD width= "140"><B>read-name</B></TD>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
25 * <TD width= "200"><B>chromosom-name</B></TD>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
26 * <TD width= "150"><B>start-position</B></TD>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
27 * <TD width= "200"><B>end-position</B></TD>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
28 * </TR>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
29 * <TR height=""></TR>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
30 * </TABLE>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
31 * <P>to the wiggle-format. The wiggle format (WIG) allows the display of continuous-
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
32 * valued data in a track format and it is used to visualize the read enrichment
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
33 * with the <a href="http://genome.ucsc.edu/cgi-bin/hgGateway" target="_new">ucsc genome browser</a>. Click on the following link:
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
34 * <a href="http://genome.ucsc.edu/goldenPath/help/wiggle.html" target="_new">
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
35 * http://genome.ucsc.edu/goldenPath/help/wiggle.html</a> for more information.</P>
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
36 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
37 * @author Ali Abdallah
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
38 * @version 06.01.2011
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
39 * @since jdk 1.6.0
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
40 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
41
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
42 public class Read2Wig {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
43
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
44 private static final int LENGTH = 1024;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
45 private File alignFile;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
46 private File outputFile;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
47 private String outputDir;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
48 private int gMin = Integer.MAX_VALUE;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
49 private int gMax = Integer.MIN_VALUE;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
50 private FileWriter tmpWigWriter;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
51
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
52 /**
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
53 * Constructs and initialzes a new Read2Wig object.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
54 * Converts the read alignment file to a overall covrage wig file.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
55 *
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
56 * @param alignFileName the name of the alignment file.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
57 * @throws IOException
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
58 */
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
59 public Read2Wig(String alignFileName,String outPrefix,String outputDir,String genome,String tmpDir) throws IOException{
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
60 // Das File-Objekt zur Behandlung der Alignment-Datei erzeugen.
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
61 this.alignFile = new File(alignFileName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
62 this.outputDir = outputDir+Misc.slash(outputDir);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
63 tmpWigWriter = new FileWriter(tmpDir+Misc.slash(tmpDir)+"tmpWig.wig");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
64 convert(alignFileName,this.outputDir,outPrefix);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
65 try{
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
66 wigToBigWig("hg19",tmpDir);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
67 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
68 catch(Exception e){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
69 System.err.println("Converting wig file to a bigwig file failed. " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
70 "Check whether you have a 64-bit linux system!");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
71 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
72 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
73
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
74 private void convert(String alignFileName, String outputDir,String outPrefix) throws FileNotFoundException, IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
75 Scanner s = new Scanner(this.alignFile);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
76 computeExtremas(s); s.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
77 Scanner readScanner = new Scanner(this.alignFile);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
78 alignFileName = Misc.prefix(alignFileName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
79 Scanner as = new Scanner(alignFileName);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
80 as.useDelimiter("_");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
81 as.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
82 outputFile = new File(outputDir+outPrefix+".wig");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
83 FileWriter fw = new FileWriter(outputFile);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
84
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
85 annotationHeader(fw);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
86
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
87 ReadFrame readF = computeNextRead(readScanner); //Current read frame
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
88 GenomeFrame frame = new GenomeFrame(readF.start(), LENGTH); //Current base frame
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
89 String chrom = readF.chrom(); //Current chromosome
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
90 if(frame.contains(readF)){frame.updateHits(readF);} //Sum up all hits of curr read
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
91 writeHeader(fw, frame, readF); //Write header line
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
92
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
93 while(true){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
94 while(readScanner.hasNextLine() && chrom.equals(readF.chrom()) && frame.contains(readF)){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
95 frame.updateHits(readF); readF = computeNextRead(readScanner);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
96 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
97 while(readScanner.hasNextLine() && chrom.equals(readF.chrom()) && frame.overlaps(readF) && !frame.limitExceeded(readF)){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
98 frame.updateFrameFromRightEnd(readF); frame.updateHits(readF); readF = computeNextRead(readScanner);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
99 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
100 if(!readScanner.hasNextLine()){break;}
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
101 else if(!chrom.equals(readF.chrom())){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
102 frame = new GenomeFrame(readF.start(), LENGTH);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
103 writeHeader(fw, frame, readF);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
104 chrom = readF.chrom();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
105 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
106 else if(!frame.overlaps(readF)){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
107 GenomeFrame last = frame; writeFrame(fw, last);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
108 frame = new GenomeFrame(readF.start(), LENGTH);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
109 writeFrameLeak(fw, last, frame, readF);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
110 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
111 else if(frame.limitExceeded(readF)){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
112 writeFramePortion(fw, frame, readF.start()); frame.updateFrameFromBothEnds(readF, LENGTH);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
113 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
114 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
115 fw.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
116 tmpWigWriter.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
117 readScanner.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
118 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
119
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
120 private void wigToBigWig(String genome,String tmpDir){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
121 String scriptDir = Misc.binDir()+Misc.slash(Misc.binDir());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
122 String wig2bw = scriptDir + "../thirdparty/wigToBigWig";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
123 String fetchChromSizes = scriptDir + "fetchChromSizes";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
124
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
125 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
126 Process p = Runtime.getRuntime().exec("sh "+fetchChromSizes+" "+genome);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
127 FileWriter fw = new FileWriter(outputDir+Misc.slash(outputDir)+genome+".chrom.sizes");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
128 Scanner s = new Scanner(p.getInputStream());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
129 while(s.hasNextLine())
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
130 fw.write(s.nextLine()+"\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
131 fw.close();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
132
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
133 Runtime.getRuntime().exec(wig2bw+" "+outputFile.getAbsolutePath()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
134 +" "+outputDir+Misc.slash(outputDir)+genome+".chrom.sizes "+
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
135 outputDir+Misc.slash(outputDir)+
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
136 Misc.prefix(outputFile.getAbsolutePath())+".bw");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
137 new File(outputDir+Misc.slash(outputDir)+genome+".chrom.sizes").delete();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
138 new File(tmpDir+Misc.slash(tmpDir)+"tmpWig.wig").delete();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
139 } catch (IOException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
140 // TODO Auto-generated catch block
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
141 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
142 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
143 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
144
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
145 private void computeExtremas(Scanner s){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
146 String chrom = "Datei falsch formatiert.";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
147 String oldChrom = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
148 int start = -1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
149 int end = -1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
150 String line = s.nextLine();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
151
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
152 oldChrom = chrom(line); start = start(line); end = end(line);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
153
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
154 while(s.hasNextLine()){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
155 line = s.nextLine();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
156 if(isHeader(line)){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
157 chrom = chrom(line); start = start(line); end = end(line);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
158 if(gMin > start && chrom.equals(oldChrom))
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
159 gMin = start;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
160
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
161 if(gMax < end && chrom.equals(oldChrom))
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
162 gMax = end;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
163 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
164 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
165 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
166
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
167 private boolean isHeader(String line){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
168 return line.indexOf("chr")!=-1;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
169 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
170
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
171 private int start(String line){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
172 Scanner s = new Scanner(line);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
173 s.next();s.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
174 return s.nextInt();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
175 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
176
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
177 private int end(String line){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
178 Scanner s = new Scanner(line);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
179 s.next();s.next();s.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
180 return s.nextInt();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
181 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
182
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
183 private String chrom(String line){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
184 Scanner s = new Scanner(line);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
185 s.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
186 return s.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
187 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
188
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
189 private void writeFramePortion(FileWriter fw, GenomeFrame frame, int start2) throws IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
190 for(int base = frame.start(); base < start2; base++){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
191 fw.write(frame.getHit(base)+"\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
192 tmpWigWriter.write(frame.getHit(base)+"\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
193 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
194 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
195
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
196 private void writeFrameLeak(FileWriter fw,
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
197 GenomeFrame last, GenomeFrame frame, ReadFrame read)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
198 throws IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
199 if(frame.start()-last.end() > 50){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
200 writeHeader(fw, frame, read);
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
201 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
202 else{
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
203 for(int i = 0; i < frame.start()-last.end()-1; i++){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
204 fw.write(0+"\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
205 tmpWigWriter.write(0+"\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
206 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
207 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
208 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
209
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
210 private void annotationHeader(FileWriter fw) throws IOException{
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
211 String browserLines = "browser position chr1:"+gMin+"-"+gMax+"\r\n"+
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
212 "browser hide all"+"\r\n"+
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
213 "browser pack refGene encodeRegions"+"\r\n"+
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
214 "browser full altGraph";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
215 Scanner as = new Scanner(alignFile.getName());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
216 as.useDelimiter("_");as.next();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
217 String trackLine = "track type=wiggle_0 name=\""+as.next()+"\" " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
218 "description=\"Base read coverage\" visibility=full " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
219 "color=0,0,0 altColor=255,0,0 priority=20 " +
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
220 "autoScale=on";
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
221 fw.write(browserLines+"\r\n"+trackLine+"\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
222 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
223
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
224 private void writeHeader(FileWriter fw, GenomeFrame frame, ReadFrame read)
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
225 throws IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
226 fw.write("fixedStep chrom="+read.chrom()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
227 +" start="+frame.start()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
228 + " step=1\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
229 tmpWigWriter.write("fixedStep chrom="+read.chrom()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
230 +" start="+frame.start()
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
231 + " step=1\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
232 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
233
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
234 private void writeFrame(FileWriter fw, GenomeFrame frame) throws IOException {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
235 // TODO Auto-generated method stub
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
236 for(int base = frame.start(); base <= frame.end(); base++){
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
237 fw.write(frame.getHit(base)+"\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
238 tmpWigWriter.write(frame.getHit(base)+"\r\n");
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
239 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
240 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
241
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
242 private ReadFrame computeNextRead(Scanner afScanner) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
243 ReducedReadLine rl = null;
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
244 try {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
245 rl = new ReducedReadLine(afScanner.nextLine());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
246 } catch (ChromosomeFormatException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
247 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
248 } catch (ChromosomeNotFoundException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
249 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
250 } catch (RangeFormatException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
251 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
252 } catch (RangeLimitNotFoundException e) {
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
253 e.printStackTrace();
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
254 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
255 return new ReadFrame(rl.name(), rl.chrom(), rl.start(), rl.end());
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
256 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
257
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
258 }
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
259
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
260
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
261
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
262
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
263
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
264
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
265
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
266
89ad0a9cca52 Uploaded
pfrommolt
parents:
diff changeset
267