Skip to content

Commit

Permalink
more mods to anchor annotation tools
Browse files Browse the repository at this point in the history
  • Loading branch information
suhas-rao committed Jan 11, 2022
1 parent dc47f16 commit 6202b43
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/juicebox/data/anchor/GenericLocus.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public void mergeWithTakeSmaller(GenericLocus anchor) {

@Override
public String toString() {
return "chr" + chr + "\t" + x1 + "\t" + x2;
String chrString = chr.startsWith("chr") ? chr.substring(3) : chr;
return "chr" + chrString + "\t" + x1 + "\t" + x2;
}

@Override
Expand Down
34 changes: 18 additions & 16 deletions src/juicebox/tools/clt/juicer/Localizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ public class Localizer extends JuicerCLT {
//defaults
// TODO right now these units are based on n*res/sqrt(2)
// TODO the sqrt(2) scaling should be removed (i.e. handle scaling internally)
private int window = 10;
private int window = 1;
private int expandSize = 2500;
private int numLocalizedPeaks = 1;
private int[] resolutions = new int[]{10};
private int[] resolutions = new int[]{100};
private int[] regionWidths = new int[]{window};
private boolean includeInterChr = false;
private Feature2DList finalLoopList = new Feature2DList();
Expand Down Expand Up @@ -167,7 +167,7 @@ public void run() {

AtomicInteger[] gwPeakNumbers = {new AtomicInteger(0), new AtomicInteger(0), new AtomicInteger(0)};

System.out.println("Processing Localizer for resolution " + resolution);
System.out.println("Processing Localizer for resolution " + resolution + " with window " + window);
HiCZoom zoom = new HiCZoom(HiC.Unit.BP, resolution);

ChromosomeHandler handler = ds.getChromosomeHandler();
Expand All @@ -194,7 +194,7 @@ public List<Feature2D> filter(String chr, List<Feature2D> features) {
GenomeWideList<GenericLocus> featureAnchors = GenericLocusTools.extractAnchorsFromIntrachromosomalFeatures(loopList,
false, handler, expandSize);
GenericLocusTools.updateOriginalFeatures(featureAnchors, "coarse");
featureAnchors.simpleExport(new File(outputDirectory, "coarseLoopAnchors_"+expandSize+".bed"));
//featureAnchors.simpleExport(new File(outputDirectory, "coarseLoopAnchors_"+expandSize+".bed"));


double maxProgressStatus = handler.size();
Expand Down Expand Up @@ -256,11 +256,14 @@ public void run() {
try {

// set radius to search for localization, uses radius attribute from HiCCUPS, otherwise uses defaults
int radius = (int) Float.parseFloat(loop.getAttribute("radius")) / resolution;
int radius = 0;
if (loop.containsAttributeKey("radius")) {
radius = (int) Float.parseFloat(loop.getAttribute("radius")) / resolution;
}
if (radius <= 0) {
radius = (int) (loop.getEnd1() - loop.getStart1()) / resolution;
} else if (radius <= 1000 / resolution) {
radius = 1000 / resolution;
} else if (radius <= 2000 / resolution) {
radius = 2000 / resolution;
}

// load raw data and relevant portions of norm vector
Expand Down Expand Up @@ -359,14 +362,13 @@ public void run() {
System.err.println("Unable to find data for loop: " + loop);
}
}
Instant B = Instant.now();
//System.out.println("Localization Chunk " + threadChunk + ": " + Duration.between(A,B).toMillis());

int reasonableDivisor = Math.max(numOfLoopChunks / 20, 1);
if (HiCGlobals.printVerboseComments || threadChunk % reasonableDivisor == 0) {
DecimalFormat df = new DecimalFormat("#.####");
df.setRoundingMode(RoundingMode.FLOOR);
System.out.println(df.format(Math.floor((100.0 * threadChunk) / numOfLoopChunks)) + "% ");
}
//if (HiCGlobals.printVerboseComments || threadChunk % reasonableDivisor == 0) {
// DecimalFormat df = new DecimalFormat("#.####");
// df.setRoundingMode(RoundingMode.FLOOR);
// System.out.println(df.format(Math.floor((100.0 * threadChunk) / numOfLoopChunks)) + "% ");
//}
threadChunk = loopChunk.getAndIncrement();
}
}
Expand All @@ -386,14 +388,14 @@ public void run() {
// output primary list
GenericLocusTools.callMergeAnchors(highResAnchorPrimaryList);
GenericLocusTools.updateOriginalFeatures(highResAnchorPrimaryList, "highRes");
highResAnchorPrimaryList.simpleExport(new File(outputDirectory, "highRes_primary_loopAnchors.bed"));
//highResAnchorPrimaryList.simpleExport(new File(outputDirectory, "highRes_primary_loopAnchors.bed"));
finalPrimaryLoopList.exportFeatureList(new File(outputDirectory, "localizedList_primary_"+resolution+".bedpe"), true, Feature2DList.ListFormat.LOCALIZED);

// output secondary list if number of requested localized peaks > 1
if (numLocalizedPeaks > 1) {
GenericLocusTools.callMergeAnchors(highResAnchorList);
GenericLocusTools.updateOriginalFeatures(highResAnchorList, "highRes");
highResAnchorList.simpleExport(new File(outputDirectory, "highRes_loopAnchors.bed"));
//highResAnchorList.simpleExport(new File(outputDirectory, "highRes_loopAnchors.bed"));
finalLoopList.exportFeatureList(new File(outputDirectory, "localizedList_" + resolution + ".bedpe"), true, Feature2DList.ListFormat.LOCALIZED);
}
} else {
Expand Down
6 changes: 6 additions & 0 deletions src/juicebox/track/feature/Feature2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ private String justColorString() {
public String simpleStringWithColor() {
if (HiCGlobals.isLegacyOutputPrintingEnabled) {
return simpleString() + justColorString();
} else if (this.containsAttributeKey("score")) {
return simpleString() + "\t.\t" + this.attributes.get("score") + "\t.\t." + justColorString();
} else {
return simpleString() + BEDPE_SPACER + justColorString();
}
Expand Down Expand Up @@ -438,6 +440,10 @@ public boolean containsAttributeValue(String attribute) {
return attributes.containsValue(attribute);
}

public boolean containsAttributeKey(String attribute) {
return attributes.containsKey(attribute);
}

public String getLocationKey() {
return start1 + "_" + start2;
}
Expand Down
14 changes: 10 additions & 4 deletions src/juicebox/track/feature/Feature2DList.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,20 +325,26 @@ private boolean exportFeatureList(final PrintWriter outputFilePrintWriter, final
outputKeys.addAll(Arrays.asList("observed", "expectedBL", "expectedDonut", "expectedH",
"expectedV", "fdrBL", "fdrDonut", "fdrH", "fdrV", "numCollapsed", "centroid1", "centroid2", "radius"));
} else if (listFormat == ListFormat.LOCALIZED) {
if (featureZero.attributes.containsKey("motif_start_1")) {
if (featureZero.attributes.containsKey("motif_start_1") && featureZero.attributes.containsKey("expectedBL")) {
outputKeys.addAll(Arrays.asList("observed", "expectedBL", "expectedDonut", "expectedH",
"expectedV", "fdrBL", "fdrDonut", "fdrH", "fdrV", "numCollapsed", "centroid1", "centroid2", "radius",
"motif_start_1", "motif_end_1", "sequence_1", "orientation_1", "uniqueness_1",
"motif_start_2", "motif_end_2", "sequence_2", "orientation_2", "uniqueness_2",
"coarse_start_1", "coarse_end_1", "coarse_start_2", "coarse_end_2",
"highRes_start_1", "highRes_end_1", "highRes_start_2", "highRes_end_2",
"localX", "localY", "localObserved", "localPval", "localPeakID"));
} else {
} else if (featureZero.attributes.containsKey("motif_start_1")) {
outputKeys.addAll(Arrays.asList("motif_start_1", "motif_end_1", "sequence_1", "orientation_1", "uniqueness_1",
"motif_start_2", "motif_end_2", "sequence_2", "orientation_2", "uniqueness_2",
"highRes_start_1", "highRes_end_1", "highRes_start_2", "highRes_end_2",
"localX", "localY", "localObserved", "localPval", "localPeakID"));
} else if (featureZero.attributes.containsKey("expectedBL")){
outputKeys.addAll(Arrays.asList("observed", "expectedBL", "expectedDonut", "expectedH",
"expectedV", "fdrBL", "fdrDonut", "fdrH", "fdrV", "numCollapsed", "centroid1", "centroid2", "radius",
"coarse_start_1", "coarse_end_1", "coarse_start_2", "coarse_end_2",
"highRes_start_1", "highRes_end_1", "highRes_start_2", "highRes_end_2",
"localX", "localY", "localObserved", "localPval", "localPeakID"));
} else {
outputKeys.addAll(Arrays.asList("highRes_start_1", "highRes_end_1", "highRes_start_2", "highRes_end_2",
"localX", "localY", "localObserved", "localPval", "localPeakID"));
}
}else if (listFormat == ListFormat.ARROWHEAD) {
outputKeys.addAll(Arrays.asList("score", "uVarScore", "lVarScore", "upSign", "loSign"));
Expand Down
2 changes: 1 addition & 1 deletion src/juicebox/track/feature/Feature2DParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ void parseBEDPEAndAddToList(String path, String[] headers, String[] tokens, int
try {
attrs.put("score", "" + Float.parseFloat(tokens[7]));
} catch (Exception e) {
// ignore
//ignore
}

addToList(chr1Name, chr2Name, handler, nextLine, newList, useFeature2DWithMotif, featureType,
Expand Down

0 comments on commit 6202b43

Please sign in to comment.