@@ -50,6 +50,8 @@ public class WIGExporterFromReadDB {
5050 private boolean loadType1 =true ;
5151 private boolean loadType2 =false ;
5252 private boolean loadPairs =false ;
53+ private boolean rpm =false ;
54+ private double totalReads =0 ;
5355 private Client client =null ;
5456 private List <String > exptNames = new ArrayList <String >();
5557 private List <SeqAlignment > aligns = new ArrayList <SeqAlignment >();
@@ -87,6 +89,7 @@ public WIGExporterFromReadDB(String [] args) {
8789 "\t --description <string to use as track description>\n " +
8890 "\t --ylimit <default track y max>\n " +
8991 "\t --color <R,G,B>\n " +
92+ "\t --rpm [read per million normalize]" +
9093 "\t --out <output file name>" );
9194 System .exit (1 );
9295 }
@@ -102,9 +105,9 @@ public WIGExporterFromReadDB(String [] args) {
102105 String strandStr = Args .parseString (args ,"strand" ,"." );
103106 strand = strandStr .charAt (0 );
104107 winSize = Args .parseInteger (args ,"winsize" ,winSize );
108+ rpm = Args .parseFlags (args ).contains ("rpm" ) ? true : false ;
105109
106110 //General options processed directly by ExptConfig
107-
108111 perBaseMax = Args .parseInteger (args ,"pbmax" ,perBaseMax );
109112 if (ap .hasKey ("ylimit" )){trackYMax =Args .parseInteger (args ,"ylimit" ,-1 );}
110113 winStep =winSize ;
@@ -114,6 +117,7 @@ public WIGExporterFromReadDB(String [] args) {
114117
115118 // Load the experiments
116119 sdloader = new SeqDataLoader ();
120+
117121 List <SeqLocator > rdbexpts = Args .parseSeqExpt (args ,"rdbexpt" );
118122 if (rdbexpts .size ()>0 ){
119123 //Start a new ReadDB client
@@ -143,6 +147,8 @@ public WIGExporterFromReadDB(String [] args) {
143147 if (alignment .getNumPairs ()>0 ){
144148 availPairedChroms .get (alignment ).addAll (client .getChroms (Integer .toString (alignment .getDBID ()), false ,true , null ));
145149 }
150+
151+ totalReads +=alignment .getTotalWeight ();
146152 }else {
147153 System .err .println ("ReadDBHitLoader: Error: " +alignment .getExpt ().getName ()+";" +alignment .getExpt ().getReplicate ()+";" +alignment .getName ()+"\t RDBID:" +alignment .getDBID ()+" does not exist in ReadDB." );
148154 System .exit (1 );
@@ -177,6 +183,7 @@ public void close(){
177183 public void execute (){
178184 try {
179185 FileWriter fw = new FileWriter (outName +".wig" );
186+ double millionReads = totalReads /1000000 ;
180187
181188 double basesDone =0 , printStep =10000000 , numPrint =0 ;
182189 if (trackName .equals ("out" ))
@@ -225,13 +232,19 @@ public void execute(){
225232 int binid = (int )Math .max (0 , ((double )(currWin .getStart ()-currSubRegion .getStart ())/winStep ));
226233 double winHits =(double )stackedHitCounts [binid ];
227234
235+ if (rpm )
236+ winHits /=millionReads ;
237+
228238 if (winHits >0 ){
229239 if (!recording ){
230240 //WIG is 1-based, inclusive (although bigWig is 0 based)
231241 fw .write ("fixedStep chrom=chr" +currSubRegion .getChrom ()+" start=" +i +" step=" +winStep +" span=" +winSize +"\n " );
232242 recording =true ;
233243 }
234- fw .write (String .format ("%.1f\n " , winHits ));
244+ if (rpm )
245+ fw .write (String .format ("%.4f\n " , winHits ));
246+ else
247+ fw .write (String .format ("%.1f\n " , winHits ));
235248 }else {
236249 recording =false ;
237250 }
@@ -263,7 +276,7 @@ private Pair<ArrayList<Integer>,ArrayList<Float>> loadStrandedBaseCounts(Region
263276 if (client ==null ) {
264277 client = new Client ();
265278 }
266-
279+ System . out . println ( r . getLocationString ()+ " requested" );
267280 allHits = client .getWeightHistogram (alignIDs ,
268281 r .getGenome ().getChromID (r .getChrom ()),
269282 loadType2 ,
0 commit comments