Skip to content

Commit

Permalink
Version 1.16
Browse files Browse the repository at this point in the history
  • Loading branch information
jernst98 committed Jul 29, 2018
1 parent 4c11c75 commit d98a39a
Show file tree
Hide file tree
Showing 22 changed files with 2,299 additions and 618 deletions.
Binary file modified COORDS/ce10/RefSeqExon.ce10.bed.gz
Binary file not shown.
Binary file modified COORDS/ce11/RefSeqExon.ce11.bed.gz
Binary file not shown.
Binary file modified COORDS/ce6/RefSeqExon.ce6.bed.gz
Binary file not shown.
Binary file modified COORDS/danRer10/RefSeqExon.danRer10.bed.gz
Binary file not shown.
Binary file modified COORDS/danRer11/RefSeqExon.danRer11.bed.gz
Binary file not shown.
Binary file modified COORDS/danRer7/RefSeqExon.danRer7.bed.gz
Binary file not shown.
Binary file modified COORDS/dm3/RefSeqExon.dm3.bed.gz
Binary file not shown.
Binary file modified COORDS/dm6/RefSeqExon.dm6.bed.gz
Binary file not shown.
Binary file modified COORDS/hg18/RefSeqExon.hg18.bed.gz
Binary file not shown.
Binary file modified COORDS/hg19/RefSeqExon.hg19.bed.gz
Binary file not shown.
Binary file modified COORDS/hg38/RefSeqExon.hg38.bed.gz
Binary file not shown.
Binary file modified COORDS/mm10/RefSeqExon.mm10.bed.gz
Binary file not shown.
Binary file modified COORDS/mm9/RefSeqExon.mm9.bed.gz
Binary file not shown.
Binary file modified COORDS/rn5/RefSeqExon.rn5.bed.gz
Binary file not shown.
Binary file modified COORDS/rn6/RefSeqExon.rn6.bed.gz
Binary file not shown.
Binary file modified ChromHMM.jar
Binary file not shown.
Binary file modified ChromHMM.zip
Binary file not shown.
Binary file modified ChromHMM_manual.pdf
Binary file not shown.
327 changes: 239 additions & 88 deletions edu/mit/compbio/ChromHMM/BrowserOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.*;
import java.util.*;
import java.util.zip.GZIPOutputStream;

/**
* This class handles generating the browser output.
Expand Down Expand Up @@ -119,16 +120,22 @@ else if (n1 > n2)
*/
int numstates;

/**
* True if files should be in gzip format
*/
boolean bgzip;


public BrowserOutput(String szsegmentfile, String szcolormapping,String szidlabelmapping,
String szsegmentationname, String szoutputfileprefix, int numstates) throws IOException
String szsegmentationname, String szoutputfileprefix, int numstates, boolean bgzip) throws IOException
{
this.szsegmentfile = szsegmentfile;
this.szcolormapping =szcolormapping;
this.szidlabelmapping = szidlabelmapping;
this.szsegmentationname = szsegmentationname;
this.szoutputfileprefix = szoutputfileprefix;
this.numstates = numstates;
this.bgzip = bgzip;

hmcolor = new HashMap();
hmlabelExtend = new HashMap();
Expand Down Expand Up @@ -358,43 +365,95 @@ private void makeLabelMapping() throws IOException
*/
public void makebrowserdense() throws IOException
{
System.out.println("Writing to file "+szoutputfileprefix+ChromHMM.SZBROWSERDENSEEXTENSION+".bed");
PrintWriter pw = new PrintWriter(new FileWriter(szoutputfileprefix+ChromHMM.SZBROWSERDENSEEXTENSION+".bed"));
if (bgzip)
{
System.out.println("Writing to file "+szoutputfileprefix+ChromHMM.SZBROWSERDENSEEXTENSION+".bed.gz");
//PrintWriter pwzip = new PrintWriter(new FileWriter(szoutputfileprefix+ChromHMM.SZBROWSERDENSEEXTENSION+".bed.gz"));
GZIPOutputStream pwzip = new GZIPOutputStream(new FileOutputStream(szoutputfileprefix+ChromHMM.SZBROWSERDENSEEXTENSION+".bed.gz"));

BufferedReader brsegment = Util.getBufferedReader(szsegmentfile);
String szLine;
boolean bfirst = true;
BufferedReader brsegment = Util.getBufferedReader(szsegmentfile);
String szLine;
boolean bfirst = true;

while ((szLine =brsegment.readLine())!=null)
while ((szLine =brsegment.readLine())!=null)
{
StringTokenizer st = new StringTokenizer(szLine,"\t");
String szcurrchrom = st.nextToken();
int nbegin = Integer.parseInt(st.nextToken());
int nend = Integer.parseInt(st.nextToken());
String szFullID = st.nextToken();
String szID = szFullID.substring(1); //this removes ordering type
if (bfirst)
{
String szout = "track name=\""+szsegmentationname+"\" description=\" "+szsegmentationname+" ("+ChromHMM.convertCharOrderToStringOrder(szFullID.charAt(0))
+" ordered)"+"\" visibility=1 itemRgb=\"On\""+"\n";
byte[] btformat = szout.getBytes();
pwzip.write(btformat,0,btformat.length);
//pw.println("track name=\""+szsegmentationname+"\" description=\" "+szsegmentationname+" ("+ChromHMM.convertCharOrderToStringOrder(szFullID.charAt(0))
// +" ordered)"+"\" visibility=1 itemRgb=\"On\"");
bfirst = false;
}
String szColor = (String) hmcolor.get(szID);
if (szColor == null)
{
throw new IllegalArgumentException("Color not given for "+szID);
}

String szsuffix;
if ((szsuffix = (String) hmlabelExtend.get(szFullID))!=null)
{
szID = szID+"_"+szsuffix;
}

String szout = szcurrchrom+"\t"+nbegin+"\t"+nend+"\t"+szID+"\t0\t.\t"+nbegin+"\t"+nend+"\t"+szColor +"\n";
//pw.println(szcurrchrom+"\t"+nbegin+"\t"+nend+"\t"+szID+"\t0\t.\t"+nbegin+"\t"+nend+"\t"+szColor);
byte[] btformat = szout.getBytes();
pwzip.write(btformat,0,btformat.length);
}
brsegment.close();
pwzip.finish();
pwzip.close();
}
else
{
StringTokenizer st = new StringTokenizer(szLine,"\t");
String szcurrchrom = st.nextToken();
int nbegin = Integer.parseInt(st.nextToken());
int nend = Integer.parseInt(st.nextToken());
String szFullID = st.nextToken();
String szID = szFullID.substring(1); //this removes ordering type
if (bfirst)
{
pw.println("track name=\""+szsegmentationname+"\" description=\" "+szsegmentationname+" ("+ChromHMM.convertCharOrderToStringOrder(szFullID.charAt(0))
+" ordered)"+"\" visibility=1 itemRgb=\"On\"");
bfirst = false;
}
String szColor = (String) hmcolor.get(szID);
if (szColor == null)
{
throw new IllegalArgumentException("Color not given for "+szID);
}
System.out.println("Writing to file "+szoutputfileprefix+ChromHMM.SZBROWSERDENSEEXTENSION+".bed");
PrintWriter pw = new PrintWriter(new FileWriter(szoutputfileprefix+ChromHMM.SZBROWSERDENSEEXTENSION+".bed"));

String szsuffix;
if ((szsuffix = (String) hmlabelExtend.get(szFullID))!=null)
{
szID = szID+"_"+szsuffix;
}
BufferedReader brsegment = Util.getBufferedReader(szsegmentfile);
String szLine;
boolean bfirst = true;

pw.println(szcurrchrom+"\t"+nbegin+"\t"+nend+"\t"+szID+"\t0\t.\t"+nbegin+"\t"+nend+"\t"+szColor);
}
brsegment.close();
pw.close();
while ((szLine =brsegment.readLine())!=null)
{
StringTokenizer st = new StringTokenizer(szLine,"\t");
String szcurrchrom = st.nextToken();
int nbegin = Integer.parseInt(st.nextToken());
int nend = Integer.parseInt(st.nextToken());
String szFullID = st.nextToken();
String szID = szFullID.substring(1); //this removes ordering type
if (bfirst)
{
pw.println("track name=\""+szsegmentationname+"\" description=\" "+szsegmentationname+" ("+ChromHMM.convertCharOrderToStringOrder(szFullID.charAt(0))
+" ordered)"+"\" visibility=1 itemRgb=\"On\"");
bfirst = false;
}
String szColor = (String) hmcolor.get(szID);
if (szColor == null)
{
throw new IllegalArgumentException("Color not given for "+szID);
}

String szsuffix;
if ((szsuffix = (String) hmlabelExtend.get(szFullID))!=null)
{
szID = szID+"_"+szsuffix;
}

pw.println(szcurrchrom+"\t"+nbegin+"\t"+nend+"\t"+szID+"\t0\t.\t"+nbegin+"\t"+nend+"\t"+szColor);
}
brsegment.close();
pw.close();
}
}


Expand All @@ -407,8 +466,14 @@ public void makebrowserdense() throws IOException
*/
public void makebrowserexpanded() throws IOException
{
System.out.println("Writing to file "+szoutputfileprefix+ChromHMM.SZBROWSEREXPANDEDEXTENSION+".bed");
PrintWriter pw = new PrintWriter(new FileWriter(szoutputfileprefix+ChromHMM.SZBROWSEREXPANDEDEXTENSION+".bed"));
if (bgzip)
{
System.out.println("Writing to file "+szoutputfileprefix+ChromHMM.SZBROWSEREXPANDEDEXTENSION+".bed.gz");
}
else
{
System.out.println("Writing to file "+szoutputfileprefix+ChromHMM.SZBROWSEREXPANDEDEXTENSION+".bed");
}

String szLine;

Expand Down Expand Up @@ -491,62 +556,148 @@ public void makebrowserexpanded() throws IOException
}
Arrays.sort(szChroms);

pw.println("track name=\"Expanded_"+szsegmentationname+"\" description=\" "+szsegmentationname+" ("+ChromHMM.convertCharOrderToStringOrder(szLabelFull.charAt(0))
+" ordered)"+"\" visibility=2 itemRgb=\"On\"");
int nbrowserend = (int) (((Integer)hmchromMax.get(szChroms[0])).intValue()*.001)+1;
pw.println("browser position "+szChroms[0]+":1-"+nbrowserend);

for (int nlabel = szLabels.length-1; nlabel >=0; nlabel--)
if (bgzip)
{
//UCSC browser seems to reverse the ordering of browser track files
String szcolor = (String) hmcolor.get(""+szLabels[nlabel]);
for (int nchrom = 0; nchrom < szChroms.length; nchrom++)
{
//omits those segment labels not observed at all on chromosome
ArrayList alRecs = (ArrayList) hmcoords.get(szChroms[nchrom]+"\t"+szLabels[nlabel]);
if (alRecs == null) continue;

int nmax = ((Integer) hmchromMax.get(szChroms[nchrom])).intValue();

//this forces browser to display segment until the end of the chromosome
alRecs.add(new BeginEndRec(nmax-1,nmax));

int nsize = alRecs.size();
int nmin = ((BeginEndRec) alRecs.get(0)).nbegin;
int nfinalend = nmax;

String szoutlabel;
String szsuffix;
if ((szsuffix = (String) hmlabelExtend.get((String) hmlabelToFull.get(szLabels[nlabel])))!=null)
{
szoutlabel = szLabels[nlabel]+"_"+szsuffix;
}
else
{
szoutlabel = szLabels[nlabel];
}
GZIPOutputStream pwzip = new GZIPOutputStream(new FileOutputStream(szoutputfileprefix+ChromHMM.SZBROWSEREXPANDEDEXTENSION+".bed.gz"));
String szout = "track name=\"Expanded_"+szsegmentationname+"\" description=\" "+szsegmentationname+" ("+ChromHMM.convertCharOrderToStringOrder(szLabelFull.charAt(0))
+" ordered)"+"\" visibility=2 itemRgb=\"On\""+"\n";
byte[] btformat = szout.getBytes();
pwzip.write(btformat,0,btformat.length);

//pw.println("track name=\"Expanded_"+szsegmentationname+"\" description=\" "+szsegmentationname+" ("+ChromHMM.convertCharOrderToStringOrder(szLabelFull.charAt(0))
// +" ordered)"+"\" visibility=2 itemRgb=\"On\"");
int nbrowserend = (int) (((Integer)hmchromMax.get(szChroms[0])).intValue()*.001)+1;

szout = "browser position "+szChroms[0]+":1-"+nbrowserend+"\n";
btformat = szout.getBytes();
pwzip.write(btformat,0,btformat.length);
//pwzip.println("browser position "+szChroms[0]+":1-"+nbrowserend);

for (int nlabel = szLabels.length-1; nlabel >=0; nlabel--)
{
//UCSC browser seems to reverse the ordering of browser track files
String szcolor = (String) hmcolor.get(""+szLabels[nlabel]);
for (int nchrom = 0; nchrom < szChroms.length; nchrom++)
{
//omits those segment labels not observed at all on chromosome
ArrayList alRecs = (ArrayList) hmcoords.get(szChroms[nchrom]+"\t"+szLabels[nlabel]);
if (alRecs == null) continue;

int nmax = ((Integer) hmchromMax.get(szChroms[nchrom])).intValue();

//this forces browser to display segment until the end of the chromosome
alRecs.add(new BeginEndRec(nmax-1,nmax));

int nsize = alRecs.size();
int nmin = ((BeginEndRec) alRecs.get(0)).nbegin;
int nfinalend = nmax;

String szoutlabel;
String szsuffix;
if ((szsuffix = (String) hmlabelExtend.get((String) hmlabelToFull.get(szLabels[nlabel])))!=null)
{
szoutlabel = szLabels[nlabel]+"_"+szsuffix;
}
else
{
szoutlabel = szLabels[nlabel];
}

StringBuffer sbout = new StringBuffer();
sbout.append(szChroms[nchrom]+"\t"+0+"\t"+nfinalend+"\t"+szoutlabel+"\t0\t.\t"+nmin+"\t"+nfinalend+"\t"+szcolor+"\t"+(nsize+1)+"\t");
//pw.print(szChroms[nchrom]+"\t"+0+"\t"+nfinalend+"\t"+szoutlabel+"\t0\t.\t"+nmin+"\t"+nfinalend+"\t"+szcolor+"\t"+(nsize+1)+"\t");
//pw.print(0); //forcing the display to start at the beginning of the chromosome
sbout.append(0);
for (int ni = 0; ni < nsize; ni++)
{
BeginEndRec theBeginEndRec = (BeginEndRec) alRecs.get(ni);
int ndiff = theBeginEndRec.nend - theBeginEndRec.nbegin;
sbout.append(",");
sbout.append(ndiff);
//pw.print(",");
//pw.print(ndiff);
}
sbout.append("\t");
sbout.append(0);
//pw.print("\t");
//pw.print(0);
for (int ni = 0; ni < nsize; ni++)
{
int nloc = ((BeginEndRec) alRecs.get(ni)).nbegin;
sbout.append(",");
sbout.append(nloc);
//pw.print(",");
//pw.print(nloc);
}
sbout.append("\n");
// pw.println();
btformat = sbout.toString().getBytes();
pwzip.write(btformat,0,btformat.length);
}
}
pwzip.finish();
pwzip.close();
}
else
{
PrintWriter pw = new PrintWriter(new FileWriter(szoutputfileprefix+ChromHMM.SZBROWSEREXPANDEDEXTENSION+".bed"));
pw.println("track name=\"Expanded_"+szsegmentationname+"\" description=\" "+szsegmentationname+" ("+ChromHMM.convertCharOrderToStringOrder(szLabelFull.charAt(0))
+" ordered)"+"\" visibility=2 itemRgb=\"On\"");
int nbrowserend = (int) (((Integer)hmchromMax.get(szChroms[0])).intValue()*.001)+1;
pw.println("browser position "+szChroms[0]+":1-"+nbrowserend);

pw.print(szChroms[nchrom]+"\t"+0+"\t"+nfinalend+"\t"+szoutlabel+"\t0\t.\t"+nmin+"\t"+nfinalend+"\t"+szcolor+"\t"+(nsize+1)+"\t");
pw.print(0); //forcing the display to start at the beginning of the chromosome
for (int ni = 0; ni < nsize; ni++)
{
BeginEndRec theBeginEndRec = (BeginEndRec) alRecs.get(ni);
int ndiff = theBeginEndRec.nend - theBeginEndRec.nbegin;
pw.print(",");
pw.print(ndiff);
}
pw.print("\t");
pw.print(0);
for (int ni = 0; ni < nsize; ni++)
{
int nloc = ((BeginEndRec) alRecs.get(ni)).nbegin;
pw.print(",");
pw.print(nloc);
}
pw.println();
}
for (int nlabel = szLabels.length-1; nlabel >=0; nlabel--)
{
//UCSC browser seems to reverse the ordering of browser track files
String szcolor = (String) hmcolor.get(""+szLabels[nlabel]);
for (int nchrom = 0; nchrom < szChroms.length; nchrom++)
{
//omits those segment labels not observed at all on chromosome
ArrayList alRecs = (ArrayList) hmcoords.get(szChroms[nchrom]+"\t"+szLabels[nlabel]);
if (alRecs == null) continue;

int nmax = ((Integer) hmchromMax.get(szChroms[nchrom])).intValue();

//this forces browser to display segment until the end of the chromosome
alRecs.add(new BeginEndRec(nmax-1,nmax));

int nsize = alRecs.size();
int nmin = ((BeginEndRec) alRecs.get(0)).nbegin;
int nfinalend = nmax;

String szoutlabel;
String szsuffix;
if ((szsuffix = (String) hmlabelExtend.get((String) hmlabelToFull.get(szLabels[nlabel])))!=null)
{
szoutlabel = szLabels[nlabel]+"_"+szsuffix;
}
else
{
szoutlabel = szLabels[nlabel];
}

pw.print(szChroms[nchrom]+"\t"+0+"\t"+nfinalend+"\t"+szoutlabel+"\t0\t.\t"+nmin+"\t"+nfinalend+"\t"+szcolor+"\t"+(nsize+1)+"\t");
pw.print(0); //forcing the display to start at the beginning of the chromosome
for (int ni = 0; ni < nsize; ni++)
{
BeginEndRec theBeginEndRec = (BeginEndRec) alRecs.get(ni);
int ndiff = theBeginEndRec.nend - theBeginEndRec.nbegin;
pw.print(",");
pw.print(ndiff);
}
pw.print("\t");
pw.print(0);
for (int ni = 0; ni < nsize; ni++)
{
int nloc = ((BeginEndRec) alRecs.get(ni)).nbegin;
pw.print(",");
pw.print(nloc);
}
pw.println();
}
}
pw.close();
}
pw.close();
}
}

Loading

0 comments on commit d98a39a

Please sign in to comment.