Skip to content

Commit

Permalink
compute long chr names for chrom.sizes file
Browse files Browse the repository at this point in the history
  • Loading branch information
jrobinso committed Aug 12, 2024
1 parent 7663069 commit 8c599b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/broad/igv/feature/genome/Genome.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public Genome(GenomeConfig config) throws IOException {

/**
* Alternate constructor for defining a minimal genome, usually from parsing a chrom.sizes file. Used to
* create mock genomes for testing.
* create mock genomes for igvtools and testing.
*
* @param id
* @param chromosomes
Expand All @@ -241,6 +241,7 @@ public Genome(String id, List<Chromosome> chromosomes) {
chromosomeNames.add(chromosome.getName());
chromosomeMap.put(chromosome.getName(), chromosome);
}
this.longChromosomeNames = computeLongChromosomeNames();
}

private void addTracks(GenomeConfig config) {
Expand Down
24 changes: 14 additions & 10 deletions src/test/java/org/broad/igv/tools/IGVToolsCountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.broad.igv.data.WiggleParser;
import org.broad.igv.feature.LocusScore;
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.GenomeUtils;
import org.broad.igv.feature.tribble.CodecFactory;
import org.broad.igv.tdf.TDFDataSource;
import org.broad.igv.tdf.TDFDataset;
Expand Down Expand Up @@ -57,7 +58,7 @@ public class IGVToolsCountTest extends AbstractHeadlessTest {

IgvTools igvTools;

private static final String hg18id = TestUtils.DATA_DIR + "genomes/hg18.unittest.genome";
private static final String genomePath = TestUtils.DATA_DIR + "genomes/hg19.chrom.sizes";
private static final int MAX_LINES_CHECK = 200;

@Rule
Expand Down Expand Up @@ -91,9 +92,12 @@ public void testCountBEDoutWig() throws Exception {

@Test
public void testCountBEDoutWigCheckBW() throws Exception {

GenomeUtils.main(null);

String inputFile = TestUtils.DATA_DIR + "bed/test2.bed";
String fullout = TestUtils.TMP_OUTPUT_DIR + "twig.wig";
String input = "count " + inputFile + " " + fullout + " " + hg18id;
String input = "count " + inputFile + " " + fullout + " " + genomePath;
String[] args = input.split("\\s+");
igvTools.run(args);

Expand Down Expand Up @@ -126,7 +130,7 @@ public void testCountBEDstdoutWig() throws Exception {

//Write to a file
String fileOutArg = TestUtils.TMP_OUTPUT_DIR + "testfilewig.wig";
String input = "count " + inputFile + " " + fileOutArg + " " + hg18id;
String input = "count " + inputFile + " " + fileOutArg + " " + genomePath;
String[] args = input.split("\\s+");
igvTools.run(args);

Expand All @@ -135,7 +139,7 @@ public void testCountBEDstdoutWig() throws Exception {
PrintStream oldOut = System.out;
System.setOut(new PrintStream(os));

input = "count " + inputFile + " " + IgvTools.STDOUT_FILE_STR + " " + hg18id;
input = "count " + inputFile + " " + IgvTools.STDOUT_FILE_STR + " " + genomePath;
args = input.split("\\s+");
(new IgvTools()).run(args);

Expand Down Expand Up @@ -230,7 +234,7 @@ public void tstCountOptsGen(String inputFile, String outputBase, String outputEx
if (ind == 0) refOpt = opt;

String fullout = outputFile + ind + "." + outputExt;
String input = "count " + opt + " " + inputFile + " " + fullout + " " + hg18id;
String input = "count " + opt + " " + inputFile + " " + fullout + " " + genomePath;
String[] args = input.split("\\s+");
igvTools.run(args);

Expand All @@ -253,7 +257,7 @@ public void tstCountOptsGen(String inputFile, String outputBase, String outputEx
assertTrue(outFile.canRead());

ResourceLocator locator = new ResourceLocator(fullout);
WiggleDataset ds = (new WiggleParser(locator, IgvTools.loadGenome(hg18id))).parse();
WiggleDataset ds = (new WiggleParser(locator, IgvTools.loadGenome(genomePath))).parse();

//We miss a few alignments with this option sometimes,
//so it doesn't total up the same
Expand Down Expand Up @@ -358,7 +362,7 @@ private void tstCountBamList(String listArg) throws Exception {
for (int ind = 0; ind < opts.length; ind++) {
String opt = opts[ind];
String fullout = outputFile + ind + ".tdf";
String input = "count " + opt + " " + listArg + " " + fullout + " " + hg18id;
String input = "count " + opt + " " + listArg + " " + fullout + " " + genomePath;
String[] args = input.split("\\s+");
igvTools.run(args);

Expand All @@ -379,10 +383,10 @@ public void testCountDups() throws Exception {

int pos = 9718611;
String queryStr = queryChr + ":" + (pos - 100) + "-" + (pos + 100) + " ";
String cmd_nodups = "count --windowSize 1 -z 7 --query " + queryStr + inputFile + " " + outputFileND + " " + hg18id;
String cmd_nodups = "count --windowSize 1 -z 7 --query " + queryStr + inputFile + " " + outputFileND + " " + genomePath;
igvTools.run(cmd_nodups.split("\\s+"));

String cmd_withdups = "count --includeDuplicates -z 7 --windowSize 1 --query " + queryStr + inputFile + " " + outputFileWithDup + " " + hg18id;
String cmd_withdups = "count --includeDuplicates -z 7 --windowSize 1 --query " + queryStr + inputFile + " " + outputFileWithDup + " " + genomePath;
igvTools.run(cmd_withdups.split("\\s+"));

assertTrue((new File(outputFileND).exists()));
Expand Down Expand Up @@ -532,7 +536,7 @@ private void tstCountWindowFunctions(String inputFile, String chr, Iterable<Wind
wfs += wf.name() + ",";
}
wfs = wfs.substring(0, wfs.lastIndexOf(","));
String[] cmd = {"count", "--windowFunctions", wfs, inputFile, outputFile, hg18id};
String[] cmd = {"count", "--windowFunctions", wfs, inputFile, outputFile, genomePath};
igvTools.run(cmd);

TDFReader reader = new TDFReader(new ResourceLocator(outputFile));
Expand Down

0 comments on commit 8c599b8

Please sign in to comment.