Skip to content

Commit 899f147

Browse files
authored
Merge pull request #22 from apeltzer/master
V0.4.3
2 parents 34ececa + 35fdbcc commit 899f147

File tree

5 files changed

+83
-38
lines changed

5 files changed

+83
-38
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ jdk:
44
- oraclejdk8
55
script: gradle build
66
env:
7-
- version=0.4.2
7+
- version=0.4.3
88
deploy:
99
provider: releases
1010
api_key:
1111
secure: uw5/0KF8F/Hve8WgCy45AsKxjUl9rYMJzjMLk6SI4BRvJcxFfJqOtE/NRzdn1AJhKlYfJF72fLenf1VI0DCAsJom1o9q68xKtxNXPVvHgjKhfQjX5VLwO2lIK/L5EwFRirtp+Ey1Fi/O3Tqxxg7MR4NSHKoYlZZ4g5L0d5cKObPOup4T8UU7enTBVA+RhlpHPD2T/TwjSzA2eHc7sU+C53WVJyW9aAKY6fIJS0dk6/WdpFNMns1fKBM/rvVXz5XGCmTy8TS9U2vR4de3gbrCrLhvXWVvg4kA2GDa6xEnPBnVqnVf1UHnZHt6vqv4r0MzIVaIgynd+NkqpLszH8/+tY50nHV9dC5Z6O4KC2eVqi0nthBYJxhRti9R9fwCV9/TyPE6ThBGa53CiIAaDTrAHIsIWL7EUXIU+EiOAZiYEgc2CWBBvVqIrUuuLXCU1XTZLpt3klamelsx7pUlCpj6QlUl1QeF1c4KZBteUGi5Y7xlssdBMZ0uQjYqYLwsQ0aySMw0TQl8nPcxR/95NKcGQt1uadskbLhpGb+8519UmrGOEuVIToN+XvLkosmajSzbTnlKiPVTE9K/j5tLy1/Q68VYkVcJjccVUmNPKyF+8sI5F9F6oRUY1LXPd6sm4h69T8RPKS43MyECa9lOQixOl+9XXhDpOmXFm1VNBm4akWA=
12-
file: build/libs/DamageProfiler-0.4.2.jar
12+
file: build/libs/DamageProfiler-0.4.3.jar
1313
skip_cleanup: true
1414
on:
1515
all_branches: true

build.gradle

Lines changed: 2 additions & 2 deletions
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.2'
2+
version '0.4.3'
33

44

55

@@ -50,7 +50,7 @@ dependencies {
5050
compile group: 'com.intellij', name: 'forms_rt', version: '6.0.+'
5151
compile group: 'log4j', name: 'log4j', version: '1.+'
5252
compile group: 'com.github.broadinstitute', name: 'picard', version: '2.+'
53-
compile 'org.yaml:snakeyaml:1.2+'
53+
compile 'com.google.code.gson:gson:2.8.5'
5454
}
5555

5656

src/main/java/IO/OutputGenerator.java

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@
22

33
import calculations.DamageProfiler;
44
import calculations.Frequencies;
5+
import com.google.gson.Gson;
56
import com.itextpdf.awt.PdfGraphics2D;
67
import com.itextpdf.text.*;
78
import com.itextpdf.text.Font;
89
import com.itextpdf.text.pdf.PdfContentByte;
910
import com.itextpdf.text.pdf.PdfTemplate;
1011
import com.itextpdf.text.pdf.PdfWriter;
12+
import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
1113
import org.apache.log4j.Logger;
1214
import org.jfree.chart.JFreeChart;
1315
import org.jfree.data.statistics.HistogramDataset;
1416
import org.jfree.data.xy.XYDataset;
15-
import org.yaml.snakeyaml.Yaml;
1617

1718

1819
import java.awt.*;
@@ -43,6 +44,7 @@ public class OutputGenerator {
4344
private int threshold;
4445
private int length;
4546
private String input;
47+
private HashMap<String,Object> json_map = new HashMap<>();
4648

4749

4850

@@ -65,6 +67,37 @@ public OutputGenerator(String outputFolder, DamageProfiler damageProfiler, Strin
6567
}
6668
}
6769

70+
/**
71+
* writes all generated output statistics to YAML output file
72+
* YAML has several key,value pairs (HashMaps) that all contain information created in DamageProfiler
73+
* sample_name = the name of the sample
74+
*
75+
*
76+
* @throws IOException
77+
*/
78+
public void writeJSON(String version) throws IOException {
79+
//Add Sample Name to yaml
80+
String sampleName = input.split("/")[input.split("/").length-1];
81+
82+
83+
//Add Metadata to JSON output
84+
HashMap<String, Object> meta_map = new HashMap<>();
85+
meta_map.put("sample_name", sampleName);
86+
meta_map.put("tool_name", "DamageProfiler");
87+
meta_map.put("version", version);
88+
89+
json_map.put("metadata", meta_map);
90+
91+
Gson gson = new Gson();
92+
93+
String json = gson.toJson(json_map);
94+
95+
FileWriter fw = new FileWriter(this.outpath + "/dmgprof.json");
96+
fw.write(json);
97+
fw.flush();
98+
fw.close();
99+
100+
}
68101

69102
/**
70103
* create tab-separated txt file with all read length, sorted according strand direction
@@ -73,12 +106,7 @@ public OutputGenerator(String outputFolder, DamageProfiler damageProfiler, Strin
73106
*/
74107
public void writeLengthDistribution() throws IOException{
75108

76-
77109
BufferedWriter lgdist = new BufferedWriter(new FileWriter(this.outpath + "/lgdistribution.txt"));
78-
Yaml lgdistyaml_fw = new Yaml();
79-
Yaml lgdistyaml_rv = new Yaml();
80-
FileWriter writer_fw = new FileWriter(this.outpath + "/lgdistribution_fw.yaml");
81-
FileWriter writer_rv = new FileWriter(this.outpath + "/lgdistribution_rv.yaml");
82110
HashMap<Integer, Integer> map_forward = damageProfiler.getLength_distribution_map_forward();
83111
HashMap<Integer, Integer> map_reverse = damageProfiler.getLength_distribution_map_reverse();
84112

@@ -94,8 +122,6 @@ public void writeLengthDistribution() throws IOException{
94122
key_list.addAll(map_forward.keySet());
95123
Collections.sort(key_list);
96124

97-
HashMap<String,HashMap> dump_fw_hm = new HashMap<>();
98-
String sampleid= input.split("/")[input.split("/").length-1];
99125
HashMap<Integer,Integer> yaml_dump_fw = new HashMap<>();
100126

101127
if(key_list.size()>0){
@@ -107,15 +133,13 @@ public void writeLengthDistribution() throws IOException{
107133
yaml_dump_fw.put(key, map_forward.get(key));
108134
}
109135
}
110-
dump_fw_hm.put(sampleid,yaml_dump_fw);
111-
lgdistyaml_fw.dump(dump_fw_hm,writer_fw);
136+
json_map.put("lendist_fw",yaml_dump_fw);
112137

113138
key_list.clear();
114139
key_list.addAll(map_reverse.keySet());
115140
Collections.sort(key_list);
116141

117142
HashMap<Integer,Integer> yaml_dump_rv = new HashMap<>();
118-
HashMap<String,HashMap> dump_rv_hm = new HashMap<>();
119143

120144

121145
if(key_list.size()>0){
@@ -133,12 +157,7 @@ public void writeLengthDistribution() throws IOException{
133157

134158
}
135159

136-
dump_rv_hm.put(sampleid,yaml_dump_rv);
137-
138-
lgdistyaml_rv.dump(dump_rv_hm,writer_rv);
139-
140-
141-
160+
json_map.put("lendist_rv", yaml_dump_rv);
142161
lgdist.close();
143162
}
144163

@@ -453,22 +472,10 @@ public void writeDamageFiles(double[] gToA_reverse, double[] cToT) throws IOExce
453472
BufferedWriter writer3Prime = new BufferedWriter(new FileWriter(this.outpath + "/3pGtoA_freq.txt"));
454473
BufferedWriter writer5Prime = new BufferedWriter(new FileWriter(this.outpath + "/5pCtoT_freq.txt"));
455474

456-
FileWriter writ3P = new FileWriter(this.outpath + "/3pGtoA_freq.yaml");
457-
FileWriter writ5p = new FileWriter(this.outpath + "/5pCtoT_freq.yaml");
475+
//Add stuff to json output file
476+
json_map.put("dmg_5p",getSubArray(cToT, this.threshold));
477+
json_map.put("dmg_3p",getSubArray(gToA_reverse,this.threshold));
458478

459-
String sampleid= input.split("/")[input.split("/").length-1];
460-
461-
Yaml yml3p = new Yaml();
462-
Yaml yml5p = new Yaml();
463-
464-
Map<String, double[]> yml3p_map = new HashMap<String,double[]>();
465-
yml3p_map.put(sampleid,getSubArray(cToT, this.threshold));
466-
yml3p.dump(yml3p_map,writ3P);
467-
468-
469-
Map<String, double[]> yml5p_map = new HashMap<String,double[]>();
470-
yml5p_map.put(sampleid,getSubArray(gToA_reverse,this.threshold));
471-
yml5p.dump(yml5p_map,writ5p);
472479

473480
writer3Prime.write("# table produced by calculations.DamageProfiler\n");
474481
writer3Prime.write("# using mapped file " + input + "\n");
@@ -502,6 +509,41 @@ private void writeDamagePattern(String title, double[] values, BufferedWriter wr
502509

503510
}
504511

512+
public void computeSummaryMetrics(){
513+
HashMap<Integer,Integer> forwardMap = damageProfiler.getLength_distribution_map_forward(); // key = length, value = occurences
514+
HashMap<Integer, Integer>reverseMap = damageProfiler.getLength_distribution_map_reverse();
515+
516+
//Create ArrayList<Integer> of read lengths
517+
DescriptiveStatistics descriptiveStatistics = new DescriptiveStatistics();
518+
519+
for (int key : forwardMap.keySet()){
520+
int occurences = forwardMap.get(key);
521+
for (int i = 0; i <= occurences; i++) {
522+
descriptiveStatistics.addValue(key);
523+
}
524+
}
525+
526+
for (int key : reverseMap.keySet()){
527+
int occurences = reverseMap.get(key);
528+
for (int i = 0; i <= occurences; i++) {
529+
descriptiveStatistics.addValue(key);
530+
}
531+
}
532+
533+
double mean = descriptiveStatistics.getMean();
534+
double std = descriptiveStatistics.getStandardDeviation();
535+
double median = descriptiveStatistics.getPercentile(50);
536+
537+
HashMap<String, Double> summ_stats = new HashMap<>();
538+
539+
summ_stats.put("mean_readlength", mean);
540+
summ_stats.put("std", std);
541+
summ_stats.put("median", std);
542+
543+
json_map.put("summary_stats", summ_stats);
544+
545+
}
546+
505547

506548

507549
public void writeMisincorporations(Frequencies frequencies, int threshold) throws IOException {

src/main/java/RunDamageProfiler.java

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

12-
private static final String VERSION = "0.3.14";
12+
private static final String VERSION = "0.4.3";
1313

1414

1515
@SuppressWarnings("static-access")

src/main/java/calculations/StartCalculations.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class StartCalculations {
3535
private String input;
3636
private SpecieHandler specieHandler;
3737

38+
3839
public StartCalculations(String version){
3940
VERSION = version;
4041
}
@@ -280,7 +281,6 @@ parse species reference (-s) and run DP
280281

281282
}
282283

283-
284284
private void generateOutput(DamageProfiler damageProfiler, String output_folder, String inputfileNameWithOutExtension, String spe)
285285
throws IOException, DocumentException {
286286

@@ -296,6 +296,7 @@ private void generateOutput(DamageProfiler damageProfiler, String output_folder,
296296
input,
297297
LOG
298298
);
299+
299300
outputGenerator.writeLengthDistribution();
300301
outputGenerator.writeDamageFiles(
301302
damageProfiler.getFrequencies().getCount_G_A_3_norm(),
@@ -308,6 +309,8 @@ private void generateOutput(DamageProfiler damageProfiler, String output_folder,
308309
damageProfiler.getFrequencies(),
309310
threshold
310311
);
312+
outputGenerator.computeSummaryMetrics();
313+
outputGenerator.writeJSON(VERSION);
311314

312315

313316
// create DamagePlots of 3' and 5' ends

0 commit comments

Comments
 (0)