diff --git a/biojava-aa-prop/src/main/java/org/biojava/nbio/aaproperties/PeptidePropertiesImpl.java b/biojava-aa-prop/src/main/java/org/biojava/nbio/aaproperties/PeptidePropertiesImpl.java index c75554f9e6..239d8d2329 100644 --- a/biojava-aa-prop/src/main/java/org/biojava/nbio/aaproperties/PeptidePropertiesImpl.java +++ b/biojava-aa-prop/src/main/java/org/biojava/nbio/aaproperties/PeptidePropertiesImpl.java @@ -50,6 +50,10 @@ public class PeptidePropertiesImpl implements IPeptideProperties{ private final static Logger logger = LoggerFactory.getLogger(PeptidePropertiesImpl.class); + private final static String ALANINE = "A"; + private final static String VALAINE = "V"; + private final static String ISOLEUCINE = "I"; + private final static String LEUCINE = "L"; /** * @return the molecular weight of water @@ -247,13 +251,23 @@ public double getApliphaticIndex(ProteinSequence sequence) { // Ala => A, Val => V, Ile => I, Leu => L AminoAcidCompoundSet aaSet = new AminoAcidCompoundSet(); Map aa2Composition = getAAComposition(sequence); - final double a = 2.9; - final double b = 3.9; - double xAla = aa2Composition.get(aaSet.getCompoundForString("A")); - double xVal = aa2Composition.get(aaSet.getCompoundForString("V")); - double xIle = aa2Composition.get(aaSet.getCompoundForString("I")); - double xLeu = aa2Composition.get(aaSet.getCompoundForString("L")); - return (xAla + (a * xVal) + (b * (xIle + xLeu))) * 100; + + final double valineVolume = 2.9; + final double leucineVolume = 3.9; + + double xAlanine = aa2Composition.get(aaSet.getCompoundForString(ALANINE)); + double xValine = aa2Composition.get(aaSet.getCompoundForString(VALAINE)); + double xIsoleucine = aa2Composition.get(aaSet.getCompoundForString(ISOLEUCINE)); + double xLeucine = aa2Composition.get(aaSet.getCompoundForString(LEUCINE)); + + double valContribution = valineVolume * xValine; + double ileLeuContribution = leucineVolume * (xIsoleucine + xLeucine); + /* + Aliphatic index = X(Ala) + (valineVolume * X(Val)) + (leucineVolume * ( X(Ile) + X(Leu))) + Here X(Ala),X(Val),X(Ile),X(Leu) are xAlanine, xValine, xIsoleucine, xLeucine for readability, + and are in fraction form which when multiplied * 100 is retuning the percentage. + */ + return (xAlanine + valContribution + ileLeuContribution) * 100; } @Override @@ -275,6 +289,7 @@ public double getAvgHydropathy(ProteinSequence sequence) { } return total / validLength; + } @Override diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/CDSSequence.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/CDSSequence.java index f897622f3c..bbb445beee 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/CDSSequence.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/CDSSequence.java @@ -35,7 +35,7 @@ * to a gff3 file. {@link http://www.sequenceontology.org/gff3.shtml} * @author Scooter Willis */ -public class CDSSequence extends DNASequence { +public class CDSSequence extends DNAExtractSequence { //private static final Logger log = Logger.getLogger(CDSSequence.class.getName()); Integer phase = 0; // 0, 1, 2 @@ -65,11 +65,6 @@ public CDSSequence(TranscriptSequence parentSequence, int bioBegin, int bioEnd, } - @Override - public int getLength() { - return Math.abs(this.getBioEnd() - this.getBioBegin()) + 1; - } - /** * * @return get the phase diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/DNAExtractSequence.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/DNAExtractSequence.java new file mode 100644 index 0000000000..5b63184542 --- /dev/null +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/DNAExtractSequence.java @@ -0,0 +1,8 @@ +package org.biojava.nbio.core.sequence; + +public class DNAExtractSequence extends DNASequence{ + @Override + public int getLength() { + return Math.abs(this.getBioEnd() - this.getBioBegin()) + 1; + } +} diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/DNASequence.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/DNASequence.java index 215e3c8a26..5843309056 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/DNASequence.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/DNASequence.java @@ -166,5 +166,16 @@ public DNAType getDNAType() { public void setDNAType(DNAType dnaType) { this.dnaType = dnaType; } + + /** Converts the DNA sequence to protein sequence. + * + * @param dnaSequence the DNA sequence + * + * @return the protein sequence + */ + public ProteinSequence convertDNAtoProteinSequence(DNASequence dnaSequence) throws CompoundNotFoundException { + RNASequence mRNA = dnaSequence.getRNASequence(); + return mRNA.getProteinSequence(); + } } diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/ExonSequence.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/ExonSequence.java index fde268b8db..731f563cfc 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/ExonSequence.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/ExonSequence.java @@ -29,7 +29,7 @@ * A gene contains a collection of Exon sequences * @author Scooter Willis */ -public class ExonSequence extends DNASequence { +public class ExonSequence extends DNAExtractSequence { /** @@ -56,10 +56,6 @@ public ExonSequence(GeneSequence parentGeneSequence, int bioBegin, int bioEnd) { } - @Override - public int getLength() { - return Math.abs(this.getBioEnd() - this.getBioBegin()) + 1; - } } diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/GeneSequence.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/GeneSequence.java index 34f1ec3986..cc6008cd58 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/GeneSequence.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/GeneSequence.java @@ -37,7 +37,7 @@ * * @author Scooter Willis */ -public class GeneSequence extends DNASequence { +public class GeneSequence extends DNAExtractSequence { private final static Logger logger = LoggerFactory.getLogger(GeneSequence.class); @@ -102,10 +102,6 @@ public ChromosomeSequence getParentChromosomeSequence() { return chromosomeSequence; } - @Override - public int getLength() { - return Math.abs(this.getBioEnd() - this.getBioBegin()) + 1; - } /** * Once everything has been added to the gene sequence where you might have added exon sequences only then you diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/IntronSequence.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/IntronSequence.java index 292c65f4f9..5da40789c7 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/IntronSequence.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/IntronSequence.java @@ -30,7 +30,7 @@ * * @author Scooter Willis */ -public class IntronSequence extends DNASequence{ +public class IntronSequence extends DNAExtractSequence{ /** @@ -47,9 +47,5 @@ public IntronSequence(GeneSequence parentGeneSequence, int begin, int end){ } - @Override - public int getLength() { - return Math.abs(this.getBioEnd() - this.getBioBegin()) + 1; - } } diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/StartCodonSequence.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/StartCodonSequence.java index eb3d37674a..32a2e09658 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/StartCodonSequence.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/StartCodonSequence.java @@ -28,7 +28,7 @@ * Used to map the start codon feature on a gene * @author Scooter Willis */ -public class StartCodonSequence extends DNASequence { +public class StartCodonSequence extends DNAExtractSequence { public DNASequence parentGeneSequence = null; @@ -38,9 +38,5 @@ public StartCodonSequence(TranscriptSequence parentGeneSequence, int begin, int setBioEnd(end); } - @Override - public int getLength() { - return Math.abs(this.getBioEnd() - this.getBioBegin()) + 1; - } } diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/StopCodonSequence.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/StopCodonSequence.java index 636d8548e0..362e2f392e 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/StopCodonSequence.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/StopCodonSequence.java @@ -28,7 +28,7 @@ * Used to map the stop codon sequence on a gene * @author Scooter Willis */ -public class StopCodonSequence extends DNASequence { +public class StopCodonSequence extends DNAExtractSequence { public DNASequence parentGeneSequence = null; @@ -40,8 +40,4 @@ public StopCodonSequence(TranscriptSequence parentGeneSequence, int begin, int e } - @Override - public int getLength() { - return Math.abs(this.getBioEnd() - this.getBioBegin()) + 1; - } } diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/TranscriptSequence.java b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/TranscriptSequence.java index 83e50474bd..f0fa6b0e71 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/sequence/TranscriptSequence.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/sequence/TranscriptSequence.java @@ -37,7 +37,7 @@ * ChromosomeSequence then getting a GeneSequence and then a TranscriptSequence * @author Scooter Willis */ -public class TranscriptSequence extends DNASequence { +public class TranscriptSequence extends DNAExtractSequence { private final static Logger logger = LoggerFactory.getLogger(TranscriptSequence.class); @@ -78,10 +78,6 @@ public TranscriptSequence(GeneSequence parentDNASequence, AccessionID accessionI setAccession(accessionID); } - @Override - public int getLength() { - return Math.abs(this.getBioEnd() - this.getBioBegin()) + 1; - } /** * @return the strand diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java b/biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java index 8c3a691e0f..9413db76ba 100644 --- a/biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java +++ b/biojava-core/src/main/java/org/biojava/nbio/core/util/FileDownloadUtils.java @@ -57,68 +57,6 @@ public enum Hash{ MD5, SHA1, SHA256, UNKNOWN } - /** - * Copy the content of file src to dst TODO since java 1.7 this is provided - * in java.nio.file.Files - * - * @param src - * @param dst - * @throws IOException - */ - @SuppressWarnings("resource") - public static void copy(File src, File dst) throws IOException { - - // Took following recipe from - // http://stackoverflow.com/questions/106770/standard-concise-way-to-copy-a-file-in-java - // The nio package seems to be the most efficient way to copy a file - FileChannel source = null; - FileChannel destination = null; - - try { - // we need the supress warnings here (the warning that the stream is not closed is harmless) - // see http://stackoverflow.com/questions/12970407/does-filechannel-close-close-the-underlying-stream - source = new FileInputStream(src).getChannel(); - destination = new FileOutputStream(dst).getChannel(); - destination.transferFrom(source, 0, source.size()); - } finally { - if (source != null) { - source.close(); - } - if (destination != null) { - destination.close(); - } - } - } - - /** - * Gets the file extension of a file, excluding '.'. - * If the file name has no extension the file name is returned. - * @param f a File - * @return The extension - */ - public static String getFileExtension(File f) { - String fileName = f.getName(); - String ext = ""; - int mid = fileName.lastIndexOf("."); - ext = fileName.substring(mid + 1, fileName.length()); - return ext; - } - - /** - * Gets the file name up to and excluding the first - * '.' character. If there is no extension, the full filename - * is returned. - * @param f A file - * @return A possibly empty but non-null String. - */ - public static String getFilePrefix(File f) { - String fileName = f.getName(); - int mid = fileName.indexOf("."); - if (mid < 0) { - return fileName; - } - return fileName.substring(0, mid); - } /** * Download the content provided at URL url and store the result to a local @@ -134,7 +72,7 @@ public static void downloadFile(URL url, File destination) throws IOException { int maxTries = 10; int timeout = 60000; //60 sec - File tempFile = Files.createTempFile(getFilePrefix(destination), "." + getFileExtension(destination)).toFile(); + File tempFile = Files.createTempFile(FileOperationUtils.getFilePrefix(destination), "." + FileOperationUtils.getFileExtension(destination)).toFile(); // Took following recipe from stackoverflow: // http://stackoverflow.com/questions/921262/how-to-download-and-save-a-file-from-internet-using-java @@ -165,7 +103,7 @@ public static void downloadFile(URL url, File destination) throws IOException { } logger.debug("Copying temp file [{}] to final location [{}]", tempFile, destination); - copy(tempFile, destination); + FileOperationUtils.copy(tempFile, destination); // delete the tmp file tempFile.delete(); @@ -187,7 +125,7 @@ public static void downloadFile(URL url, File destination) throws IOException { public static void createValidationFiles(URL url, File localDestination, URL hashURL, Hash hash){ try { URLConnection resourceConnection = url.openConnection(); - createValidationFiles(resourceConnection, localDestination, hashURL, FileDownloadUtils.Hash.UNKNOWN); + createValidationFiles(resourceConnection, localDestination, hashURL, Hash.UNKNOWN); } catch (IOException e) { logger.warn("could not open connection to resource file due to exception: {}", e.getMessage()); } @@ -293,49 +231,6 @@ public boolean accept(File dir, String name) { return true; } - /** - * Converts path to Unix convention and adds a terminating slash if it was - * omitted. - * - * @param path original platform dependent path - * @return path in Unix convention - * @author Peter Rose - * @since 3.2 - */ - public static String toUnixPath(String path) { - String uPath = path; - if (uPath.contains("\\")) { - uPath = uPath.replaceAll("\\\\", "/"); - } - // this should be removed, it's need since "\" is added AtomCache code - if (uPath.endsWith("//")) { - uPath = uPath.substring(0, uPath.length() - 1); - } - if (!uPath.endsWith("/")) { - uPath = uPath + "/"; - } - return uPath; - } - - /** - * Expands ~ in paths to the user's home directory. - * - *

- * This does not work for some special cases for paths: Other users' homes - * (~user/...), and Tilde expansion within the path (/.../~/...). In these cases - * the original argument is returned. - * - * @param file A filepath starting with a tilde - * @return An absolute path - */ - public static String expandUserHome(String file) { - // replace any / with the proper separator (/ or \ for Linux and Windows respectively). - file = file.replaceAll("/", "\\"+File.separator); //The "\\" is to escape the separator if needed. - if (file.startsWith("~") && (file.length() == 1 || File.separator.equals(file.substring(1, 2)))) { - file = System.getProperty("user.home") + file.substring(1); - } - return file; - } /** * Pings a HTTP URL. This effectively sends a HEAD request and returns @@ -393,38 +288,6 @@ public static URLConnection prepareURLConnection(String url, int timeout) throws return connection; } - /** - * Recursively delete a folder & contents - * - * @param dir directory to delete - */ - public static void deleteDirectory(Path dir) throws IOException { - if(dir == null || !Files.exists(dir)) - return; - Files.walkFileTree(dir, new SimpleFileVisitor() { - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - Files.delete(file); - return FileVisitResult.CONTINUE; - } - @Override - public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { - if (e != null) { - throw e; - } - Files.delete(dir); - return FileVisitResult.CONTINUE; - } - }); - } - /** - * Recursively delete a folder & contents - * - * @param dir directory to delete - */ - public static void deleteDirectory(String dir) throws IOException { - deleteDirectory(Paths.get(dir)); - } } diff --git a/biojava-core/src/main/java/org/biojava/nbio/core/util/FileOperationUtils.java b/biojava-core/src/main/java/org/biojava/nbio/core/util/FileOperationUtils.java new file mode 100644 index 0000000000..d9b390389e --- /dev/null +++ b/biojava-core/src/main/java/org/biojava/nbio/core/util/FileOperationUtils.java @@ -0,0 +1,151 @@ +package org.biojava.nbio.core.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; + +/** + * @author Sreejith Nair + */ +public class FileOperationUtils { + /** + * @param src + * @param dst + * @throws IOException + */ + @SuppressWarnings("resource") + public static void copy(File src, File dst) throws IOException { + + // Took following recipe from + // http://stackoverflow.com/questions/106770/standard-concise-way-to-copy-a-file-in-java + // The nio package seems to be the most efficient way to copy a file + FileChannel source = null; + FileChannel destination = null; + + try { + // we need the supress warnings here (the warning that the stream is not closed is harmless) + // see http://stackoverflow.com/questions/12970407/does-filechannel-close-close-the-underlying-stream + source = new FileInputStream(src).getChannel(); + destination = new FileOutputStream(dst).getChannel(); + destination.transferFrom(source, 0, source.size()); + } finally { + if (source != null) { + source.close(); + } + if (destination != null) { + destination.close(); + } + } + } + + /** + * Gets the file extension of a file, excluding '.'. + * If the file name has no extension the file name is returned. + * @param f a File + * @return The extension + */ + public static String getFileExtension(File f) { + String fileName = f.getName(); + String ext = ""; + int mid = fileName.lastIndexOf("."); + ext = fileName.substring(mid + 1, fileName.length()); + return ext; + } + + /** + * Gets the file name up to and excluding the first + * '.' character. If there is no extension, the full filename + * is returned. + * @param f A file + * @return A possibly empty but non-null String. + */ + public static String getFilePrefix(File f) { + String fileName = f.getName(); + int mid = fileName.indexOf("."); + if (mid < 0) { + return fileName; + } + return fileName.substring(0, mid); + } + + /** + * Converts path to Unix convention and adds a terminating slash if it was + * omitted. + * + * @param path original platform dependent path + * @return path in Unix convention + * @author Peter Rose + * @since 3.2 + */ + public static String toUnixPath(String path) { + String uPath = path; + if (uPath.contains("\\")) { + uPath = uPath.replaceAll("\\\\", "/"); + } + // this should be removed, it's need since "\" is added AtomCache code + if (uPath.endsWith("//")) { + uPath = uPath.substring(0, uPath.length() - 1); + } + if (!uPath.endsWith("/")) { + uPath = uPath + "/"; + } + return uPath; + } + + /** + * Expands ~ in paths to the user's home directory. + * + *

+ * This does not work for some special cases for paths: Other users' homes + * (~user/...), and Tilde expansion within the path (/.../~/...). In these cases + * the original argument is returned. + * + * @param file A filepath starting with a tilde + * @return An absolute path + */ + public static String expandUserHome(String file) { + // replace any / with the proper separator (/ or \ for Linux and Windows respectively). + file = file.replaceAll("/", "\\"+File.separator); //The "\\" is to escape the separator if needed. + if (file.startsWith("~") && (file.length() == 1 || File.separator.equals(file.substring(1, 2)))) { + file = System.getProperty("user.home") + file.substring(1); + } + return file; + } + /** + * Recursively delete a folder & contents + * + * @param dir directory to delete + */ + public static void deleteDirectory(Path dir) throws IOException { + if(dir == null || !Files.exists(dir)) + return; + Files.walkFileTree(dir, new SimpleFileVisitor() { + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + Files.delete(file); + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException { + if (e != null) { + throw e; + } + Files.delete(dir); + return FileVisitResult.CONTINUE; + } + }); + } + /** + * Recursively delete a folder & contents + * + * @param dir directory to delete + */ + public static void deleteDirectory(String dir) throws IOException { + deleteDirectory(Paths.get(dir)); + } +} diff --git a/biojava-core/src/test/java/org/biojava/nbio/core/util/FileDownloadUtilsTest.java b/biojava-core/src/test/java/org/biojava/nbio/core/util/FileDownloadUtilsTest.java index 33825e19a5..dbc2cce7e6 100644 --- a/biojava-core/src/test/java/org/biojava/nbio/core/util/FileDownloadUtilsTest.java +++ b/biojava-core/src/test/java/org/biojava/nbio/core/util/FileDownloadUtilsTest.java @@ -1,7 +1,5 @@ package org.biojava.nbio.core.util; -import static org.biojava.nbio.core.util.FileDownloadUtils.getFileExtension; -import static org.biojava.nbio.core.util.FileDownloadUtils.getFilePrefix; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -39,7 +37,7 @@ void copyFile() throws IOException { assertEquals(5, src.length()); File dest = Files.createTempFile("dest", ".dat").toFile(); assertEquals(0, dest.length()); - FileDownloadUtils.copy(src, dest); + FileOperationUtils.copy(src, dest); assertEquals(5, dest.length()); //original is unaffected @@ -62,31 +60,31 @@ class FileExtension { @Test void getExtensionHappyCase(){ File someFile = new File("sequence.fasta"); - assertEquals("fasta", getFileExtension(someFile)); + assertEquals("fasta", FileOperationUtils.getFileExtension(someFile)); } @Test void lastSuffixOnlyReturned(){ File someFile = new File("sequence.1.a.fasta"); - assertEquals("fasta", getFileExtension(someFile)); + assertEquals("fasta", FileOperationUtils.getFileExtension(someFile)); } @Test void fileNameEndingInDotReturnsEmptyString(){ File someFile = new File("noExtension."); - assertEquals("", getFileExtension(someFile)); + assertEquals("", FileOperationUtils.getFileExtension(someFile)); } @Test void hiddenFile(){ File someFile = new File(".m2"); - assertEquals("m2", getFileExtension(someFile)); + assertEquals("m2", FileOperationUtils.getFileExtension(someFile)); } @Test void noExtension(){ File someFile = new File("nameOnly"); - assertEquals("nameOnly", getFileExtension(someFile)); + assertEquals("nameOnly", FileOperationUtils.getFileExtension(someFile)); } } @@ -95,24 +93,24 @@ class GetFilePrefix{ @Test void standardFileName(){ File someFile = new File("sequence.fasta"); - assertEquals("sequence", getFilePrefix(someFile)); + assertEquals("sequence", FileOperationUtils.getFilePrefix(someFile)); } @Test void prefixIsUpToFirstDot(){ File someFile = new File("sequence.1.2.fasta"); - assertEquals("sequence", getFilePrefix(someFile)); + assertEquals("sequence", FileOperationUtils.getFilePrefix(someFile)); } @Test void noExtension(){ File someFile = new File("nameOnly"); - assertEquals("nameOnly", getFilePrefix(someFile)); + assertEquals("nameOnly", FileOperationUtils.getFilePrefix(someFile)); } @Test void hiddenFile(){ File someFile = new File(".m2"); - assertEquals("", getFilePrefix(someFile)); + assertEquals("", FileOperationUtils.getFilePrefix(someFile)); } } @@ -121,12 +119,12 @@ class ToUnixPath { @Test void windowsToUnixAddsTrailingSlash(){ String winPath = "C:\\a\\b\\c"; - assertEquals("C:/a/b/c/", FileDownloadUtils.toUnixPath(winPath)); + assertEquals("C:/a/b/c/", FileOperationUtils.toUnixPath(winPath)); } @Test void unixPathReturnedUnchanged(){ String path = "/a/b/c/"; - assertEquals(path, FileDownloadUtils.toUnixPath(path)); + assertEquals(path, FileOperationUtils.toUnixPath(path)); } } @@ -136,12 +134,12 @@ class ExpandUserHome { @Test void minimalPath (){ String path="~"; - assertEquals(currUserHome, FileDownloadUtils.expandUserHome(path)); + assertEquals(currUserHome, FileOperationUtils.expandUserHome(path)); } @Test void simplePath (){ String path="~/sequence.gb"; - assertEquals(currUserHome+File.separator+"sequence.gb", FileDownloadUtils.expandUserHome(path)); + assertEquals(currUserHome+File.separator+"sequence.gb", FileOperationUtils.expandUserHome(path)); } @Test void nestedPath (){ @@ -150,8 +148,8 @@ void nestedPath (){ + "a" + File.separator + "b" + File.separator + "c" + File.separator - + "sequence.gb", - FileDownloadUtils.expandUserHome(path)); + + "sequence.gb", + FileOperationUtils.expandUserHome(path)); } } @@ -189,7 +187,7 @@ void deleteFolderTree() throws IOException{ File toDelete = createDirectoryTree(); assertTrue(toDelete.exists()); - FileDownloadUtils.deleteDirectory(toDelete.getAbsolutePath()); + FileOperationUtils.deleteDirectory(toDelete.getAbsolutePath()); assertFalse(toDelete.exists()); } } diff --git a/biojava-genome/src/main/java/org/biojava/nbio/genome/util/ProteinMappingTools.java b/biojava-genome/src/main/java/org/biojava/nbio/genome/util/ProteinMappingTools.java index 8fdb093c54..283623c5cd 100644 --- a/biojava-genome/src/main/java/org/biojava/nbio/genome/util/ProteinMappingTools.java +++ b/biojava-genome/src/main/java/org/biojava/nbio/genome/util/ProteinMappingTools.java @@ -35,17 +35,6 @@ public class ProteinMappingTools { */ public static ProteinSequence convertDNAtoProteinSequence(String dnaSequence) throws CompoundNotFoundException { DNASequence dna = new DNASequence(dnaSequence); - return convertDNAtoProteinSequence(dna); - } - - /** Converts the DNA sequence to protein sequence. - * - * @param dnaSequence the DNA sequence - * - * @return the protein sequence - */ - public static ProteinSequence convertDNAtoProteinSequence(DNASequence dnaSequence) throws CompoundNotFoundException { - RNASequence mRNA = dnaSequence.getRNASequence(); - return mRNA.getProteinSequence(); + return dna.convertDNAtoProteinSequence(dna); } } diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureTools.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureTools.java index af5f7ab80f..a73d3d5fa0 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureTools.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/StructureTools.java @@ -40,6 +40,7 @@ import javax.vecmath.Point3d; +import org.biojava.nbio.core.util.FileOperationUtils; import org.biojava.nbio.structure.align.util.AtomCache; import org.biojava.nbio.structure.contact.AtomContactSet; import org.biojava.nbio.structure.contact.Grid; @@ -1696,7 +1697,7 @@ public static Structure getStructure(String name) throws IOException, */ public static Structure getStructure(String name, PDBFileParser parser, AtomCache cache) throws IOException, StructureException { - File f = new File(FileDownloadUtils.expandUserHome(name)); + File f = new File(FileOperationUtils.expandUserHome(name)); if (f.exists()) { if (parser == null) { parser = new PDBFileParser(); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/client/StructureName.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/client/StructureName.java index 123987531b..cf2187d5ae 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/client/StructureName.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/client/StructureName.java @@ -34,6 +34,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.biojava.nbio.core.util.FileOperationUtils; import org.biojava.nbio.structure.BioAssemblyIdentifier; import org.biojava.nbio.structure.PdbId; import org.biojava.nbio.structure.ResidueRange; @@ -220,7 +221,7 @@ private void init(){ return; // Guess FILE based on file existence - File file = new File(FileDownloadUtils.expandUserHome(name)); + File file = new File(FileOperationUtils.expandUserHome(name)); if( file.canRead() && !file.isDirectory() ) { // an attempt to mitigate issue #398. It doesn't fix it but it catches the most common case of passing a pdb id and finding a file in working dir matching it if (name.matches("\\d\\w\\w\\w")) { @@ -474,7 +475,7 @@ public StructureIdentifier getBaseIdentifier() throws StructureException { } else { filename = name; } - filename = FileDownloadUtils.expandUserHome(filename); + filename = FileOperationUtils.expandUserHome(filename); base = new URLIdentifier(new File(filename).toURI().toURL()); } catch (MalformedURLException e) { // Should never happen diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java index 258fdbf7f3..2835d7fb92 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/AtomCache.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.TreeSet; +import org.biojava.nbio.core.util.FileOperationUtils; import org.biojava.nbio.core.util.InputStreamProvider; import org.biojava.nbio.structure.*; import org.biojava.nbio.structure.align.client.StructureName; @@ -723,7 +724,7 @@ public void setFetchBehavior(FetchBehavior fetchBehavior) { * to a directory */ public void setPath(String path) { - this.path = FileDownloadUtils.expandUserHome(path); + this.path = FileOperationUtils.expandUserHome(path); } /** diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java index 3b7f94981a..48d9f2a197 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/cath/CathInstallation.java @@ -23,6 +23,7 @@ package org.biojava.nbio.structure.cath; +import org.biojava.nbio.core.util.FileOperationUtils; import org.biojava.nbio.structure.align.util.UserConfiguration; import org.biojava.nbio.core.util.FileDownloadUtils; import org.slf4j.Logger; @@ -640,7 +641,7 @@ protected void downloadFileFromRemote(URL remoteURL, File localFile) throws IOEx LOGGER.info("Downloading file {} to local file {}", remoteURL, localFile); long timeS = System.currentTimeMillis(); - File tempFile = Files.createTempFile(FileDownloadUtils.getFilePrefix(localFile),"." + FileDownloadUtils.getFileExtension(localFile)).toFile(); + File tempFile = Files.createTempFile(FileOperationUtils.getFilePrefix(localFile),"." + FileOperationUtils.getFileExtension(localFile)).toFile(); FileOutputStream out = new FileOutputStream(tempFile); @@ -653,7 +654,7 @@ protected void downloadFileFromRemote(URL remoteURL, File localFile) throws IOEx in.close(); out.close(); - FileDownloadUtils.copy(tempFile,localFile); + FileOperationUtils.copy(tempFile,localFile); // delete the tmp file tempFile.delete(); diff --git a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java index 127a1ad019..add7357ba6 100644 --- a/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java +++ b/biojava-structure/src/main/java/org/biojava/nbio/structure/io/LocalPDBDirectory.java @@ -36,6 +36,7 @@ import java.util.Locale; import org.biojava.nbio.core.util.FileDownloadUtils; +import org.biojava.nbio.core.util.FileOperationUtils; import org.biojava.nbio.core.util.InputStreamProvider; import org.biojava.nbio.structure.PdbId; import org.biojava.nbio.structure.PDBStatus; @@ -183,7 +184,7 @@ public LocalPDBDirectory(String path) { path = config.getPdbFilePath(); logger.debug("Initialising from system property/environment variable to path: {}", path); } else { - path = FileDownloadUtils.expandUserHome(path); + path = FileOperationUtils.expandUserHome(path); logger.debug("Initialising with path {}", path); } this.path = new File(path); @@ -205,7 +206,7 @@ public LocalPDBDirectory() { * Sets the path for the directory where PDB files are read/written */ public void setPath(String p){ - path = new File(FileDownloadUtils.expandUserHome(p)) ; + path = new File(FileOperationUtils.expandUserHome(p)) ; initPaths(); } @@ -311,7 +312,7 @@ public void setFetchBehavior(FetchBehavior fetchBehavior) { @Override public Structure getStructure(String filename) throws IOException { - filename = FileDownloadUtils.expandUserHome(filename); + filename = FileOperationUtils.expandUserHome(filename); File f = new File(filename); return getStructure(f); diff --git a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java index af56e67046..3ebf5b3b38 100644 --- a/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java +++ b/biojava-structure/src/test/java/org/biojava/nbio/structure/align/util/AtomCacheTest.java @@ -39,8 +39,7 @@ import java.util.List; import java.util.Locale; import java.util.zip.GZIPOutputStream; - -import org.biojava.nbio.core.util.FileDownloadUtils; +import org.biojava.nbio.core.util.FileOperationUtils; import org.biojava.nbio.structure.AtomPositionMap; import org.biojava.nbio.structure.Chain; import org.biojava.nbio.structure.Group; @@ -370,7 +369,7 @@ public void testEmptyChemComp() throws IOException, StructureException { System.setProperty(UserConfiguration.PDB_DIR, tmpCache.toString()); System.setProperty(UserConfiguration.PDB_CACHE_DIR, tmpCache.toString()); - FileDownloadUtils.deleteDirectory(tmpCache); + FileOperationUtils.deleteDirectory(tmpCache); Files.createDirectory(tmpCache); try { cache.setPath(tmpCache.toString()); @@ -390,7 +389,7 @@ public void testEmptyChemComp() throws IOException, StructureException { Files.createDirectories(testCif.getParent()); URL resource = AtomCacheTest.class.getResource("/atp.cif.gz"); File src = new File(resource.getPath()); - FileDownloadUtils.copy(src, testCif.toFile()); + FileOperationUtils.copy(src, testCif.toFile()); // Load structure Structure s = cache.getStructure("1ABC"); @@ -410,7 +409,7 @@ public void testEmptyChemComp() throws IOException, StructureException { assertTrue(chem.getAtoms().size() > 0); assertEquals("NON-POLYMER", chem.getType()); } finally { - FileDownloadUtils.deleteDirectory(tmpCache); + FileOperationUtils.deleteDirectory(tmpCache); } } @@ -429,7 +428,7 @@ public void testEmptyGZChemComp() throws IOException, StructureException { System.setProperty(UserConfiguration.PDB_DIR, tmpCache.toString()); System.setProperty(UserConfiguration.PDB_CACHE_DIR, tmpCache.toString()); - FileDownloadUtils.deleteDirectory(tmpCache); + FileOperationUtils.deleteDirectory(tmpCache); Files.createDirectory(tmpCache); try { cache.setPath(tmpCache.toString()); @@ -453,7 +452,7 @@ public void testEmptyGZChemComp() throws IOException, StructureException { Files.createDirectories(testCif.getParent()); URL resource = AtomCacheTest.class.getResource("/atp.cif.gz"); File src = new File(resource.getPath()); - FileDownloadUtils.copy(src, testCif.toFile()); + FileOperationUtils.copy(src, testCif.toFile()); // Load structure Structure s = cache.getStructure("1ABC"); @@ -473,7 +472,7 @@ public void testEmptyGZChemComp() throws IOException, StructureException { assertTrue(chem.getAtoms().size() > 0); assertEquals("NON-POLYMER", chem.getType()); } finally { - FileDownloadUtils.deleteDirectory(tmpCache); + FileOperationUtils.deleteDirectory(tmpCache); } }