Skip to content

Commit 06ebe31

Browse files
author
Judith Neukamm
authored
Merge pull request #30 from Integrative-Transcriptomics/dev
Dev
2 parents 038a2f0 + 9a1501b commit 06ebe31

11 files changed

+200
-51
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group 'com.uni-tuebingen.de.it.eager.damageprofiler'
2-
version '0.4.6'
2+
version '0.4.7'
33

44
buildscript {
55
repositories {

src/main/java/GUI/MainGuiFX.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private void addListener() {
143143
communicator.setSpecies_ref_identifier(textfield_specie.getText());
144144
if(!checkbox_dynamic_y_axis_height.isSelected()){
145145
try {
146-
communicator.setyAxis(Double.parseDouble(textfield_y_axis_height.getText()));
146+
communicator.setyAxis_damageplot(Double.parseDouble(textfield_y_axis_height.getText()));
147147
} catch (Exception ex){
148148
System.out.println("Height value not valid.");
149149
}

src/main/java/IO/Communicator.java

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ public class Communicator {
1414
// damage calculation
1515
private int threshold = 25;
1616

17-
private double yAxis;
17+
private double yAxis_damageplot;
18+
private double xaxis_histo_id_min =-1;
19+
private double xaxis_histo_id_max =-1;
20+
private double xaxis_histo_length_min=-1;
21+
private double xaxis_histo_length_max=-1;
1822
private int length = 100;
1923
private boolean use_merged_and_mapped_reads = false;
2024
private boolean use_all_reads = false;
@@ -95,12 +99,12 @@ public void setUse_all_reads(boolean use_all_reads) {
9599
this.use_all_reads = use_all_reads;
96100
}
97101

98-
public void setyAxis(double yAxis) {
99-
this.yAxis = yAxis;
102+
public void setyAxis_damageplot(double yAxis_damageplot) {
103+
this.yAxis_damageplot = yAxis_damageplot;
100104
}
101105

102-
public double getyAxis() {
103-
return yAxis;
106+
public double getyAxis_damageplot() {
107+
return yAxis_damageplot;
104108
}
105109

106110
public String getTitle_plots() {
@@ -120,5 +124,35 @@ public void setSpecieslist_filepath(String specieslist_filepath) {
120124
}
121125

122126

127+
public double getXaxis_histo_id_min() {
128+
return xaxis_histo_id_min;
129+
}
130+
131+
public void setXaxis_histo_id_min(double xaxis_histo_id_min) {
132+
this.xaxis_histo_id_min = xaxis_histo_id_min;
133+
}
134+
135+
public double getXaxis_histo_id_max() {
136+
return xaxis_histo_id_max;
137+
}
138+
139+
public void setXaxis_histo_id_max(double xaxis_histo_id_max) {
140+
this.xaxis_histo_id_max = xaxis_histo_id_max;
141+
}
123142

143+
public double getXaxis_histo_length_min() {
144+
return xaxis_histo_length_min;
145+
}
146+
147+
public void setXaxis_histo_length_min(double xaxis_histo_length_min) {
148+
this.xaxis_histo_length_min = xaxis_histo_length_min;
149+
}
150+
151+
public double getXaxis_histo_length_max() {
152+
return xaxis_histo_length_max;
153+
}
154+
155+
public void setXaxis_histo_length_max(double xaxis_histo_length_max) {
156+
this.xaxis_histo_length_max = xaxis_histo_length_max;
157+
}
124158
}

src/main/java/IO/Histogram.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.apache.log4j.Logger;
44
import org.jfree.chart.ChartFactory;
55
import org.jfree.chart.JFreeChart;
6+
import org.jfree.chart.axis.ValueAxis;
67
import org.jfree.chart.plot.PlotOrientation;
78
import org.jfree.chart.plot.XYPlot;
89
import org.jfree.chart.renderer.xy.StandardXYBarPainter;
@@ -56,7 +57,8 @@ public HistogramDataset createDataset(String[] title, int max){
5657
}
5758

5859

59-
public JFreeChart createChart(HistogramDataset dataset, String title, String xlab, String ylab){
60+
public JFreeChart createChart(HistogramDataset dataset, String title, String xlab, String ylab,
61+
double xmin, double xmax){
6062

6163
JFreeChart chart = ChartFactory.createHistogram(
6264
title,//"Histogram read length",
@@ -76,6 +78,16 @@ public JFreeChart createChart(HistogramDataset dataset, String title, String xla
7678
xyplot.setDomainGridlinePaint(new Color(150,150,150));
7779
xyplot.setRangeGridlinePaint(new Color(150,150,150));
7880

81+
if(xmin > -1){
82+
ValueAxis axis = xyplot.getDomainAxis();
83+
axis.setLowerBound(xmin);
84+
}
85+
86+
if(xmax > -1){
87+
ValueAxis axis = xyplot.getDomainAxis();
88+
axis.setUpperBound(xmax);
89+
}
90+
7991
XYBarRenderer xybarrenderer = (XYBarRenderer)xyplot.getRenderer();
8092
xybarrenderer.setShadowVisible(false);
8193
xybarrenderer.setBarPainter(new StandardXYBarPainter());

src/main/java/IO/OutputGenerator.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
*/
3434
public class OutputGenerator {
3535

36+
private final double x_axis_min_id_histo;
37+
private final double x_axis_max_id_histo;
38+
private final double x_axis_min_length_histo;
39+
private final double x_axis_max_length_histo;
3640
private int numberOfUsedReads;
3741
private final double height;
3842
private final Logger LOG;
@@ -50,7 +54,8 @@ public class OutputGenerator {
5054

5155

5256
public OutputGenerator(String outputFolder, DamageProfiler damageProfiler, String specie, int threshold,
53-
int length, double height, String input, Logger LOG) {
57+
int length, double height, double x_axis_min_id_histo, double x_axis_max_id_histo,
58+
double x_axis_min_length_histo, double x_axis_max_length_histo, String input, Logger LOG) {
5459

5560
this.outpath = outputFolder;
5661
this.frequencies = damageProfiler.getFrequencies();
@@ -59,6 +64,10 @@ public OutputGenerator(String outputFolder, DamageProfiler damageProfiler, Strin
5964
this.threshold = threshold;
6065
this.length = length;
6166
this.height = height;
67+
this.x_axis_min_id_histo = x_axis_min_id_histo;
68+
this.x_axis_max_id_histo = x_axis_max_id_histo;
69+
this.x_axis_min_length_histo = x_axis_min_length_histo;
70+
this.x_axis_max_length_histo = x_axis_max_length_histo;
6271
this.input = input;
6372
this.LOG = LOG;
6473

@@ -425,7 +434,8 @@ public void plotLengthHistogram(List<Double> length_all, List<Double> length_for
425434
Histogram hist_all = new Histogram(LOG);
426435
hist_all.addData(length_all);
427436
HistogramDataset dataset_all = hist_all.createDataset(new String[]{"all reads"}, max_length);
428-
JFreeChart chart_all = hist_all.createChart(dataset_all, "Read length distribution", "Read length", "Occurrences");
437+
JFreeChart chart_all = hist_all.createChart(dataset_all, "Read length distribution", "Read length",
438+
"Occurrences", x_axis_min_length_histo, x_axis_max_length_histo);
429439

430440
Histogram hist_separated = new Histogram(LOG);
431441
if(length_forward.size()>0){
@@ -435,7 +445,8 @@ public void plotLengthHistogram(List<Double> length_all, List<Double> length_for
435445
hist_separated.addData(length_reverse);
436446
}
437447
HistogramDataset dataset_separated = hist_separated.createDataset(new String[]{"+ strand", "- strand"}, max_length);
438-
JFreeChart chart_separated = hist_separated.createChart(dataset_separated, "Read length distribution", "Read length", "Occurrences");
448+
JFreeChart chart_separated = hist_separated.createChart(dataset_separated, "Read length distribution",
449+
"Read length", "Occurrences", x_axis_min_length_histo, x_axis_max_length_histo);
439450

440451
createPdf("/Length_plot.pdf", new JFreeChart[]{chart_all, chart_separated}, file);
441452

@@ -455,7 +466,8 @@ public void plotIdentitiyHistogram(ArrayList distances, String title, String fil
455466
Histogram hist_all = new Histogram(LOG);
456467
hist_all.addData(distances);
457468
HistogramDataset dataset = hist_all.createDataset(new String[]{title}, 100);
458-
JFreeChart chart_all = hist_all.createChart(dataset, "Read identity distribution", "Identity", "Occurrences");
469+
JFreeChart chart_all = hist_all.createChart(dataset, "Read identity distribution", "Identity", "Occurrences",
470+
x_axis_min_id_histo, x_axis_max_id_histo);
459471
createPdf("/identity_histogram.pdf", new JFreeChart[]{chart_all}, file);
460472

461473
}

src/main/java/IO/SpeciesListParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public SpeciesListParser(String speciesListFile, Logger LOG) {
2424
}
2525

2626

27-
public String getSingleSpecie(String rname) throws IOException {
27+
public String getSingleSpecie(String rname) {
2828

2929
specieHandler.getSpecie(rname);
3030
return specieHandler.getSpecie_name();

src/main/java/IO/UserOptionsParser.java

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,35 @@ private void parse(){
6969
.hasArg()
7070
.create("title"));
7171

72-
options.addOption(OptionBuilder.withLongOpt("yaxis")
73-
.withArgName("YAXIS")
74-
.withDescription("Maximal value on y axis.")
72+
options.addOption(OptionBuilder.withLongOpt("yaxis_damageplot")
73+
.withArgName("YAXIS_DAMAGEPLOT")
74+
.withDescription("Maximal value on y axis of damage plot.")
7575
.hasArg()
76-
.create("yaxis"));
76+
.create("yaxis_damageplot"));
7777

78+
options.addOption(OptionBuilder.withLongOpt("xaxis_histo_id_min")
79+
.withArgName("XAXIS_HISTO_ID_MIN")
80+
.withDescription("Minimal value x-axis of identity histogram.")
81+
.hasArg()
82+
.create("xaxis_histo_id_min"));
83+
84+
options.addOption(OptionBuilder.withLongOpt("xaxis_histo_id_max")
85+
.withArgName("XAXIS_HISTO_ID_MAX")
86+
.withDescription("Maximal value x-axis of identity histogram.")
87+
.hasArg()
88+
.create("xaxis_histo_id_max"));
89+
90+
options.addOption(OptionBuilder.withLongOpt("xaxis_histo_length_min")
91+
.withArgName("XAXIS_HISTO_LENGTH_MIN")
92+
.withDescription("Minimal value x-axis of length histogram.")
93+
.hasArg()
94+
.create("xaxis_histo_length_min"));
95+
96+
options.addOption(OptionBuilder.withLongOpt("xaxis_histo_length_max")
97+
.withArgName("XAXIS_HISTO_LENGTH_MAX")
98+
.withDescription("Maximal value x-axis of length histogram.")
99+
.hasArg()
100+
.create("xaxis_histo_length_max"));
78101

79102
Option mapped_and_merged = new Option("merged", "all_mapped_and_merged_reads", false,
80103
"Use all mapped and merged reads to calculate damage plot instead of using all mapped reads. The SAM/BAM entry must start with 'M_', otherwise " +
@@ -144,10 +167,29 @@ private void parse(){
144167
communicator.setTitle_plots(cmd.getOptionValue("title"));
145168
}
146169

147-
if(cmd.hasOption("yaxis")) {
148-
communicator.setyAxis(Double.parseDouble(cmd.getOptionValue("yaxis")));
170+
if(cmd.hasOption("yaxis_damageplot")) {
171+
communicator.setyAxis_damageplot(Double.parseDouble(cmd.getOptionValue("yaxis_damageplot")));
172+
}
173+
174+
if(cmd.hasOption("xaxis_histo_id_min")) {
175+
communicator.setXaxis_histo_id_min(Double.parseDouble(cmd.getOptionValue("xaxis_histo_id_min")));
149176
}
150177

178+
179+
if(cmd.hasOption("xaxis_histo_id_max")) {
180+
communicator.setXaxis_histo_id_max(Double.parseDouble(cmd.getOptionValue("xaxis_histo_id_max")));
181+
}
182+
183+
if(cmd.hasOption("xaxis_histo_length_min")) {
184+
communicator.setXaxis_histo_length_min(Double.parseDouble(cmd.getOptionValue("xaxis_histo_length_min")));
185+
}
186+
187+
188+
if(cmd.hasOption("xaxis_histo_length_max")) {
189+
communicator.setXaxis_histo_length_max(Double.parseDouble(cmd.getOptionValue("xaxis_histo_length_max")));
190+
}
191+
192+
151193
if (cmd.hasOption('t')) {
152194
communicator.setThreshold(Integer.parseInt(cmd.getOptionValue('t')));
153195
}

src/main/java/RunDamageProfiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
public class RunDamageProfiler {
1010

11-
private static final String VERSION = "0.4.6";
11+
private static final String VERSION = "0.4.7";
1212

1313

1414
@SuppressWarnings("static-access")

src/main/java/calculations/DamageProfiler.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,17 @@ private void processRecord(SAMRecord record) throws Exception{
214214
} else if(record.getStringAttribute(SAMTag.MD.name()) != null){
215215
// get reference corresponding to the record
216216
if(record.getCigar().getReadLength() != 0 && record.getCigar().getReadLength() == record.getReadLength()){
217-
217+
// if(record.getCigarString().contains("S")){
218+
// System.out.println("Cigar contains soft clipping");
219+
// } else if(record.getCigarString().contains("D")){
220+
// System.out.println("Cigar contains deletion");
221+
// } else {
218222
byte[] ref_seq = SequenceUtil.makeReferenceFromAlignment(record, false);
219223
reference_aligned = new String(ref_seq, "UTF-8");
220224
record_aligned = record.getReadString();
225+
// }
226+
227+
221228

222229
} else {
223230
LOG.info("Skipped record (length does not match): " + record.getReadName());
@@ -282,7 +289,7 @@ public int getNumberOfAllReads() {
282289
}
283290
public ArrayList<Double> getIdentity() { return identity; }
284291

285-
public String getSpeciesname(File file, String ref) throws IOException {
292+
public String getSpeciesname(File file, String ref) {
286293

287294
SamReader input = SamReaderFactory.make().enable(SamReaderFactory.Option.DONT_MEMORY_MAP_INDEX).
288295
validationStringency(ValidationStringency.LENIENT).open(file);

src/main/java/calculations/SpecieHandler.java

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package calculations;
22

33
import java.io.*;
4+
import java.util.Random;
45

56
import IO.DOMParser;
67
import org.apache.log4j.Logger;
@@ -19,7 +20,7 @@ public SpecieHandler(){
1920
}
2021

2122

22-
public void getSpecie(String rname) throws IOException{
23+
public void getSpecie(String rname){
2324
if (rname != null) {
2425
String tax = "";
2526

@@ -62,28 +63,39 @@ public void getSpecie(String rname) throws IOException{
6263
* @return species name as string
6364
* @throws IOException
6465
*/
65-
private String getSpeciesByID(int id) throws IOException {
66-
String species;
66+
private String getSpeciesByID(int id) {
67+
String species="";
68+
Random rand = new Random();
69+
70+
// Obtain a number between [0 - 1000].
71+
int n = rand.nextInt(1000);
6772

6873
// run command line call to get XML file from
6974
// ncbi with information about the ncbiID of our species
70-
Runtime rt = Runtime.getRuntime();
71-
Process proc = rt.exec("curl https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=taxonomy&amp;id=" + id);
7275

73-
BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
74-
BufferedWriter xmlOutput = new BufferedWriter(new FileWriter("ncbiID.xml"));
76+
// try to call 'curl'. If not possible, do not set species name but only ID
77+
try {
78+
Runtime rt = Runtime.getRuntime();
79+
Process proc = rt.exec("curl https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esummary.fcgi?db=taxonomy&amp;id=" + id);
80+
81+
BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
82+
BufferedWriter xmlOutput = new BufferedWriter(new FileWriter("ncbiID" + n + ".xml"));
7583

76-
// read the output from the command and write it in xml file
77-
String s = null;
78-
while ((s = stdInput.readLine()) != null) {
79-
xmlOutput.write(s);
84+
// read the output from the command and write it in xml file
85+
String s = null;
86+
while ((s = stdInput.readLine()) != null) {
87+
xmlOutput.write(s);
88+
}
89+
xmlOutput.close();
90+
91+
DOMParser domparser = new DOMParser(LOG);
92+
species = domparser.parse("ncbiID" + n + ".xml");
93+
File f = new File("ncbiID" + n + ".xml");
94+
f.delete();
95+
} catch (Exception e){
96+
System.out.println("'Curl' is not installed. If you would like to use this option, please install it.");
8097
}
81-
xmlOutput.close();
8298

83-
DOMParser domparser = new DOMParser(LOG);
84-
species = domparser.parse("ncbiID.xml");
85-
File f = new File("ncbiID.xml");
86-
f.delete();
8799

88100

89101
return species;

0 commit comments

Comments
 (0)