Skip to content

Commit

Permalink
Replace direct use of Sequence implementation constructors with facto…
Browse files Browse the repository at this point in the history
…ry method. Rename "fasta" package to "sequence"
  • Loading branch information
jrobinso committed Oct 2, 2023
1 parent df59d5a commit fdde6d1
Show file tree
Hide file tree
Showing 29 changed files with 111 additions and 63 deletions.
2 changes: 1 addition & 1 deletion scripts/test_suite.args
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
--add-exports org.igv/org.broad.igv.feature.dranger=junit
--add-exports org.igv/org.broad.igv.feature.dsi=junit
--add-exports org.igv/org.broad.igv.feature.genome=junit
--add-exports org.igv/org.broad.igv.feature.genome.fasta=junit
--add-exports org.igv/org.broad.igv.feature.genome.sequence=junit
--add-exports org.igv/org.broad.igv.feature.tribble=junit
--add-exports org.igv/org.broad.igv.feature.tribble.reader=junit
--add-exports org.igv/org.broad.igv.oauth=junit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

package org.broad.igv.feature.genome;

import org.broad.igv.feature.genome.sequence.Sequence;

/**
* Created with IntelliJ IDEA.
* User: jrobinso
Expand Down
4 changes: 3 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 @@ -38,11 +38,13 @@
import org.broad.igv.Globals;
import org.broad.igv.feature.Chromosome;
import org.broad.igv.feature.Cytoband;
import org.broad.igv.feature.genome.sequence.InMemorySequence;
import org.broad.igv.feature.genome.sequence.Sequence;
import org.broad.igv.feature.genome.sequence.SequenceWrapper;
import org.broad.igv.logging.LogManager;
import org.broad.igv.logging.Logger;
import org.broad.igv.track.FeatureTrack;
import org.broad.igv.track.Track;
import org.broad.igv.ui.panel.ReferenceFrame;
import org.broad.igv.util.ResourceLocator;
import org.broad.igv.util.liftover.Liftover;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import org.broad.igv.logging.*;
import org.broad.igv.Globals;
import org.broad.igv.feature.genome.fasta.FastaUtils;
import org.broad.igv.feature.genome.sequence.FastaUtils;
import org.broad.igv.feature.genome.load.GenomeDescriptor;
import org.broad.igv.util.FileUtils;
import org.broad.igv.util.HttpUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package org.broad.igv.feature.genome.load;

import htsjdk.tribble.Feature;
import org.broad.igv.feature.genome.sequence.SequenceFactory;
import org.broad.igv.logging.*;
import org.broad.igv.feature.*;
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.Sequence;
import org.broad.igv.feature.genome.fasta.FastaBlockCompressedSequence;
import org.broad.igv.feature.genome.fasta.FastaIndexedSequence;
import org.broad.igv.feature.genome.sequence.Sequence;
import org.broad.igv.feature.genome.sequence.FastaBlockCompressedSequence;
import org.broad.igv.feature.genome.sequence.FastaIndexedSequence;
import org.broad.igv.feature.gff.GFFFeatureSource;
import org.broad.igv.track.FeatureCollectionSource;
import org.broad.igv.track.FeatureTrack;
Expand Down Expand Up @@ -97,11 +98,7 @@ public Genome loadGenome() throws IOException {
if (sequencePath == null) {
sequence = null;
} else {
if (sequencePath.endsWith(".gz")) {
sequence = new FastaBlockCompressedSequence(sequencePath);
} else {
sequence = new FastaIndexedSequence(sequencePath);
}
sequence = SequenceFactory.getSequence(sequencePath);
chromosOrdered = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.broad.igv.feature.genome.load;

import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.Sequence;
import org.broad.igv.feature.genome.SequenceWrapper;
import org.broad.igv.feature.genome.fasta.FastaBlockCompressedSequence;
import org.broad.igv.feature.genome.fasta.FastaIndexedSequence;
import org.broad.igv.feature.genome.fasta.FastaUtils;
import org.broad.igv.feature.genome.sequence.*;
import org.broad.igv.util.FileUtils;
import org.broad.igv.util.HttpUtils;
import org.broad.igv.util.Utilities;
Expand Down Expand Up @@ -56,9 +52,7 @@ public Genome loadGenome() throws IOException {
name = file.getName();
}

FastaIndexedSequence sequence = fastaPath.endsWith(".gz") ?
new FastaBlockCompressedSequence(fastaPath) :
new FastaIndexedSequence(fastaPath);
Sequence sequence = SequenceFactory.getSequence(fastaPath, fastaIndexPath);
return new Genome(id, name, sequence, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import org.broad.igv.Globals;
import org.broad.igv.feature.FeatureDB;
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.InMemorySequence;
import org.broad.igv.feature.genome.Sequence;
import org.broad.igv.feature.genome.sequence.InMemorySequence;
import org.broad.igv.feature.genome.sequence.Sequence;
import org.broad.igv.track.FeatureTrack;
import org.broad.igv.ui.IGV;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
import htsjdk.tribble.CloseableTribbleIterator;
import htsjdk.tribble.Feature;
import htsjdk.tribble.FeatureReader;
import org.broad.igv.feature.genome.sequence.Sequence;
import org.broad.igv.feature.genome.sequence.SequenceFactory;
import org.broad.igv.logging.*;
import org.broad.igv.Globals;
import org.broad.igv.feature.CytoBandFileParser;
import org.broad.igv.feature.FeatureDB;
import org.broad.igv.feature.NamedFeature;
import org.broad.igv.feature.genome.Genome;
import org.broad.igv.feature.genome.fasta.FastaBlockCompressedSequence;
import org.broad.igv.feature.genome.fasta.FastaIndexedSequence;
import org.broad.igv.feature.genome.sequence.FastaBlockCompressedSequence;
import org.broad.igv.feature.genome.sequence.FastaIndexedSequence;
import org.broad.igv.track.TribbleFeatureSource;
import org.broad.igv.ui.color.ColorUtilities;
import org.broad.igv.util.FileUtils;
Expand All @@ -24,8 +26,6 @@

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;

public class JsonGenomeLoader extends GenomeLoader {
Expand Down Expand Up @@ -71,9 +71,7 @@ public Genome loadGenome() throws IOException {
gziIndexPath = FileUtils.getAbsolutePath(gziIndexPath, genomePath);
}

FastaIndexedSequence sequence = fastaPath.endsWith(".gz") ?
new FastaBlockCompressedSequence(fastaPath, gziIndexPath, indexPath) :
new FastaIndexedSequence(fastaPath, indexPath);
Sequence sequence = SequenceFactory.getSequence(fastaPath, indexPath, gziIndexPath);

JsonElement orderedElement = json.get("ordered");
boolean ordered = orderedElement != null && orderedElement.getAsBoolean();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.broad.igv.feature.genome.fasta;
package org.broad.igv.feature.genome.sequence;

import htsjdk.samtools.seekablestream.SeekableBufferedStream;
import htsjdk.samtools.seekablestream.SeekableStream;
Expand All @@ -20,12 +20,12 @@ public class FastaBlockCompressedSequence extends FastaIndexedSequence {
Mapping[] gziMappings;
Mapping zeroMapping = new Mapping(0, 0);

public FastaBlockCompressedSequence(String path) throws IOException {
FastaBlockCompressedSequence(String path) throws IOException {

this(path, null, null);
}

public FastaBlockCompressedSequence(String path, String gziIndexPath, String indexPath) throws IOException {
FastaBlockCompressedSequence(String path, String gziIndexPath, String indexPath) throws IOException {

super(path, indexPath);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* THE SOFTWARE.
*/

package org.broad.igv.feature.genome.fasta;
package org.broad.igv.feature.genome.sequence;

import org.broad.igv.logging.*;
import org.broad.igv.Globals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
* THE SOFTWARE.
*/

package org.broad.igv.feature.genome.fasta;
package org.broad.igv.feature.genome.sequence;

import htsjdk.samtools.seekablestream.SeekableStream;
import org.broad.igv.logging.*;
import org.broad.igv.feature.genome.Sequence;
import org.broad.igv.util.FileUtils;
import org.broad.igv.util.stream.IGVSeekableStreamFactory;

import java.io.ByteArrayOutputStream;
Expand All @@ -51,11 +49,12 @@ public class FastaIndexedSequence implements Sequence {

private final ArrayList<String> chromoNamesList;

public FastaIndexedSequence(String path) throws IOException {
FastaIndexedSequence(String path) throws IOException {
this(path, null);
}

public FastaIndexedSequence(String path, String indexPath) throws IOException {

FastaIndexedSequence(String path, String indexPath) throws IOException {

this.path = path;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
* THE SOFTWARE.
*/

package org.broad.igv.feature.genome.fasta;
package org.broad.igv.feature.genome.sequence;

import org.broad.igv.util.ParsingUtils;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* THE SOFTWARE.
*/

package org.broad.igv.feature.genome.fasta;
package org.broad.igv.feature.genome.sequence;

import org.broad.igv.logging.*;
import org.broad.igv.Globals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* THE SOFTWARE.
*/

package org.broad.igv.feature.genome;
package org.broad.igv.feature.genome.sequence;

import java.util.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* THE SOFTWARE.
*/

package org.broad.igv.feature.genome;
package org.broad.igv.feature.genome.sequence;

import org.broad.igv.ui.panel.ReferenceFrame;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.broad.igv.feature.genome.sequence;

import org.broad.igv.logging.LogManager;
import org.broad.igv.logging.Logger;
import org.broad.igv.util.FileUtils;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;


public class SequenceFactory {

private static Logger log = LogManager.getLogger(SequenceFactory.class);

public static Sequence getSequence(String path) throws IOException {
return getSequence(path, null, null);
}


public static Sequence getSequence(String path, String indexPath) throws IOException {
return getSequence(path, indexPath, null);
}


/**
* Return the Sequence object for the associated paths.
* <p>
* TODO -- this logic relieds on file extensions, won't neccessarily work for signed or DRS urls
*
* @param path
* @param indexPath
* @param gziIndexPath
* @return
* @throws IOException
*/
public static Sequence getSequence(String path, String indexPath, String gziIndexPath) throws IOException {

String p;
if (FileUtils.isRemote(path)) {
try {
p = ((new URL(path)).getPath());
} catch (MalformedURLException e) {
log.error("Error parsing url: " + path);
p = path;
}
} else {
p = path;
}

if (gziIndexPath != null || p.endsWith(".gz")) {
return new FastaBlockCompressedSequence(path, gziIndexPath, indexPath);
} else if (p.endsWith(".2bit")) {
return new TwoBitSequence(path);
} else {
return new FastaIndexedSequence(path, indexPath);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.broad.igv.feature.genome;
package org.broad.igv.feature.genome.sequence;

import org.broad.igv.logging.*;
import org.broad.igv.ui.panel.ReferenceFrame;
import org.broad.igv.util.ObjectCache;

import java.util.Hashtable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.broad.igv.feature.genome;
package org.broad.igv.feature.genome.sequence;

/**
* Reader for UCSC ".2bit" sequence files. Reference: https://genome.ucsc.edu/FAQ/FAQformat.html#format7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.broad.igv.feature.genome;
package org.broad.igv.feature.genome.sequence;

import java.io.IOException;
import java.util.List;
Expand All @@ -7,7 +7,7 @@ public class TwoBitSequence implements Sequence{

private TwoBitReader reader;

public TwoBitSequence(String path) throws IOException {
protected TwoBitSequence(String path) throws IOException {
this.reader = new TwoBitReader(path);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/broad/igv/tools/IgvTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import org.broad.igv.feature.GFFParser;
import org.broad.igv.feature.Mutation;
import org.broad.igv.feature.genome.*;
import org.broad.igv.feature.genome.fasta.FastaUtils;
import org.broad.igv.feature.genome.sequence.FastaUtils;
import org.broad.igv.feature.genome.load.GenomeDescriptor;
import org.broad.igv.feature.tribble.CodecFactory;
import org.broad.igv.feature.tribble.GFFCodec;
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/org/broad/igv/util/TutorialUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import htsjdk.samtools.util.CloseableIterator;
import org.broad.igv.Globals;
import org.broad.igv.feature.genome.ChromosomeNameComparator;
import org.broad.igv.feature.genome.fasta.FastaIndexedSequence;
import org.broad.igv.feature.genome.sequence.FastaIndexedSequence;
import org.broad.igv.feature.genome.sequence.Sequence;
import org.broad.igv.feature.genome.sequence.SequenceFactory;
import org.broad.igv.sam.SAMAlignment;
import org.broad.igv.sam.reader.AlignmentReader;
import org.broad.igv.sam.reader.AlignmentReaderFactory;
Expand All @@ -56,7 +58,7 @@ public static void main(String[] args) throws IOException {

static void extractFasta(String inputFasta, String outputFasta, String regionsFile) throws IOException {

FastaIndexedSequence inFasta = new FastaIndexedSequence(inputFasta);
Sequence inFasta = SequenceFactory.getSequence(inputFasta);

List<Region> regions = parseRegions(new File(regionsFile));

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/broad/igv/feature/genome/GenomeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
package org.broad.igv.feature.genome;

import org.broad.igv.AbstractHeadlessTest;
import org.broad.igv.feature.genome.fasta.FastaIndex;
import org.broad.igv.feature.genome.sequence.FastaIndex;
import org.broad.igv.feature.genome.sequence.Sequence;
import org.broad.igv.util.TestUtils;
import org.junit.Assume;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.broad.igv.feature.genome;

import org.broad.igv.feature.genome.sequence.TwoBitReader;
import org.broad.igv.util.TestUtils;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.broad.igv.feature.genome.fasta;
package org.broad.igv.feature.genome.sequence;

import org.broad.igv.feature.genome.Sequence;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand Down
Loading

0 comments on commit fdde6d1

Please sign in to comment.