Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI cleanups #550

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;
import ubic.gemma.core.loader.expression.DataUpdater;
import ubic.gemma.core.loader.expression.geo.model.GeoPlatform;
import ubic.gemma.core.util.AbstractCLI;
import ubic.gemma.core.util.CLI;
import ubic.gemma.model.common.auditAndSecurity.eventType.DataReplacedEvent;
import ubic.gemma.model.common.auditAndSecurity.eventType.FailedDataReplacedEvent;
import ubic.gemma.model.common.quantitationtype.QuantitationType;
Expand Down Expand Up @@ -60,8 +62,8 @@ private boolean checkForAlreadyDone( BioAssaySet ee ) {
}

@Override
public GemmaCLI.CommandGroup getCommandGroup() {
return GemmaCLI.CommandGroup.EXPERIMENT;
public CommandGroup getCommandGroup() {
return CLI.CommandGroup.EXPERIMENT;
}

@Override
Expand All @@ -75,16 +77,16 @@ public String getShortDesc() {
}

@Override
protected void buildOptions( Options options ) {
super.buildOptions( options );
protected void buildBatchOptions( Options options ) {
super.buildBatchOptions( options );
options.addOption( Option.builder( AffyDataFromCelCli.APT_FILE_OPT ).longOpt( null ).desc( "File output from apt-probeset-summarize; use if you want to override usual GEO download behaviour; "
+ "ensure you used the right official CDF/MPS configuration" ).argName( "path" ).hasArg().build() );
super.addForceOption( options );

}

@Override
protected void doWork() throws Exception {
protected void doBatchWork() throws Exception {
DataUpdater serv = this.getBean( DataUpdater.class );

if ( this.expressionExperiments.isEmpty() )
Expand Down Expand Up @@ -182,8 +184,8 @@ protected void doWork() throws Exception {
}

@Override
protected void processOptions( CommandLine commandLine ) {
super.processOptions( commandLine );
protected void processBatchOptions( CommandLine commandLine ) throws ParseException {
super.processBatchOptions( commandLine );
if ( commandLine.hasOption( AffyDataFromCelCli.APT_FILE_OPT ) ) {
this.aptFile = commandLine.getOptionValue( AffyDataFromCelCli.APT_FILE_OPT );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import ubic.gemma.core.analysis.sequence.SequenceManipulation;
import ubic.gemma.core.loader.expression.arrayDesign.AffyProbeReader;
import ubic.gemma.model.expression.designElement.CompositeSequence;
Expand Down Expand Up @@ -60,17 +61,22 @@ public String getCommandName() {
}

@Override
protected void buildOptions( Options options ) {
super.buildOptions( options );
public String getShortDesc() {
return null;
}

@Override
protected void buildBatchOptions( Options options ) {
super.buildBatchOptions( options );
options.addOption( Option.builder( "affyProbeFile" )
.hasArg()
.desc( "Affymetrix probe file to use as input" )
.required().build() );
}

@Override
protected void processOptions( CommandLine commandLine ) {
super.processOptions( commandLine );
protected void processBatchOptions( CommandLine commandLine ) throws ParseException {
super.processBatchOptions( commandLine );
affyProbeFileName = commandLine.getOptionValue( "affyProbeFile" );
}

Expand All @@ -80,7 +86,7 @@ protected void processOptions( CommandLine commandLine ) {
* @see ubic.gemma.core.util.AbstractCLI#doWork(java.lang.String[])
*/
@Override
protected void doWork() throws IOException {
protected void doBatchWork() throws IOException {

// parse
AffyProbeReader apr = new AffyProbeReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.lang3.StringUtils;
import ubic.gemma.core.apps.GemmaCLI.CommandGroup;
import ubic.gemma.core.util.AbstractCLIContextCLI;
import ubic.gemma.core.util.AbstractCLI;
import ubic.gemma.model.expression.arrayDesign.ArrayDesign;
import ubic.gemma.persistence.service.expression.arrayDesign.ArrayDesignService;

Expand All @@ -37,7 +36,7 @@
*
* @author paul
*/
public class ArrayDesignAlternativePopulateCli extends AbstractCLIContextCLI {
public class ArrayDesignAlternativePopulateCli extends AbstractCLI {

@Override
public CommandGroup getCommandGroup() {
Expand All @@ -60,7 +59,7 @@ protected boolean requireLogin() {
}

@Override
protected void processOptions( CommandLine commandLine ) throws Exception {
protected void processOptions( CommandLine commandLine ) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.lang3.StringUtils;

import ubic.gemma.core.analysis.service.ArrayDesignAnnotationService;
import ubic.gemma.core.apps.GemmaCLI.CommandGroup;
import ubic.gemma.core.genome.gene.service.GeneService;
import ubic.gemma.core.ontology.providers.GeneOntologyService;
import ubic.gemma.core.util.AbstractCLI;
import ubic.gemma.model.expression.arrayDesign.ArrayDesign;
import ubic.gemma.model.expression.arrayDesign.TechnologyType;
import ubic.gemma.model.genome.Gene;
import ubic.gemma.model.genome.Taxon;
import ubic.gemma.persistence.service.expression.arrayDesign.ArrayDesignService;
import ubic.gemma.persistence.service.genome.taxon.TaxonService;

/**
Expand Down Expand Up @@ -81,9 +82,8 @@ public CommandGroup getCommandGroup() {
}

@Override
protected void buildOptions( Options options ) {
super.buildOptions( options );

protected void buildBatchOptions( Options options ) {
super.buildBatchOptions( options );
Option fileLoading = Option.builder( "l" ).desc( ArrayDesignAnnotationFileCli.FILE_LOAD_DESC ).hasArg()
.argName( "file of short names" ).build();

Expand All @@ -106,9 +106,9 @@ protected void buildOptions( Options options ) {
}

@Override
protected void processOptions( CommandLine commandLine ) {

if ( autoSeek ) {
protected void processBatchOptions( CommandLine commandLine ) throws ParseException {
super.processBatchOptions( commandLine );
if ( isAutoSeek() ) {
throw new IllegalArgumentException( "This CLI doesn't support the auto option" );
}

Expand Down Expand Up @@ -145,8 +145,6 @@ protected void processOptions( CommandLine commandLine ) {
if ( commandLine.hasOption( 'o' ) )
this.overWrite = true;

super.processOptions( commandLine );

this.arrayDesignAnnotationService = this.getBean( ArrayDesignAnnotationService.class );
this.goService = this.getBean( GeneOntologyService.class );
}
Expand All @@ -162,7 +160,7 @@ public String getCommandName() {
}

@Override
protected void doWork() throws Exception {
protected void doBatchWork() throws Exception {
this.taxonService = this.getBean( TaxonService.class );

this.waitForGeneOntologyReady();
Expand Down Expand Up @@ -334,7 +332,8 @@ private void processFromListInFile() throws IOException {
continue;
}

ArrayDesign arrayDesign = this.locateArrayDesign( accession, getArrayDesignService() );
ArrayDesignService arrayDesignService = getArrayDesignService();
ArrayDesign arrayDesign = arrayDesignService.findByNameOrByShortName( accession );

try {
this.processAD( arrayDesign );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ public String getCommandName() {
return "adATcleanup";
}

@Override
public String getShortDesc() {
return null;
}

/*
* (non-Javadoc)
*
* @see ubic.gemma.core.util.AbstractCLI#doWork(java.lang.String[])
*/
@Override
protected void doWork() throws Exception {
protected void doBatchWork() throws Exception {
for ( ArrayDesign arrayDesign : this.getArrayDesignsToProcess() ) {
arrayDesign = getArrayDesignService().thawLite( arrayDesign );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignSequenceRemoveEvent;
import ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType;
import ubic.gemma.model.expression.arrayDesign.ArrayDesign;
import ubic.gemma.model.expression.designElement.CompositeSequence;
import ubic.gemma.model.genome.biosequence.BioSequence;
Expand Down Expand Up @@ -51,23 +51,22 @@ public String getCommandName() {
}

@Override
protected void buildOptions( Options options ) {
super.buildOptions( options );

protected void buildBatchOptions( Options options ) {
super.buildBatchOptions( options );
Option fileOption = Option.builder( "delete" )
.desc( "Delete sequences instead of detaching them - use with care" ).build();

options.addOption( fileOption );
}

@Override
protected void processOptions( CommandLine commandLine ) {
super.processOptions( commandLine );
protected void processBatchOptions( CommandLine commandLine ) throws ParseException {
super.processBatchOptions( commandLine );
this.delete = commandLine.hasOption( "delete" );
}

@Override
protected void doWork() throws Exception {
protected void doBatchWork() throws Exception {
BioSequenceService bioSequenceService = this.getBean( BioSequenceService.class );

if ( this.getArrayDesignsToProcess().isEmpty() ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,20 @@
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import ubic.gemma.core.apps.GemmaCLI.CommandGroup;
import org.apache.commons.cli.ParseException;
import ubic.gemma.core.loader.expression.arrayDesign.ArrayDesignSequenceAlignmentService;
import ubic.gemma.core.loader.genome.BlatResultParser;
import ubic.gemma.core.util.AbstractCLI;
import ubic.gemma.model.common.auditAndSecurity.eventType.ArrayDesignSequenceAnalysisEvent;
import ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType;
import ubic.gemma.model.expression.arrayDesign.ArrayDesign;
import ubic.gemma.model.genome.Taxon;
import ubic.gemma.model.genome.sequenceAnalysis.BlatResult;
import ubic.gemma.persistence.service.genome.taxon.TaxonService;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.concurrent.*;

/**
* Command line interface to run blat on the sequences for a microarray; the results are persisted in the DB. You must
Expand All @@ -60,11 +55,9 @@ public CommandGroup getCommandGroup() {
return CommandGroup.PLATFORM;
}

@SuppressWarnings("static-access")
@Override
protected void buildOptions( Options options ) {
super.buildOptions( options );

protected void buildBatchOptions( Options options ) {
super.buildBatchOptions( options );
Option blatResultOption = Option.builder( "b" ).hasArg().argName( "PSL file" ).desc(
"Blat result file in PSL format (if supplied, BLAT will not be run; will not work with settings that indicate "
+ "multiple platforms to run); -t option overrides" )
Expand All @@ -75,6 +68,7 @@ protected void buildOptions( Options options ) {
.desc(
"Threshold (0-1.0) for acceptance of BLAT alignments [Default = " + this.blatScoreThreshold + "]" )
.longOpt( "scoreThresh" )
.type( Number.class )
.build();

options.addOption( Option.builder( "sensitive" ).desc( "Run on more sensitive server, if available" ).build() );
Expand All @@ -92,9 +86,8 @@ protected void buildOptions( Options options ) {
}

@Override
protected void processOptions( CommandLine commandLine ) {
super.processOptions( commandLine );

protected void processBatchOptions( CommandLine commandLine ) throws ParseException {
super.processBatchOptions( commandLine );
if ( commandLine.hasOption( "sensitive" ) ) {
this.sensitive = true;
}
Expand All @@ -108,7 +101,7 @@ protected void processOptions( CommandLine commandLine ) {
// }

if ( commandLine.hasOption( 's' ) ) {
this.blatScoreThreshold = this.getDoubleOptionValue( commandLine, 's' );
this.blatScoreThreshold = ( ( Number ) commandLine.getParsedOptionValue( 's' ) ).doubleValue();
}

TaxonService taxonService = this.getBean( TaxonService.class );
Expand All @@ -131,7 +124,7 @@ public String getCommandName() {
}

@Override
protected void doWork() throws Exception {
protected void doBatchWork() throws Exception {
final Date skipIfLastRunLaterThan = this.getLimitingDate();

if ( !this.getArrayDesignsToProcess().isEmpty() ) {
Expand Down Expand Up @@ -185,13 +178,10 @@ protected void doWork() throws Exception {
+ allArrayDesigns.size() + " items]" );

// split over multiple threads so we can multiplex. Put the array designs in a queue.
Collection<Callable<Void>> arrayDesigns = new ArrayList<>( allArrayDesigns.size() );
for ( ArrayDesign arrayDesign : allArrayDesigns ) {
arrayDesigns.add( new ProcessArrayDesign( arrayDesign, skipIfLastRunLaterThan ) );
getExecutorService().submit( new ProcessArrayDesign( arrayDesign, skipIfLastRunLaterThan ) );
}

executeBatchTasks( arrayDesigns );

} else {
throw new RuntimeException();
}
Expand Down Expand Up @@ -264,7 +254,7 @@ private void updateMergedOrSubsumed( ArrayDesign design ) {
/*
* Here is our task runner.
*/
private class ProcessArrayDesign implements Callable<Void> {
private class ProcessArrayDesign implements Runnable {

private ArrayDesign arrayDesign;
private Date skipIfLastRunLaterThan;
Expand All @@ -275,14 +265,13 @@ private ProcessArrayDesign( ArrayDesign arrayDesign, Date skipIfLastRunLaterThan
}

@Override
public Void call() {
public void run() {
if ( !ArrayDesignBlatCli.this.shouldRun( skipIfLastRunLaterThan, arrayDesign, ArrayDesignSequenceAnalysisEvent.class ) ) {
return null;
return;
}
arrayDesign = getArrayDesignService().thaw( arrayDesign );
ArrayDesignBlatCli.this.processArrayDesign( arrayDesign );
addSuccessObject( arrayDesign, "Processed " + arrayDesign.getShortName() );
return null;
}
}
}
Loading