Skip to content
Open
32 changes: 22 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,57 @@
# Stage 1: Build the Java application JAR
FROM maven:3-eclipse-temurin-21 as jar_builder

# Set the working directory in the Maven image
WORKDIR /app

# Copy the java source files and the pom.xml file into the image
# Copy the Java source files and the pom.xml file into the image
COPY src ./src
COPY pom.xml .

# Build the application
RUN mvn clean package -DskipTests

# Stage 2: Prepare the final image
FROM maven:3-eclipse-temurin-21

# download system dependencies first to take advantage of docker caching
RUN apt-get update; apt-get install -y --no-install-recommends \
# Download system dependencies first to take advantage of Docker caching
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
default-mysql-client \
default-libmysqlclient-dev \
python3 \
python3-setuptools \
python3-venv \
python3-dev \
python3-pip \
unzip \
perl \
&& rm -rf /var/lib/apt/lists/* \
&& pip3 install wheel
&& rm -rf /var/lib/apt/lists/*

# Install any needed packages specified in requirements.txt
# Set up a Python virtual environment
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"

# Install Python packages in the virtual environment
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

RUN ln -s $(which python3) /usr/local/bin/python || true
# Link python3 to python for compatibility
RUN ln -s /opt/venv/bin/python /usr/local/bin/python || true

# Copy the built JAR from the first stage
COPY --from=jar_builder /app/core-*.jar /

# Copy and set permissions for scripts
COPY scripts/ scripts/
RUN chmod -R a+x /scripts/

# Set the working directory in the container
WORKDIR /scripts/

# Environment variable
ENV PORTAL_HOME=/

# This file is empty. It has to be overriden by bind mounting the actual application.properties
# Create an empty application.properties file
RUN touch /application.properties

# Entry command
CMD ["python", "your_script.py"]
24 changes: 0 additions & 24 deletions src/main/java/org/mskcc/cbio/portal/dao/DaoGeneOptimized.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,30 +343,6 @@ public List<CanonicalGene> guessGene(String geneId, String chr) {
return Collections.emptyList();
}


private static Map<String,String> validChrValues = null;
public static String normalizeChr(String strChr) {
if (strChr==null) {
return null;
}

if (validChrValues==null) {
validChrValues = new HashMap<String,String>();
for (int lc = 1; lc<=24; lc++) {
validChrValues.put(Integer.toString(lc),Integer.toString(lc));
validChrValues.put("CHR" + Integer.toString(lc),Integer.toString(lc));
}
validChrValues.put("X","23");
validChrValues.put("CHRX","23");
validChrValues.put("Y","24");
validChrValues.put("CHRY","24");
validChrValues.put("NA","NA");
validChrValues.put("MT","MT"); // mitochondria
}

return validChrValues.get(strChr);
}

private static String getChrFromCytoband(String cytoband) {
if (cytoband==null) {
return null;
Expand Down
142 changes: 142 additions & 0 deletions src/main/java/org/mskcc/cbio/portal/scripts/FilterMutationData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* Copyright (c) 2015 - 2022 Memorial Sloan Kettering Cancer Center.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
* FOR A PARTICULAR PURPOSE. The software and documentation provided hereunder
* is on an "as is" basis, and Memorial Sloan Kettering Cancer Center has no
* obligations to provide maintenance, support, updates, enhancements or
* modifications. In no event shall Memorial Sloan Kettering Cancer Center be
* liable to any party for direct, indirect, special, incidental or
* consequential damages, including lost profits, arising out of the use of this
* software and its documentation, even if Memorial Sloan Kettering Cancer
* Center has been advised of the possibility of such damage.
*/

/*
* This file is part of cBioPortal.
*
* cBioPortal is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.mskcc.cbio.portal.scripts;

import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.mskcc.cbio.maf.MafRecord;
import org.mskcc.cbio.maf.MafUtil;
import org.mskcc.cbio.portal.util.*;

import java.io.*;
import java.util.*;

/**
* Read MAF records, filter records of interest and writes back to the file. The script backs up original file under {filename with extension}_backup.
*
* @author Ruslan Forostianov
*/
public class FilterMutationData extends ConsoleRunnable {

/**
* Instantiates a ConsoleRunnable to run with the given command line args.
*
* @param args the command line arguments to be used
* @see {@link #run()}
*/
public FilterMutationData(String[] args) {
super(args);
}

public void run() {
String description = "Filter MAF file for records of interest and rewrites it with selected mutations.";
OptionParser parser = new OptionParser();
OptionSpec<String> data = parser.accepts( "data",
"MAF data file" ).withRequiredArg().describedAs( "data_mutations.txt" ).ofType( String.class );
OptionSpec<String> meta = parser.accepts( "meta",
"meta (description) file" ).withOptionalArg().describedAs( "meta_mutations.txt" ).ofType( String.class );

OptionSet options = null;
File originalMutationFile;
Set<String> namespaces = null;
Set<String> filteredMutations = null;

try {
options = parser.parse( args );
originalMutationFile = new File((String) options.valueOf("data"));
if (options.has("meta")) {
File descriptorFile = new File((String) options.valueOf( "meta" ) );
filteredMutations = GeneticProfileReader.getVariantClassificationFilter(descriptorFile);
namespaces = GeneticProfileReader.getNamespaces(descriptorFile);
}
} catch (OptionException e) {
throw new UsageException(
this.getClass().getName(), description, parser,
e.getMessage());
} catch (Exception e) {
throw new RuntimeException(e);
}
ProgressMonitor.setCurrentMessage("Start filtering mutation records in the MAF file ...");
File resultMutationFile = new File(originalMutationFile.getAbsolutePath() + "_filtered");
final MutationFilter mutationFilter = new MutationFilter();
try (
BufferedReader originalFileBufferedReader = new BufferedReader(new FileReader(originalMutationFile));
BufferedWriter resultFileBufferedWriter = new BufferedWriter(new FileWriter(resultMutationFile))
) {
String line;
MafUtil mafUtil = null;
while ((line = originalFileBufferedReader.readLine()) != null) {
ProgressMonitor.incrementCurValue();
ConsoleUtil.showProgress();

if (TsvUtil.isDataLine(line)) {
if (mafUtil == null) {
mafUtil = new MafUtil(line, namespaces);
} else {
MafRecord record = mafUtil.parseRecord(line);
if (!mutationFilter.acceptMutation(record, filteredMutations)) {
continue;
}
}
}
resultFileBufferedWriter.write(line);
resultFileBufferedWriter.write(System.lineSeparator());
}
} catch (IOException e) {
e.printStackTrace();
}
File backupMutationFile = new File(originalMutationFile.getAbsolutePath() + "_backup");
if (originalMutationFile.renameTo(backupMutationFile)) {
ProgressMonitor.setCurrentMessage("The original file is backed up to:"
+ backupMutationFile.getAbsolutePath());
if (resultMutationFile.renameTo(originalMutationFile)) {
ProgressMonitor.setCurrentMessage("The MAF file has been overwritten with filtered records.");
} else {
throw new RuntimeException("Failed to rename the filtered MAF file ("
+ resultMutationFile.getAbsolutePath() + ") to the input MAF file ("
+ originalMutationFile.getAbsolutePath() + ").");
}
} else {
throw new RuntimeException("Failed to rename MAF file ("
+ originalMutationFile.getAbsolutePath() + ") for backup.");
}
ProgressMonitor.setCurrentMessage(mutationFilter.getStatistics());
}

public static void main(String[] args) {
ConsoleRunnable runner = new FilterMutationData(args);
runner.runInConsole();
}
}
Loading