<commit_before>package edu.yu.einstein.wasp.macstwo.batch.tasklet;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import edu.yu.einstein.wasp.Assert;
import edu.yu.einstein.wasp.daemon.batch.tasklets.WaspRemotingTasklet;
import edu.yu.einstein.wasp.grid.GridHostResolver;
import edu.yu.einstein.wasp.grid.work.GridResult;
import edu.yu.einstein.wasp.grid.work.GridTransportConnection;
import edu.yu.einstein.wasp.grid.work.GridWorkService;
import edu.yu.einstein.wasp.grid.work.WorkUnit;
import edu.yu.einstein.wasp.grid.work.WorkUnitGridConfiguration;
import edu.yu.einstein.wasp.grid.work.WorkUnitGridConfiguration.ProcessMode;
import edu.yu.einstein.wasp.integration.messages.WaspSoftwareJobParameters;
import edu.yu.einstein.wasp.macstwo.integration.messages.MacstwoSoftwareJobParameters;
import edu.yu.einstein.wasp.macstwo.service.MacstwoService;
import edu.yu.einstein.wasp.macstwo.software.Macstwo;
import edu.yu.einstein.wasp.model.FileGroup;
import edu.yu.einstein.wasp.model.FileGroupMeta;
import edu.yu.einstein.wasp.model.FileHandle;
import edu.yu.einstein.wasp.model.FileType;
import edu.yu.einstein.wasp.model.Job;
import edu.yu.einstein.wasp.model.Run;
import edu.yu.einstein.wasp.model.RunMeta;
import edu.yu.einstein.wasp.model.Sample;
import edu.yu.einstein.wasp.model.SampleMeta;
import edu.yu.einstein.wasp.model.SampleSource;
import edu.yu.einstein.wasp.model.Software;
import edu.yu.einstein.wasp.plugin.mps.grid.software.Imagemagick;
import edu.yu.einstein.wasp.plugin.mps.grid.software.R;
import edu.yu.einstein.wasp.plugin.supplemental.organism.Build;
import edu.yu.einstein.wasp.service.FileService;
import edu.yu.einstein.wasp.service.GenomeService;
import edu.yu.einstein.wasp.service.JobService;
import edu.yu.einstein.wasp.service.RunService;
import edu.yu.einstein.wasp.service.SampleService;

public class MacstwoTaskletModel extends WaspRemotingTasklet implements StepExecutionListener {

	private String jobIdAsString = "";
	private Integer jobId = null;
	private Job job = null;	
	private String prefixForFileName = "";
	private String macs2AnalysisFileGroupIdAsString = "";
	private String workingDirectory = "";
	private String resultsDirectory = "";
	private Integer macs2AnalysisFileGroupId = null;
	
	private String commandLineCall;	
	private String softwareIdUsedListAsString;
	
	private StepExecution stepExecution;
	
	@Autowired
	private FileType textFileType;//here, the model.r script output file
	@Autowired
	private FileType pdfFileType;//output pdf file after running the model.r script
	@Autowired
	private FileType pngFileType;//output after imagemagik on the pdf file
	
	@Autowired
	private JobService jobService;
	
	@Autowired
	private FileService fileService;

	@Autowired
	private GridHostResolver gridHostResolver;
	
	@Autowired
	private Macstwo macs2;
	
	@Autowired
	private MacstwoService macstwoService;

	public MacstwoTaskletModel() {
		// proxy
	}

	/**
	 * 
	 * @param contrib
	 * @param context
	 * @return
	 * @throws Exception
	 */
	@Transactional("entityManager")
	@Override
	public GridResult doExecute(ChunkContext context) throws Exception {
		
		logger.debug("Starting MacstwoTaskletModel execute");
		
		JobExecution jobExecution = this.stepExecution.getJobExecution();
		ExecutionContext executionContext = jobExecution.getExecutionContext();
				
		if(executionContext.containsKey(MacstwoService.JOB_ID_AS_STRING)){
			this.jobIdAsString = (String) executionContext.get(MacstwoService.JOB_ID_AS_STRING);
			this.jobId = Integer.parseInt(jobIdAsString);
			this.job = jobService.getJobByJobId(jobId);
		}
		if(executionContext.containsKey(MacstwoService.PREFIX_FOR_FILE_NAME)){
			this.prefixForFileName = (String) executionContext.get(MacstwoService.PREFIX_FOR_FILE_NAME);
			fileService.getSanitizedName(prefixForFileName);
		}		
		if(executionContext.containsKey(MacstwoService.MACSTWO_ANALYSIS_FILEGROUP_ID_AS_STRING)){<commit_msg>actually fixed the previous problem<commit_after>package edu.yu.einstein.wasp.macstwo.batch.tasklet;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameter;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepExecutionListener;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import edu.yu.einstein.wasp.Assert;
import edu.yu.einstein.wasp.daemon.batch.tasklets.WaspRemotingTasklet;
import edu.yu.einstein.wasp.grid.GridHostResolver;
import edu.yu.einstein.wasp.grid.work.GridResult;
import edu.yu.einstein.wasp.grid.work.GridTransportConnection;
import edu.yu.einstein.wasp.grid.work.GridWorkService;
import edu.yu.einstein.wasp.grid.work.WorkUnit;
import edu.yu.einstein.wasp.grid.work.WorkUnitGridConfiguration;
import edu.yu.einstein.wasp.grid.work.WorkUnitGridConfiguration.ProcessMode;
import edu.yu.einstein.wasp.integration.messages.WaspSoftwareJobParameters;
import edu.yu.einstein.wasp.macstwo.integration.messages.MacstwoSoftwareJobParameters;
import edu.yu.einstein.wasp.macstwo.service.MacstwoService;
import edu.yu.einstein.wasp.macstwo.software.Macstwo;
import edu.yu.einstein.wasp.model.FileGroup;
import edu.yu.einstein.wasp.model.FileGroupMeta;
import edu.yu.einstein.wasp.model.FileHandle;
import edu.yu.einstein.wasp.model.FileType;
import edu.yu.einstein.wasp.model.Job;
import edu.yu.einstein.wasp.model.Run;
import edu.yu.einstein.wasp.model.RunMeta;
import edu.yu.einstein.wasp.model.Sample;
import edu.yu.einstein.wasp.model.SampleMeta;
import edu.yu.einstein.wasp.model.SampleSource;
import edu.yu.einstein.wasp.model.Software;
import edu.yu.einstein.wasp.plugin.mps.grid.software.Imagemagick;
import edu.yu.einstein.wasp.plugin.mps.grid.software.R;
import edu.yu.einstein.wasp.plugin.supplemental.organism.Build;
import edu.yu.einstein.wasp.service.FileService;
import edu.yu.einstein.wasp.service.GenomeService;
import edu.yu.einstein.wasp.service.JobService;
import edu.yu.einstein.wasp.service.RunService;
import edu.yu.einstein.wasp.service.SampleService;

public class MacstwoTaskletModel extends WaspRemotingTasklet implements StepExecutionListener {

	private String jobIdAsString = "";
	private Integer jobId = null;
	private Job job = null;	
	private String prefixForFileName = "";
	private String macs2AnalysisFileGroupIdAsString = "";
	private String workingDirectory = "";
	private String resultsDirectory = "";
	private Integer macs2AnalysisFileGroupId = null;
	
	private String commandLineCall;	
	private String softwareIdUsedListAsString;
	
	private StepExecution stepExecution;
	
	@Autowired
	private FileType textFileType;//here, the model.r script output file
	@Autowired
	private FileType pdfFileType;//output pdf file after running the model.r script
	@Autowired
	private FileType pngFileType;//output after imagemagik on the pdf file
	
	@Autowired
	private JobService jobService;
	
	@Autowired
	private FileService fileService;

	@Autowired
	private GridHostResolver gridHostResolver;
	
	@Autowired
	private Macstwo macs2;
	
	@Autowired
	private MacstwoService macstwoService;

	public MacstwoTaskletModel() {
		// proxy
	}

	/**
	 * 
	 * @param contrib
	 * @param context
	 * @return
	 * @throws Exception
	 */
	@Transactional("entityManager")
	@Override
	public GridResult doExecute(ChunkContext context) throws Exception {
		
		logger.debug("Starting MacstwoTaskletModel execute");
		
		JobExecution jobExecution = this.stepExecution.getJobExecution();
		ExecutionContext executionContext = jobExecution.getExecutionContext();
				
		if(executionContext.containsKey(MacstwoService.JOB_ID_AS_STRING)){
			this.jobIdAsString = (String) executionContext.get(MacstwoService.JOB_ID_AS_STRING);
			this.jobId = Integer.parseInt(jobIdAsString);
			this.job = jobService.getJobByJobId(jobId);
		}
		if(executionContext.containsKey(MacstwoService.PREFIX_FOR_FILE_NAME)){
			prefixForFileName = (String) executionContext.get(MacstwoService.PREFIX_FOR_FILE_NAME);
			prefixForFileName = fileService.getSanitizedName(prefixForFileName);
		}		
		if(executionContext.containsKey(MacstwoService.MACSTWO_ANALYSIS_FILEGROUP_ID_AS_STRING)){
{'fraction_non_alphanumeric': 0.09816079873883342, 'fraction_numerical': 0.0006305832895428271, 'mean_word_length': 6.017699115044247, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5715927', 'n_tokens_mistral': 3272, 'n_tokens_neox': 3032, 'n_words': 488}