Skip to content

Commit

Permalink
refactor code - update names
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-ebi committed Aug 8, 2024
1 parent 30181d0 commit 5a91653
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ public class BeanNames {
public static final String VARIANT_ANNOTATION_READER = "variant-annotation-reader";
public static final String VARIANT_READER = "variant-reader";
public static final String ACCESSION_REPORT_READER = "accession-report-reader";
public static final String STATS_VARIANTS_READER = "stats-variants-reader";
public static final String VARIANT_STATS_READER = "variant-stats-reader";

public static final String VEP_ANNOTATION_PROCESSOR = "vep-annotation-processor";
public static final String ANNOTATION_PARSER_PROCESSOR = "annotation-parser-processor";
public static final String ANNOTATION_COMPOSITE_PROCESSOR = "annotation-composite-processor";
public static final String STATS_VARIANTS_PROCESSOR = "stats-variants-processor";
public static final String VARIANT_STATS_PROCESSOR = "variant-stats-processor";

public static final String GENE_WRITER = "gene-writer";
public static final String ANNOTATION_WRITER = "annotation-writer";
public static final String ANNOTATION_IN_VARIANT_WRITER = "annotation-in-variant-writer";
public static final String COMPOSITE_ANNOTATION_VARIANT_WRITER = "composite-annotation-variant-writer";
public static final String VARIANT_WRITER = "variant-writer";
public static final String ACCESSION_IMPORTER = "accession-importer";
public static final String STATS_VARIANTS_WRITER = "stats-variants-writer";
public static final String VARIANT_STATS_WRITER = "variant-stats-writer";

public static final String ANNOTATION_SKIP_STEP_DECIDER = "annotation-skip-step-decider";
public static final String STATISTICS_SKIP_STEP_DECIDER = "statistics-skip-step-decider";
Expand All @@ -63,7 +63,7 @@ public class BeanNames {
public static final String DROP_FILES_BY_STUDY_STEP = "drop-files-by-study-step";
public static final String LOAD_ANNOTATION_METADATA_STEP = "annotation-metadata-step";
public static final String ACCESSION_IMPORT_STEP = "accession-import-step";
public static final String CALCULATE_STATISTICS_STEP_NEW = "calculate-statistics-step-new";
public static final String CALCULATE_AND_LOAD_STATISTICS_STEP = "calculate-load-statistics-step";

public static final String AGGREGATED_VCF_JOB = "aggregated-vcf-job";
public static final String ANNOTATE_VARIANTS_JOB = "annotate-variants-job";
Expand All @@ -73,5 +73,5 @@ public class BeanNames {
public static final String CALCULATE_STATISTICS_JOB = "calculate-statistics-job";
public static final String DROP_STUDY_JOB = "drop-study-job";
public static final String ACCESSION_IMPORT_JOB = "accession-import-job";
public static final String CALCULATE_STATISTICS_JOB_NEW = "calculate-statistics-job-new";
public static final String CALCULATE_AND_LOAD_STATISTICS_JOB = "calculate-load-statistics-job";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;
import uk.ac.ebi.eva.commons.models.mongo.entity.VariantDocument;
import uk.ac.ebi.eva.pipeline.io.readers.StatsVariantReader;
import uk.ac.ebi.eva.pipeline.io.readers.VariantStatsReader;
import uk.ac.ebi.eva.pipeline.parameters.ChunkSizeParameters;
import uk.ac.ebi.eva.pipeline.parameters.DatabaseParameters;
import uk.ac.ebi.eva.pipeline.parameters.InputParameters;

import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.STATS_VARIANTS_READER;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.VARIANT_STATS_READER;

@Configuration
public class StatsVariantsReaderConfiguration {
public class VariantStatsReaderConfiguration {

@Bean(STATS_VARIANTS_READER)
@Bean(VARIANT_STATS_READER)
@StepScope
public ItemStreamReader<VariantDocument> statsVariantsReader(DatabaseParameters databaseParameters,
MongoTemplate mongoTemplate,
InputParameters inputParameters,
ChunkSizeParameters chunkSizeParameters) {
public ItemStreamReader<VariantDocument> variantStatsReader(DatabaseParameters databaseParameters,
MongoTemplate mongoTemplate,
InputParameters inputParameters,
ChunkSizeParameters chunkSizeParameters) {

return new StatsVariantReader(databaseParameters, mongoTemplate, inputParameters.getStudyId(), chunkSizeParameters.getChunkSize());
return new VariantStatsReader(databaseParameters, mongoTemplate, inputParameters.getStudyId(), chunkSizeParameters.getChunkSize());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.MongoTemplate;
import uk.ac.ebi.eva.commons.models.mongo.entity.VariantDocument;
import uk.ac.ebi.eva.pipeline.io.writers.StatsVariantWriter;
import uk.ac.ebi.eva.pipeline.io.writers.VariantStatsWriter;
import uk.ac.ebi.eva.pipeline.parameters.DatabaseParameters;

import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.STATS_VARIANTS_WRITER;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.VARIANT_STATS_WRITER;

@Configuration
public class StatsVariantsWriterConfiguration {
public class VariantStatsWriterConfiguration {

@Bean(STATS_VARIANTS_WRITER)
@Bean(VARIANT_STATS_WRITER)
@StepScope
public ItemWriter<VariantDocument> statsVariantsWriter(DatabaseParameters databaseParameters, MongoTemplate mongoTemplate) {
return new StatsVariantWriter(databaseParameters, mongoTemplate);
public ItemWriter<VariantDocument> variantStatsWriter(DatabaseParameters databaseParameters, MongoTemplate mongoTemplate) {
return new VariantStatsWriter(databaseParameters, mongoTemplate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Scope;
import uk.ac.ebi.eva.pipeline.configuration.jobs.steps.CalculateStatisticsStepConfigurationNew;
import uk.ac.ebi.eva.pipeline.configuration.jobs.steps.CalculateAndLoadStatisticsStepConfiguration;
import uk.ac.ebi.eva.pipeline.parameters.NewJobIncrementer;

import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.CALCULATE_STATISTICS_JOB_NEW;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.CALCULATE_STATISTICS_STEP_NEW;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.CALCULATE_AND_LOAD_STATISTICS_JOB;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.CALCULATE_AND_LOAD_STATISTICS_STEP;

/**
* Configuration to run a full Statistics job: variantStatsFlow: statsCreate --> statsLoad
Expand All @@ -40,24 +40,24 @@
*/
@Configuration
@EnableBatchProcessing
@Import({CalculateStatisticsStepConfigurationNew.class})
public class PopulationStatisticsJobConfigurationNew {
@Import({CalculateAndLoadStatisticsStepConfiguration.class})
public class CalculateAndLoadStatisticsJobConfiguration {

private static final Logger logger = LoggerFactory.getLogger(PopulationStatisticsJobConfigurationNew.class);
private static final Logger logger = LoggerFactory.getLogger(CalculateAndLoadStatisticsJobConfiguration.class);

@Autowired
@Qualifier(CALCULATE_STATISTICS_STEP_NEW)
private Step calculateStatisticsStepNew;
@Qualifier(CALCULATE_AND_LOAD_STATISTICS_STEP)
private Step calculateAndLoadStatisticsStep;

@Bean(CALCULATE_STATISTICS_JOB_NEW)
@Bean(CALCULATE_AND_LOAD_STATISTICS_JOB)
@Scope("prototype")
public Job calculateStatisticsJob(JobBuilderFactory jobBuilderFactory) {
logger.debug("Building '" + CALCULATE_STATISTICS_JOB_NEW + "'");
public Job calculateAndLoadStatisticsJob(JobBuilderFactory jobBuilderFactory) {
logger.debug("Building '" + CALCULATE_AND_LOAD_STATISTICS_JOB + "'");

return jobBuilderFactory
.get(CALCULATE_STATISTICS_JOB_NEW)
.get(CALCULATE_AND_LOAD_STATISTICS_JOB)
.incrementer(new NewJobIncrementer())
.start(calculateStatisticsStepNew)
.start(calculateAndLoadStatisticsStep)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@
import org.springframework.context.annotation.Import;
import uk.ac.ebi.eva.commons.models.mongo.entity.VariantDocument;
import uk.ac.ebi.eva.pipeline.configuration.ChunkSizeCompletionPolicyConfiguration;
import uk.ac.ebi.eva.pipeline.configuration.io.readers.StatsVariantsReaderConfiguration;
import uk.ac.ebi.eva.pipeline.configuration.io.writers.StatsVariantsWriterConfiguration;
import uk.ac.ebi.eva.pipeline.configuration.jobs.steps.processors.StatsVariantsProcessorConfiguration;
import uk.ac.ebi.eva.pipeline.configuration.io.readers.VariantStatsReaderConfiguration;
import uk.ac.ebi.eva.pipeline.configuration.io.writers.VariantStatsWriterConfiguration;
import uk.ac.ebi.eva.pipeline.configuration.jobs.steps.processors.VariantStatsProcessorConfiguration;

import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.CALCULATE_STATISTICS_STEP_NEW;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.STATS_VARIANTS_PROCESSOR;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.STATS_VARIANTS_READER;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.STATS_VARIANTS_WRITER;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.CALCULATE_AND_LOAD_STATISTICS_STEP;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.VARIANT_STATS_PROCESSOR;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.VARIANT_STATS_READER;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.VARIANT_STATS_WRITER;


@Configuration
@EnableBatchProcessing
@Import({StatsVariantsReaderConfiguration.class, StatsVariantsWriterConfiguration.class,
StatsVariantsProcessorConfiguration.class, ChunkSizeCompletionPolicyConfiguration.class})
public class CalculateStatisticsStepConfigurationNew {
@Import({VariantStatsReaderConfiguration.class, VariantStatsWriterConfiguration.class,
VariantStatsProcessorConfiguration.class, ChunkSizeCompletionPolicyConfiguration.class})
public class CalculateAndLoadStatisticsStepConfiguration {

@Bean(CALCULATE_STATISTICS_STEP_NEW)
public Step calculateStatisticsStep(
@Qualifier(STATS_VARIANTS_READER) ItemStreamReader<VariantDocument> variantReader,
@Qualifier(STATS_VARIANTS_PROCESSOR) ItemProcessor<VariantDocument, VariantDocument> variantProcessor,
@Qualifier(STATS_VARIANTS_WRITER) ItemWriter<VariantDocument> variantWriter,
@Bean(CALCULATE_AND_LOAD_STATISTICS_STEP)
public Step calculateAndLoadStatisticsStep(
@Qualifier(VARIANT_STATS_READER) ItemStreamReader<VariantDocument> variantStatsReader,
@Qualifier(VARIANT_STATS_PROCESSOR) ItemProcessor<VariantDocument, VariantDocument> variantStatsProcessor,
@Qualifier(VARIANT_STATS_WRITER) ItemWriter<VariantDocument> variantStatsWriter,
StepBuilderFactory stepBuilderFactory,
SimpleCompletionPolicy chunkSizeCompletionPolicy) {
TaskletStep step = stepBuilderFactory.get(CALCULATE_STATISTICS_STEP_NEW)
TaskletStep step = stepBuilderFactory.get(CALCULATE_AND_LOAD_STATISTICS_STEP)
.<VariantDocument, VariantDocument>chunk(chunkSizeCompletionPolicy)
.reader(variantReader)
.processor(variantProcessor)
.writer(variantWriter)
.reader(variantStatsReader)
.processor(variantStatsProcessor)
.writer(variantStatsWriter)
.build();
return step;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import uk.ac.ebi.eva.commons.models.mongo.entity.VariantDocument;
import uk.ac.ebi.eva.pipeline.io.processors.StatsVariantProcessor;
import uk.ac.ebi.eva.pipeline.io.processors.VariantStatsProcessor;

import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.STATS_VARIANTS_PROCESSOR;
import static uk.ac.ebi.eva.pipeline.configuration.BeanNames.VARIANT_STATS_PROCESSOR;

@Configuration
public class StatsVariantsProcessorConfiguration {
public class VariantStatsProcessorConfiguration {

@Bean(STATS_VARIANTS_PROCESSOR)
@Bean(VARIANT_STATS_PROCESSOR)
@StepScope
public ItemProcessor<VariantDocument, VariantDocument> statsVariantsReader() {
return new StatsVariantProcessor();
public ItemProcessor<VariantDocument, VariantDocument> variantStatsProcessor() {
return new VariantStatsProcessor();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import uk.ac.ebi.eva.commons.models.mongo.entity.VariantDocument;
import uk.ac.ebi.eva.commons.models.mongo.entity.subdocuments.VariantSourceEntryMongo;
import uk.ac.ebi.eva.commons.models.mongo.entity.subdocuments.VariantStatsMongo;
import uk.ac.ebi.eva.pipeline.io.readers.StatsVariantReader;
import uk.ac.ebi.eva.pipeline.io.readers.VariantStatsReader;

import java.util.Arrays;
import java.util.Comparator;
Expand All @@ -21,21 +21,21 @@
import java.util.Set;
import java.util.stream.Collectors;

public class StatsVariantProcessor implements ItemProcessor<VariantDocument, VariantDocument> {
private static final Logger logger = LoggerFactory.getLogger(StatsVariantProcessor.class);
public class VariantStatsProcessor implements ItemProcessor<VariantDocument, VariantDocument> {
private static final Logger logger = LoggerFactory.getLogger(VariantStatsProcessor.class);
private static final String GENOTYPE_COUNTS_MAP = "genotypeCountsMap";
private static final String ALLELE_COUNTS_MAP = "alleleCountsMap";
private static final String MISSING_GENOTYPE = "missingGenotype";
private static final String MISSING_ALLELE = "missingAllele";
private static final String DEFAULT_GENOTYPE = "def";
private static final List<String> MISSING_GENOTYPE_ALLELE_REPRESENTATIONS = Arrays.asList(".", "-1");

public StatsVariantProcessor() {
public VariantStatsProcessor() {
}

@Override
public VariantDocument process(VariantDocument variant) {
Map<String, Integer> filesIdNumberOfSamplesMap = StatsVariantReader.getFilesIdAndNumberOfSamplesMap();
Map<String, Integer> filesIdNumberOfSamplesMap = VariantStatsReader.getFilesIdAndNumberOfSamplesMap();

String variantRef = variant.getReference();
String variantAlt = variant.getAlternate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import static com.mongodb.client.model.Projections.fields;
import static java.util.Arrays.asList;

public class StatsVariantReader implements ItemStreamReader<VariantDocument> {
private static final Logger logger = LoggerFactory.getLogger(StatsVariantReader.class);
public class VariantStatsReader implements ItemStreamReader<VariantDocument> {
private static final Logger logger = LoggerFactory.getLogger(VariantStatsReader.class);

private DatabaseParameters databaseParameters;
private MongoTemplate mongoTemplate;
Expand All @@ -40,7 +40,7 @@ public class StatsVariantReader implements ItemStreamReader<VariantDocument> {

private static Map<String, Integer> filesIdNumberOfSamplesMap = new HashMap<>();

public StatsVariantReader(DatabaseParameters databaseParameters, MongoTemplate mongoTemplate, String studyId, int chunkSize) {
public VariantStatsReader(DatabaseParameters databaseParameters, MongoTemplate mongoTemplate, String studyId, int chunkSize) {
this.databaseParameters = databaseParameters;
this.mongoTemplate = mongoTemplate;
this.studyId = studyId;
Expand All @@ -50,10 +50,10 @@ public StatsVariantReader(DatabaseParameters databaseParameters, MongoTemplate m
@Override
public VariantDocument read() {
Document nextElement = cursor.tryNext();
return (nextElement != null) ? getStatsVariant(nextElement) : null;
return (nextElement != null) ? getVariant(nextElement) : null;
}

private VariantDocument getStatsVariant(Document variantDocument) {
private VariantDocument getVariant(Document variantDocument) {
return converter.read(VariantDocument.class, new BasicDBObject(variantDocument));
}

Expand All @@ -74,11 +74,11 @@ private MongoCursor<Document> initializeCursor() {
Bson query = Filters.elemMatch(VariantDocument.FILES_FIELD, Filters.eq(VariantSourceEntryMongo.STUDYID_FIELD, studyId));
logger.info("Issuing find: {}", query);

FindIterable<Document> statsVariantDocuments = getStatsVariants(query);
FindIterable<Document> statsVariantDocuments = getVariants(query);
return statsVariantDocuments.iterator();
}

private FindIterable<Document> getStatsVariants(Bson query) {
private FindIterable<Document> getVariants(Bson query) {
return mongoTemplate.getCollection(databaseParameters.getCollectionVariantsName())
.find(query)
.noCursorTimeout(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

import java.util.List;

public class StatsVariantWriter implements ItemWriter<VariantDocument> {
private static final Logger logger = LoggerFactory.getLogger(StatsVariantWriter.class);
public class VariantStatsWriter implements ItemWriter<VariantDocument> {
private static final Logger logger = LoggerFactory.getLogger(VariantStatsWriter.class);
private DatabaseParameters databaseParameters;
private MongoTemplate mongoTemplate;

public StatsVariantWriter(DatabaseParameters databaseParameters, MongoTemplate mongoTemplate) {
public VariantStatsWriter(DatabaseParameters databaseParameters, MongoTemplate mongoTemplate) {
this.databaseParameters = databaseParameters;
this.mongoTemplate = mongoTemplate;
}
Expand Down
Loading

0 comments on commit 5a91653

Please sign in to comment.