Skip to content

Wrapped priority Picard tools (#122) and added program record to Filter PIP-seq output (#144) #187

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
16 changes: 1 addition & 15 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@
<attribute name="gradle_used_by_scope" value="main,test"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/java">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/test" path="src/test/resources">
<attributes>
<attribute name="gradle_scope" value="test"/>
<attribute name="gradle_used_by_scope" value="test"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="bin/main" path="src/main/java">
<attributes>
<attribute name="gradle_scope" value="main"/>
Expand All @@ -29,4 +15,4 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
</classpath>
11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,15 @@
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1731979070369</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
13 changes: 12 additions & 1 deletion .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
arguments=--init-script /var/folders/vs/qy0cxq3x47v2gjsbgwxmt14r0000gn/T/db3b08fc4a9ef609cb16b96b200fa13e563f396e9bb1ed0905fdab7bc3bc513b.gradle --init-script /var/folders/vs/qy0cxq3x47v2gjsbgwxmt14r0000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/jdk-22.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
show.console.view=true
show.executions.view=true
32 changes: 32 additions & 0 deletions src/main/java/scriptmanager/main/ScriptManagerGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ public void run() {
// CrossCorrelation
pnlStat.add(initializeToolPanel("Cross Correlation", ToolDescriptions.archtex_crosscorrelation_description,
Class.forName("scriptmanager.window_interface.BAM_Statistics.CrossCorrelationWindow")));

// CollectBaseDistributionByCycle
pnlStat.add(initializeToolPanel("Collect BAM Distribution", ToolDescriptions.collect_base_distribution_by_cycle_description,
Class.forName("scriptmanager.window_interface.BAM_Statistics.CollectBaseDistributionByCycleWindow")));

// ======== BAM_Manipulation ========
JPanel pnlBamManip = new JPanel();
Expand All @@ -138,6 +142,26 @@ public void run() {
// FilterPIPseq
pnlBamManip.add(initializeToolPanel("Filter for PIP-seq", ToolDescriptions.filter_pip_seq_description,
Class.forName("scriptmanager.window_interface.BAM_Manipulation.FilterforPIPseqWindow")));

// DownsampleSAM
pnlBamManip.add(initializeToolPanel("Downsample SAM/BAM", ToolDescriptions.downsample_sam_description,
Class.forName("scriptmanager.window_interface.BAM_Manipulation.DownsampleSamWindow")));

// ValidateSAMFile
pnlBamManip.add(initializeToolPanel("Validate SAM/BAM", ToolDescriptions.validate_sam_file_description,
Class.forName("scriptmanager.window_interface.BAM_Manipulation.ValidateSamWindow")));

// NormalizeFasta
pnlBamManip.add(initializeToolPanel("Normalize FASTA File", ToolDescriptions.normalize_fasta_description,
Class.forName("scriptmanager.window_interface.BAM_Manipulation.NormalizeFastaWindow")));

// FilterSAMReads
pnlBamManip.add(initializeToolPanel("Filter BAM Reads", ToolDescriptions.filter_sam_reads_description,
Class.forName("scriptmanager.window_interface.BAM_Manipulation.FilterSamReadsWindow")));

// FilterSAMReads
pnlBamManip.add(initializeToolPanel("Add Comments to BAM", ToolDescriptions.add_comments_to_bam_description,
Class.forName("scriptmanager.window_interface.BAM_Manipulation.AddCommentsToBamWindow")));

// ======== BAM_Format_Converter ========
JPanel pnlBamConvert = new JPanel();
Expand All @@ -160,6 +184,14 @@ public void run() {
pnlBamConvert.add(initializeToolPanel("BAM to bedGraph", ToolDescriptions.bam_to_bedgraph_description,
Class.forName("scriptmanager.window_interface.BAM_Format_Converter.BAMtobedGraphWindow")));

// SAMtoFASTQ
pnlBamConvert.add(initializeToolPanel("BAM to FASTQ", ToolDescriptions.sam_to_fastq_description,
Class.forName("scriptmanager.window_interface.BAM_Format_Converter.SamtoFastqWindow")));

// SAMFormatConverter
pnlBamConvert.add(initializeToolPanel("SAM to BAM or BAM to SAM", ToolDescriptions.sam_to_fastq_description,
Class.forName("scriptmanager.window_interface.BAM_Format_Converter.SamFormatConverterWindow")));

// ======== File_Utilities ========
JPanel pnlFileUtility = new JPanel();
BoxLayout bl_pnlFileUtility = new BoxLayout(pnlFileUtility, BoxLayout.PAGE_AXIS);
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/scriptmanager/objects/ToolDescriptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class ToolDescriptions {
public static final String se_stat_description = "Output BAM Header including alignment statistics and parameters given any indexed (BAI) BAM File.";
public static final String pe_stat_description = "Generates Insert-size Histogram statistics (GEO requirement) and outputs BAM Header including alignment statistics and parameters given a sorted and indexed (BAI) paired-end BAM File.";
public static final String bam_correlation_description = "Genome-Genome correlations for replicate comparisons given multiple sorted and indexed (BAI) BAM files.";
public static final String collect_base_distribution_by_cycle_description = "Chart the nucleotide distribution per cycle in a BAM file";
public static final String archtex_crosscorrelation_description = ("Calculate optimal tag shift based on ArchTEx implementation (PMID:22302569)");

// BAM Manipulation
Expand All @@ -41,12 +42,19 @@ public class ToolDescriptions {
public static final String remove_duplicates_description = "Removes duplicate reads in Paired-End sequencing given identical 5' read locations. RAM intensive process. If program freezes, increase JAVA heap size."; //*
public static final String merge_bam_description = "Merges Multiple BAM files into single BAM file. Sorting is performed automatically. RAM intensive process. If program freezes, increase JAVA heap size."; //*
public static final String filter_pip_seq_description = "Filter BAM file by -1 nucleotide. Requires genome FASTA file.";
public static final String downsample_sam_description = "Downsample a BAM file to a specified percentage or read count of deterministically random reads.";
public static final String validate_sam_file_description = "Validate SAM/BAM files comprehensively, ensuring adherence to the SAM format specification and detecting errors or inconsistencies in alignment data.";
public static final String normalize_fasta_description = "Reduce redundant sequences and normalize read coverage in a FASTA file, improving downstream analysis accuracy";
public static final String filter_sam_reads_description = "Filter BAM files by applying user-defined filters to include or exclude specific reads based on read lists or genomic intervals";
public static final String add_comments_to_bam_description = "Adds comments to the header of a BAM file.";

// BAM Format Converter
public static final String bam_to_scidx_description = "Convert BAM file to scIDX file.";
public static final String bam_to_gff_description = "Convert BAM file to GFF file.";
public static final String bam_to_bed_description = "Convert BAM file to BED file.";
public static final String bam_to_bedgraph_description = "Convert BAM file to bedGraph file.";
public static final String sam_to_fastq_description = "Convert BAM file to FASTQ file";
public static final String sam_format_converter_description = "Convert SAM file to Bam file or Bam file to Sam file";

// File Utilities
public static final String md5checksum_description = "Calculate MD5 checksum for files.";
Expand Down Expand Up @@ -85,7 +93,6 @@ public class ToolDescriptions {
public static final String aggregate_data_description = "Compile data from tab-delimited file into matrix according to user-specified metric.";
public static final String transpose_matrix_description = "Interchange the rows and columns of tab-delimited matrix data.";


// Sequence Analysis
public static final String fasta_extract_description = "Generate FASTA file from indexed Genome FASTA file and BED file. Script will generate FAI index if not present in Genome FASTA folder.";
public static final String randomize_fasta_description = "Randomize FASTA sequence for each input entry.";
Expand All @@ -101,4 +108,6 @@ public class ToolDescriptions {
public static final String composite_description = "Generate a Composite Plot PNG from composite data like the output in TagPileup";
public static final String label_heatmap_description = "Create an SVG label for heatmap inputs";

// Whether or not to log legacy Picard commands
public static final boolean picard_legacy_commends = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package scriptmanager.scripts.BAM_Format_Converter;
import htsjdk.samtools.SAMException;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import org.broadinstitute.barclay.argparser.CommandLineParser;

/**
* @author Erik Pavloski
* @see scriptmanager.window_interface.BAM_Format_Converter.SamFormatConverterWindow
* This code runs the Picard tool SamFormatConverter
* It can swap a SAM file to a BAM file and vice versa
*/

public class SamFormatConverterWrapper {
/**
* @param input the BAM/SAM file to be converted
* @param output the output BAM/SAM file
*
* @throws IOException
* @throws SAMException
*/
public static void run(File input, File output) throws IOException, SAMException {
System.out.println("Converting file...");
// Converts the SAM/BAM file to fastq
final picard.sam.SamFormatConverter samFormatConverter = new picard.sam.SamFormatConverter();
final ArrayList<String> args = new ArrayList<>();
args.add("INPUT=" + input.getAbsolutePath());
args.add("OUTPUT=" + output.getAbsolutePath());
samFormatConverter.instanceMain(args.toArray(new String[args.size()]));
System.out.println("File converted");
}

/**
* Reconstruct CLI command
*
* @param input the BAM/SAM file to be converted
* @param output the output BAM/SAM file
*/
public static String getCLIcommand(File input, File output) {
String command = "java -jar $PICARD ";
final CommandLineParser parser = new picard.sam.SamFormatConverter().getCommandLineParser();
final ArrayList<String> args = new ArrayList<>();
args.add("INPUT=" + input.getAbsolutePath());
args.add("OUTPUT=" + output.getAbsolutePath());
String[] argv = args.toArray(new String[args.size()]);
parser.parseArguments(System.err, argv);
command += parser.getCommandLine();
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package scriptmanager.scripts.BAM_Format_Converter;
import htsjdk.samtools.SAMException;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

import org.broadinstitute.barclay.argparser.CommandLineParser;

/**
* @author Erik Pavloski
* @see scriptmanager.window_interface.BAM_Format_Converter.SamtoFastqWindow
* This code runs the Picard tool SamtoFastq
*/

public class SamtoFastqWrapper {
/**
* @param input the BAM/SAM file to be converted
* @param output the output fastq file
* @param compress a boolean to determine whether to compress the output or not
* default = false = do not compress
* @param perRG a boolean to determine whether to output per read group. Compress does this as well
* @param outputDir the output directory
* @throws IOException
* @throws SAMException
*/
public static void run(File input, File output, boolean compress, boolean perRG, File outputDir) throws IOException, SAMException {

System.out.println("Converting file...");
// Converts the SAM/BAM file to fastq
final picard.sam.SamToFastq samToFastq = new picard.sam.SamToFastq();
final ArrayList<String> args = new ArrayList<>();
args.add("INPUT=" + input.getAbsolutePath());
if (compress) {
args.add("OUTPUT_DIR=" + outputDir.getCanonicalPath());
args.add("COMPRESS_OUTPUTS_PER_RG=" + true);
} else if (perRG) {
args.add("OUTPUT_DIR=" + outputDir.getCanonicalPath());
args.add("OUTPUT_PER_RG=" + true);
} else {
args.add("FASTQ=" + output.getAbsolutePath());
}
samToFastq.instanceMain(args.toArray(new String[args.size()]));
System.out.println("File converted");
}

/**
* Reconstruct CLI command
*
* @param input the BAM/SAM file to be converted
* @param output the output fastq file
* @param compress a boolean to determine whether to compress the output or not
* default = false = do not compress
* @param perRG a boolean to determine whether to output per read group. Compress does this as well
* @param outputDir the output directory
* @throws IOException
*/
public static String getCLIcommand(File input, File output, boolean compress, boolean perRG, File outputDir) throws IOException {
String command = "java -jar $PICARD ";
final CommandLineParser parser = new picard.sam.SamToFastq().getCommandLineParser();
final ArrayList<String> args = new ArrayList<>();
args.add("INPUT=" + input.getAbsolutePath());
if (compress) {
args.add("OUTPUT_DIR=" + outputDir.getCanonicalPath());
args.add("COMPRESS_OUTPUTS_PER_RG=" + true);
} else if (perRG) {
args.add("OUTPUT_DIR=" + outputDir.getCanonicalPath());
args.add("OUTPUT_PER_RG=" + true);
} else {
args.add("FASTQ=" + output.getAbsolutePath());
}
String[] argv = args.toArray(new String[args.size()]);
parser.parseArguments(System.err, argv);
command += parser.getCommandLine();
return command;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package scriptmanager.scripts.BAM_Manipulation;

import htsjdk.samtools.BamFileIoUtils;
import htsjdk.samtools.SAMException;
import htsjdk.samtools.SAMProgramRecord;
import htsjdk.samtools.SamReader;
import htsjdk.samtools.SamReaderFactory;
import picard.cmdline.CommandLineSyntaxTranslater;
import picard.sam.AddCommentsToBam;
import scriptmanager.objects.ToolDescriptions;
import scriptmanager.util.BAMUtilities;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Files;
import java.util.ArrayList;

import org.broadinstitute.barclay.argparser.CommandLineParser;

/**
* @author Erik Pavloski
* This is the Wrapper class for the AddCommentsToBam Picard tool
* @see scriptmanager.window_interface.BAM_Manipulation.AddCommentsToBamWindow
*/
public class AddCommentsToBamWrapper {
/**
* @param input the bam file to add comments to
* @param output the output file
*
* @throws IOException
* @throws SAMException
*/
public static void run(File input, File output, ArrayList<String> comments) throws IOException, SAMException {
System.out.println("Add Comments To Bam");

final picard.sam.AddCommentsToBam addComments = new picard.sam.AddCommentsToBam();
final ArrayList<String> args = new ArrayList<>();
args.add("INPUT=" + input.getAbsolutePath());
args.add("OUTPUT=" + output.getAbsolutePath());
for (String c: comments){
args.add("C=" + c);
}
addComments.instanceMain(args.toArray(new String[args.size()]));

// Copy output
File temp = new File(output.toPath() + "copy");
Files.copy(output.toPath(), new PrintStream(temp));
// Create and add new record
SamReader reader = SamReaderFactory.makeDefault().open(temp);
String command = AddCommentsToBamWrapper.getCLIcommand(input, output, comments);
SAMProgramRecord newRecord = BAMUtilities.getPGRecord(reader.getFileHeader(), addComments.getClass().getSimpleName(), command, addComments.getVersion());
reader.getFileHeader().addProgramRecord(newRecord);
BamFileIoUtils.reheaderBamFile(reader.getFileHeader(), temp, output, false, false);
// Delete copy
temp.delete();
System.out.println("SAM/BAM file downsampled");

System.out.println("Comments Added");
}

/**
* Reconstruct CLI command
*
* @param input the bam file to add comments to
* @param output the output file
*/
public static String getCLIcommand(File input, File output, ArrayList<String> comments) {
String command = "java -jar $PICARD ";
final CommandLineParser parser = new picard.sam.AddCommentsToBam().getCommandLineParser();
final ArrayList<String> args = new ArrayList<>();
args.add("INPUT=" + input.getAbsolutePath());
args.add("OUTPUT=" + output.getAbsolutePath());
for (String c: comments){
args.add("C=" + c);
}
String[] argv = args.toArray(new String[args.size()]);
parser.parseArguments(System.err, argv);
command += parser.getCommandLine();
return command;
}
}
Loading