Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct normalization of chromosome at resolution #11

Merged
merged 3 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/artifacts/HiCTools_jar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
2 changes: 1 addition & 1 deletion src/hic/HiCGlobals.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @since 11/25/14
*/
public class HiCGlobals {
public static final String versionNum = "3.26.00";
public static final String versionNum = "3.27.00";
public static final int writingVersion = 9;
public static final int bufferSize = 2097152;
public static int MAX_PEARSON_ZOOM = 50000;
Expand Down
2 changes: 2 additions & 0 deletions src/hic/tools/clt/CLTFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public static JuiceboxCLT getCLTCommand(String cmd) {
return new Sum();
} else if (cmd.startsWith("addnorm")) {
return new AddNorm();
} else if (cmd.startsWith("test") && cmd.contains("norm")) {
return new TestNorm();
} else if (cmd.equals("bigwig")) {
return new BigWig();
} else if (cmd.equals("bintopairs")) {
Expand Down
120 changes: 120 additions & 0 deletions src/hic/tools/clt/old/TestNorm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020-2022 Rice University, Baylor College of Medicine, Aiden Lab
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hic.tools.clt.old;

import hic.HiCGlobals;
import hic.tools.clt.CommandLineParser;
import hic.tools.clt.JuiceboxCLT;
import hic.tools.utils.bigarray.BigContactList;
import hic.tools.utils.norm.IntraNorms;
import hic.tools.utils.norm.NormalizationCalculations;
import javastraw.reader.Dataset;
import javastraw.reader.DatasetReaderV2;
import javastraw.reader.basics.Chromosome;
import javastraw.reader.datastructures.ListOfFloatArrays;
import javastraw.reader.type.HiCZoom;

import java.io.*;
import java.nio.charset.StandardCharsets;


public class TestNorm extends JuiceboxCLT {

private final String norm = "SCALE";
private int resolution = 1000;
private String file, name, output;

public TestNorm() {
super(getBasicUsage());
}

public static String getBasicUsage() {
return "testNorm [-k NORM] [--threads number] [--mthreads number] <input.hic> <chromosome> <resolution> <output>";
}

@Override
public void readArguments(String[] args, CommandLineParser parser) {
if (parser.getHelpOption() || args.length != 5) {
printUsageAndExit();
}

HiCGlobals.normThreads = updateNumberOfCPUThreads(parser, 10);

file = args[1];
name = args[2];
resolution = Integer.parseInt(args[3]);
output = args[4];
}

@Override
public void run() {
HiCGlobals.allowDynamicBlockIndex = false;

try {
DatasetReaderV2 reader = new DatasetReaderV2(file, false, false);
Dataset ds = reader.read();
HiCGlobals.verifySupportedHiCFileVersion(reader.getVersion());

Chromosome chrom = ds.getChromosomeHandler().getChromosomeFromName(name);
HiCZoom zoom = new HiCZoom(resolution);
String stem = "NORM_" + chrom.getIndex() + "_" + zoom.getBinSize();

BigContactList ba = IntraNorms.getBigArrayFromAndClearCache(ds, chrom, zoom, 0);
System.out.println("Contacts loaded to RAM");
if (ba != null) {
NormalizationCalculations nc = new NormalizationCalculations(ba, zoom.getBinSize());
ListOfFloatArrays vc = nc.computeVC();
long s0 = System.nanoTime();
ListOfFloatArrays scale = nc.computeSCALE(vc, stem);
long s1 = System.nanoTime();
System.out.println("Overall time taken " + ((s1 - s0) * 1e-9) + " seconds");
export(scale, output);
}

} catch (Exception e) {
e.printStackTrace();
}
}

private void export(ListOfFloatArrays scale, String output) {
PrintWriter out = null;
try {
out = new PrintWriter(new OutputStreamWriter(
new BufferedOutputStream(new FileOutputStream(output)), StandardCharsets.UTF_8));
for (float[] row : scale.getValues()) {
for (float val : row) {
out.println(val);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (out != null) {
out.flush();
out.close();
}
}
}
}
4 changes: 2 additions & 2 deletions src/hic/tools/utils/norm/NormVectorInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2011-2022 Broad Institute, Aiden Lab, Rice University, Baylor College of Medicine
* Copyright (c) 2020-2022 Rice University, Baylor College of Medicine, Aiden Lab
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -32,7 +32,7 @@
import java.util.List;
import java.util.Map;

class NormVectorInfo {
public class NormVectorInfo {

private final BigListOfByteWriters normVectorBuffers;
private final List<NormalizationVectorIndexEntry> normVectorIndices;
Expand Down
2 changes: 1 addition & 1 deletion src/hic/tools/utils/norm/NormalizationCalculations.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void fixBySumFactor(ListOfFloatArrays norm) {
*
* @return Normalization vector
*/
ListOfFloatArrays computeVC() {
public ListOfFloatArrays computeVC() {
return ba.getRowSums();
}

Expand Down