Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
takutosato committed Aug 9, 2024
1 parent 6390929 commit 5454cdb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/main/java/picard/cmdline/CommandLineProgram.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import com.intel.gkl.compression.IntelDeflaterFactory;
import com.intel.gkl.compression.IntelInflaterFactory;
import htsjdk.io.IOPath;
import htsjdk.samtools.Defaults;
import htsjdk.samtools.SAMFileHeader;
import htsjdk.samtools.SAMFileWriterFactory;
Expand Down Expand Up @@ -341,7 +342,7 @@ protected boolean parseArgs(final String[] argv) {
// object created by this code path won't be valid - but we still have to set it here in case
// the tool tries to access REFERENCE_SEQUENCE directly (such tools will subsequently fail given
// a non-local file anyway, but this prevents them from immediately throwing an NPE).
final PicardHtsPath refHtsPath = referenceSequence.getHtsPath();
final IOPath refHtsPath = referenceSequence.getHtsPath();
REFERENCE_SEQUENCE = ReferenceArgumentCollection.getFileSafe(refHtsPath, Log.getInstance(this.getClass()));

// The TMP_DIR setting section below was moved from instanceMain() to here due to timing issues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.File;
import java.nio.file.Path;

import htsjdk.io.IOPath;
import htsjdk.samtools.util.Log;
import picard.nio.PicardBucketUtils;
import picard.nio.PicardHtsPath;
Expand Down Expand Up @@ -61,7 +62,7 @@ default Path getReferencePath(){
*
* @return The reference provided by the user, if any, or the default, if any, as a PicardHtsPath. May be null.
*/
default PicardHtsPath getHtsPath(){
default IOPath getHtsPath(){
return getReferenceFile() == null ? null : new PicardHtsPath(getReferenceFile());
}

Expand All @@ -74,7 +75,7 @@ default PicardHtsPath getHtsPath(){
* the value returned by calls to getReferenceFile to not get an NPE, and to fail gracefully downstream
* with an error message that includes the reference file specifier.
*/
static File getFileSafe(final PicardHtsPath picardPath, final Log log) {
static File getFileSafe(final IOPath picardPath, final Log log) {
if (picardPath == null) {
return null;
} else if (picardPath.getScheme().equals(PicardBucketUtils.FILE_SCHEME)) {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/picard/nio/PicardBucketUtils.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package picard.nio;

import com.google.cloud.storage.contrib.nio.CloudStorageFileSystem;
import com.google.cloud.storage.contrib.nio.CloudStoragePath;
import htsjdk.io.HtsPath;
import htsjdk.io.IOPath;
import htsjdk.samtools.util.FileExtensions;
import htsjdk.utils.ValidationUtils;
import picard.PicardException;

import java.util.UUID;


/**
* Derived from BucketUtils.java in GATK
*/
Expand Down Expand Up @@ -143,6 +139,9 @@ public static boolean isLocalPath(final IOPath path){
}

/**
* As of August 2024, we only support Google Cloud.
* Will add other filesystems (e.g. Azure, AWS) when ready.
*
* @return whether the cloud filesystem is currently supported by Picard.
*/
public static boolean isSupportedCloudFilesystem(final IOPath path){
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/picard/cmdline/CommandLineProgramTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package picard.cmdline;

import htsjdk.io.IOPath;
import org.apache.commons.io.FileUtils;
import org.testng.annotations.AfterClass;
import picard.PicardException;
Expand All @@ -24,13 +25,13 @@ public abstract class CommandLineProgramTest {
public static final File CHR_M_DICT = new File(REFERENCE_TEST_DIR,"chrM.reference.dict");

// These are the hg19 references with chromosome names "1" (rather than "chr1")
public static final PicardHtsPath HG19_CHR2021_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/references/human_g1k_v37.20.21.fasta");
public static final PicardHtsPath HG19_CHR2021 = new PicardHtsPath("testdata/picard/reference/human_g1k_v37.20.21.fasta.gz");
public static final IOPath HG19_CHR2021_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/references/human_g1k_v37.20.21.fasta");
public static final IOPath HG19_CHR2021 = new PicardHtsPath("testdata/picard/reference/human_g1k_v37.20.21.fasta.gz");

public static final PicardHtsPath NA12878_MINI_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/bam/CEUTrio.HiSeq.WGS.b37.NA12878.20.21_n100.bam");
public static final PicardHtsPath NA12878_MINI_CRAM_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/bam/CEUTrio.HiSeq.WGS.b37.NA12878.20.21_n100.cram");
public static final PicardHtsPath NA12878_MEDIUM_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/bam/CEUTrio.HiSeq.WGS.b37.NA12878.20.21_n10000.bam");
public static final PicardHtsPath NA12878_MEDIUM_CRAM_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/bam/CEUTrio.HiSeq.WGS.b37.NA12878.20.21_n10000.cram");
public static final IOPath NA12878_MINI_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/bam/CEUTrio.HiSeq.WGS.b37.NA12878.20.21_n100.bam");
public static final IOPath NA12878_MINI_CRAM_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/bam/CEUTrio.HiSeq.WGS.b37.NA12878.20.21_n100.cram");
public static final IOPath NA12878_MEDIUM_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/bam/CEUTrio.HiSeq.WGS.b37.NA12878.20.21_n10000.bam");
public static final IOPath NA12878_MEDIUM_CRAM_GCLOUD = PicardHtsPath.resolve(GCloudTestUtils.getTestInputPath(), "picard/bam/CEUTrio.HiSeq.WGS.b37.NA12878.20.21_n10000.cram");

// A per-test-class directory that will be deleted after the tests are complete.
private File tempOutputDir;
Expand Down
11 changes: 3 additions & 8 deletions src/test/java/picard/nio/PicardBucketUtilsTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package picard.nio;

import htsjdk.io.HtsPath;
import htsjdk.io.IOPath;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import picard.util.GCloudTestUtils;

import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;

public class PicardBucketUtilsTest {

@DataProvider(name="testGetTempFilePathDataProvider")
Expand Down Expand Up @@ -38,9 +33,9 @@ public void testGetTempFilePath(final IOPath directory, final String prefix, fin
@DataProvider
public Object[][] getVariousPathsForPrefetching(){
return new Object[][]{
{new HtsPath("file:///local/file"), false},
{new HtsPath("gs://abucket/bucket"), true},
{new HtsPath("gs://abucket_with_underscores"), true},
{new PicardHtsPath("file:///local/file"), false},
{new PicardHtsPath("gs://abucket/bucket"), true},
{new PicardHtsPath("gs://abucket_with_underscores"), true},
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/picard/sam/RevertSamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public Object[][] getCloudTestData() {
// Output by read group using the output map, write output bams in the cloud
{NA12878_MEDIUM_GCLOUD, null, OUTPUT_BY_READ_GROUP, DEFAULT_CLOUD_TEST_OUTPUT_DIR, null },
// Output by read group using the local output map, write output bams in the cloud
{NA12878_MEDIUM_GCLOUD, null, OUTPUT_BY_READ_GROUP, new PicardHtsPath(REVERT_SAM_LOCAL_TEST_DATA_DIR), null }, // tsato: relative local dir...just wrap it in PicardHtsPath to see what happens
{NA12878_MEDIUM_GCLOUD, null, OUTPUT_BY_READ_GROUP, new PicardHtsPath(REVERT_SAM_LOCAL_TEST_DATA_DIR), null },
// Cram input, output a CRAM for each read group
{NA12878_MEDIUM_CRAM_GCLOUD, null, OUTPUT_BY_READ_GROUP, DEFAULT_CLOUD_TEST_OUTPUT_DIR, HG19_CHR2021 },
// Cram input in the cloud, single cloud cram output
Expand Down

0 comments on commit 5454cdb

Please sign in to comment.