Skip to content

Commit c8992b2

Browse files
Convert org.biojava3.genome to slf4j biojava#155
1 parent 809e9c8 commit c8992b2

20 files changed

Lines changed: 300 additions & 222 deletions
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package org.biojava3.genome;
22

3+
import org.slf4j.Logger;
4+
import org.slf4j.LoggerFactory;
5+
36
/**
47
* Hello world!
58
*
69
*/
7-
public class App
8-
{
9-
public static void main( String[] args )
10-
{
11-
System.out.println( "Hello World!" );
12-
}
10+
public class App {
11+
12+
private static final Logger logger = LoggerFactory.getLogger(App.class);
13+
14+
public static void main(String[] args) {
15+
logger.info("Hello World!");
16+
}
1317
}

biojava3-genome/src/main/java/org/biojava3/genome/GeneFeatureHelper.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,16 @@
3030
import org.biojava3.genome.parsers.gff.GeneIDGFF2Reader;
3131
import org.biojava3.genome.parsers.gff.GeneMarkGTFReader;
3232

33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
35+
3336
/**
3437
*
3538
* @author Scooter Willis <willishf at gmail dot com>
3639
*/
3740
public class GeneFeatureHelper {
3841

42+
private static final Logger logger = LoggerFactory.getLogger(App.class);
3943

4044
static public LinkedHashMap<String, ChromosomeSequence> loadFastaAddGeneFeaturesFromUpperCaseExonFastaFile(File fastaSequenceFile, File uppercaseFastaFile, boolean throwExceptionGeneNotFound) throws Exception {
4145
LinkedHashMap<String, ChromosomeSequence> chromosomeSequenceList = new LinkedHashMap<String, ChromosomeSequence>();
@@ -83,7 +87,8 @@ static public LinkedHashMap<String, ChromosomeSequence> loadFastaAddGeneFeatures
8387
}
8488

8589
if (geneFound) {
86-
System.out.println("Gene " + dnaSequence.getAccession().toString() + " found at " + contigDNASequence.getAccession().toString() + " " + bioStart + " " + bioEnd + " " + strand);
90+
logger.info("Gene {} found at {} {} {} {}",
91+
dnaSequence.getAccession().toString(), contigDNASequence.getAccession().toString(), bioStart, bioEnd, strand);
8792
ChromosomeSequence chromosomeSequence = chromosomeSequenceList.get(accession);
8893

8994
ArrayList<Integer> exonBoundries = new ArrayList<Integer>();
@@ -142,7 +147,7 @@ static public LinkedHashMap<String, ChromosomeSequence> loadFastaAddGeneFeatures
142147
if (throwExceptionGeneNotFound) {
143148
throw new Exception(dnaSequence.getAccession().toString() + " not found");
144149
}
145-
System.out.println("Gene not found " + dnaSequence.getAccession().toString());
150+
logger.info("Gene not found {}", dnaSequence.getAccession().toString());
146151
}
147152

148153
}
@@ -837,19 +842,19 @@ static public LinkedHashMap<String, ProteinSequence> getProteinSequences(Collect
837842
for (TranscriptSequence transcriptSequence : geneSequence.getTranscripts().values()) {
838843
//TODO remove?
839844
// DNASequence dnaCodingSequence = transcriptSequence.getDNACodingSequence();
840-
// System.out.println("CDS=" + dnaCodingSequence.getSequenceAsString());
845+
// logger.info("CDS={}", dnaCodingSequence.getSequenceAsString());
841846

842847
try {
843848
ProteinSequence proteinSequence = transcriptSequence.getProteinSequence();
844849

845-
// System.out.println(proteinSequence.getAccession().getID() + " " + proteinSequence);
850+
// logger.info("{} {}", proteinSequence.getAccession().getID(), proteinSequence);
846851
if (proteinSequenceHashMap.containsKey(proteinSequence.getAccession().getID())) {
847852
throw new Exception("Duplicate protein sequence id=" + proteinSequence.getAccession().getID() + " found at Gene id=" + geneSequence.getAccession().getID());
848853
} else {
849854
proteinSequenceHashMap.put(proteinSequence.getAccession().getID(), proteinSequence);
850855
}
851856
} catch (Exception e) {
852-
e.printStackTrace();
857+
logger.error("Exception: ", e);
853858
}
854859

855860
}
@@ -880,7 +885,7 @@ public static void main(String args[]) throws Exception {
880885
LinkedHashMap<String, ChromosomeSequence> chromosomeSequenceList = GeneFeatureHelper.loadFastaAddGeneFeaturesFromGlimmerGFF3(new File("Scaffolds.fna"), new File("glimmerhmm.gff"));
881886
LinkedHashMap<String, ProteinSequence> proteinSequenceList = GeneFeatureHelper.getProteinSequences(chromosomeSequenceList.values());
882887
// for (ProteinSequence proteinSequence : proteinSequenceList.values()) {
883-
// System.out.println(proteinSequence.getAccession().getID() + " " + proteinSequence);
888+
// logger.info(proteinSequence.getAccession().getID() + " " + proteinSequence);
884889
// }
885890
FastaWriterHelper.writeProteinSequence(new File("predicted_glimmer.faa"), proteinSequenceList.values());
886891
@@ -900,7 +905,7 @@ public static void main(String args[]) throws Exception {
900905
}
901906

902907
} catch (Exception e) {
903-
e.printStackTrace();
908+
logger.error("Exception: ", e);
904909
}
905910

906911
}

biojava3-genome/src/main/java/org/biojava3/genome/homology/GFF3FromUniprotBlastHits.java

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
import java.io.OutputStream;
1010
import java.util.ArrayList;
1111
import java.util.LinkedHashMap;
12-
import java.util.logging.Level;
13-
import java.util.logging.LogManager;
14-
import java.util.logging.Logger;
1512

1613
import org.biojava3.alignment.Alignments;
1714
import org.biojava3.alignment.Alignments.PairwiseSequenceAlignerType;
@@ -32,6 +29,8 @@
3229
import org.biojava3.core.sequence.features.FeaturesKeyWordInterface;
3330
import org.biojava3.core.sequence.loader.UniprotProxySequenceReader;
3431
import org.biojava3.genome.GeneFeatureHelper;
32+
import org.slf4j.Logger;
33+
import org.slf4j.LoggerFactory;
3534

3635
/**
3736
*
@@ -40,7 +39,7 @@
4039
*/
4140
public class GFF3FromUniprotBlastHits {
4241

43-
private static final Logger logger = Logger.getLogger(GFF3FromUniprotBlastHits.class.getName());
42+
private static final Logger logger = LoggerFactory.getLogger(GFF3FromUniprotBlastHits.class);
4443

4544
public void process(File xmlBlastHits, double ecutoff, LinkedHashMap<String, GeneSequence> geneSequenceHashMap, OutputStream gff3Output) throws Exception {
4645
LinkedHashMap<String, ArrayList<String>> hits = BlastHomologyHits.getMatches(xmlBlastHits, ecutoff);
@@ -56,14 +55,14 @@ public void process(LinkedHashMap<String, ArrayList<String>> hits, LinkedHashMap
5655
if (index == 12) {
5756
index = 12;
5857
}
59-
logger.severe(accessionid + " " + index + "/" + size);
58+
logger.error(accessionid + " " + index + "/" + size);
6059
try {
6160

6261
String[] data = accessionid.split(" ");
6362
String id = data[0];
6463
GeneSequence geneSequence = geneSequenceHashMap.get(id);
6564
if (geneSequence == null) {
66-
logger.severe("Not found " + id);
65+
logger.error("Not found " + id);
6766
continue;
6867
}
6968
ArrayList<String> uniprotProteinHits = hits.get(accessionid);
@@ -85,11 +84,11 @@ public void process(LinkedHashMap<String, ArrayList<String>> hits, LinkedHashMap
8584
}
8685
if (!testSequence.equals(predictedProteinSequence) && (!predictedProteinSequence.equals(testSequence.substring(0, testSequence.length() - 1)))) {
8786
DNASequence codingSequence = transcriptSequence.getDNACodingSequence();
88-
System.out.println(codingSequence.getSequenceAsString());
89-
System.out.println("Sequence agreement error");
90-
System.out.println("CDS seq=" + testSequence);
91-
System.out.println("PRE seq=" + predictedProteinSequence);
92-
System.out.println("UNI seq=" + hitSequence);
87+
logger.info("Coding Sequence: {}", codingSequence.getSequenceAsString());
88+
logger.info("Sequence agreement error");
89+
logger.info("CDS seq={}", testSequence);
90+
logger.info("PRE seq={}", predictedProteinSequence);
91+
logger.info("UNI seq={}", hitSequence);
9392
// throw new Exception("Protein Sequence compare error " + id);
9493
}
9594

@@ -249,7 +248,7 @@ PairwiseSequenceAlignerType.LOCAL, new SimpleGapPenalty(),
249248
}
250249
}
251250
} catch (Exception e) {
252-
logger.log(Level.INFO, accessionid, e);
251+
logger.info("Accession Id: {}", accessionid, e);
253252
}
254253
}
255254

@@ -263,7 +262,6 @@ PairwiseSequenceAlignerType.LOCAL, new SimpleGapPenalty(),
263262
public static void main(String[] args) {
264263
/*
265264
try {
266-
LogManager.getLogManager().getLogger("").setLevel(Level.SEVERE);
267265
LinkedHashMap<String, ChromosomeSequence> dnaSequenceList = GeneFeatureHelper.loadFastaAddGeneFeaturesFromGeneMarkGTF(new File("/Users/Scooter/scripps/dyadic/analysis/454Scaffolds/454Scaffolds.fna"), new File("/Users/Scooter/scripps/dyadic/analysis/454Scaffolds/genemark_hmm.gtf"));
268266
LinkedHashMap<String, GeneSequence> geneSequenceList = GeneFeatureHelper.getGeneSequences(dnaSequenceList.values());
269267
FileOutputStream fo = new FileOutputStream("/Users/Scooter/scripps/dyadic/analysis/454Scaffolds/genemark_uniprot_match.gff3");
@@ -274,31 +272,24 @@ public static void main(String[] args) {
274272
275273
276274
} catch (Exception e) {
277-
e.printStackTrace();
275+
logger.error("Exception: ", e);
278276
279277
280278
}
281279
*/
282280

283281
try {
284-
LogManager.getLogManager().getLogger("").setLevel(Level.SEVERE);
285282
LinkedHashMap<String, ChromosomeSequence> dnaSequenceHashMap = GeneFeatureHelper.loadFastaAddGeneFeaturesFromGlimmerGFF3(new File("/Users/Scooter/scripps/dyadic/analysis/454Scaffolds/454Scaffolds-16.fna"), new File("/Users/Scooter/scripps/dyadic/GlimmerHMM/c1_glimmerhmm-16.gff"));
286283
LinkedHashMap<String, GeneSequence> geneSequenceList = GeneFeatureHelper.getGeneSequences(dnaSequenceHashMap.values());
287284
FileOutputStream fo = new FileOutputStream("/Users/Scooter/scripps/dyadic/outputGlimmer/genemark_uniprot_match-16.gff3");
288285
LinkedHashMap<String, ArrayList<String>> blasthits = BlastHomologyHits.getMatches(new File("/Users/Scooter/scripps/dyadic/blastresults/c1_glimmer_in_uniprot.xml"), 1E-10);
289-
logger.severe("Number of uniprot hits " + blasthits.size());
286+
logger.error("Number of uniprot hits " + blasthits.size());
290287

291288
GFF3FromUniprotBlastHits gff3FromUniprotBlastHits = new GFF3FromUniprotBlastHits();
292289
gff3FromUniprotBlastHits.process(blasthits, geneSequenceList, fo);
293290
fo.close();
294-
295-
296291
} catch (Exception e) {
297-
e.printStackTrace();
298-
299-
292+
logger.error("Exception: ", e);
300293
}
301-
302-
303294
}
304295
}

biojava3-genome/src/main/java/org/biojava3/genome/parsers/cytoband/CytobandParser.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,68 +27,76 @@
2727
import java.io.IOException;
2828
import java.io.InputStream;
2929
import java.io.InputStreamReader;
30-
3130
import java.net.URL;
3231
import java.util.SortedSet;
3332
import java.util.TreeSet;
3433
import java.util.zip.GZIPInputStream;
3534

35+
import org.slf4j.Logger;
36+
import org.slf4j.LoggerFactory;
3637

37-
/** Parses the cytoband (karyotype) file from UCSC.
38+
/**
39+
* Parses the cytoband (karyotype) file from UCSC.
3840
*
3941
*/
4042
public class CytobandParser {
4143

44+
private static final Logger logger = LoggerFactory
45+
.getLogger(CytobandParser.class);
46+
4247
public static final String DEFAULT_LOCATION = "http://hgdownload.cse.ucsc.edu/goldenPath/hg19/database/cytoBand.txt.gz";
4348

44-
public static void main(String[] args){
49+
public static void main(String[] args) {
4550

4651
CytobandParser me = new CytobandParser();
4752
try {
48-
SortedSet<Cytoband> cytobands = me.getAllCytobands(new URL(DEFAULT_LOCATION));
53+
SortedSet<Cytoband> cytobands = me.getAllCytobands(new URL(
54+
DEFAULT_LOCATION));
4955
SortedSet<StainType> types = new TreeSet<StainType>();
50-
for (Cytoband c : cytobands){
51-
System.out.println(c);
52-
if ( ! types.contains(c.getType()))
56+
for (Cytoband c : cytobands) {
57+
logger.info("Cytoband: {}", c);
58+
if (!types.contains(c.getType()))
5359
types.add(c.getType());
5460
}
55-
System.out.println(types);
61+
logger.info("Strain Type: {}", types);
5662
} catch (Exception e) {
5763
// TODO Auto-generated catch block
58-
e.printStackTrace();
64+
logger.error("Exception: ", e);
5965
}
6066

61-
6267
}
6368

6469
public SortedSet<Cytoband> getAllCytobands(URL u) throws IOException {
65-
InputStream stream =new GZIPInputStream(u.openStream());
70+
InputStream stream = new GZIPInputStream(u.openStream());
6671
return getAllCytobands(stream);
6772

6873
}
6974

70-
public SortedSet<Cytoband> getAllCytobands(InputStream instream) throws IOException {
71-
BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
75+
public SortedSet<Cytoband> getAllCytobands(InputStream instream)
76+
throws IOException {
77+
BufferedReader reader = new BufferedReader(new InputStreamReader(
78+
instream));
7279
String line = null;
73-
SortedSet<Cytoband> cytobands= new TreeSet<Cytoband>();
80+
SortedSet<Cytoband> cytobands = new TreeSet<Cytoband>();
7481
while ((line = reader.readLine()) != null) {
7582
String[] spl = line.split("\t");
76-
if ( spl.length != 5){
77-
System.err.println("WRONG LINE LENGHT, expected 5, but got " + spl.length + " for: " + line);
83+
if (spl.length != 5) {
84+
logger.warn(
85+
"WRONG LINE LENGHT, expected 5, but got {} for: {}",
86+
spl.length, line);
7887
}
7988

80-
8189
Cytoband b = new Cytoband();
8290
b.setChromosome(spl[0]);
8391
b.setStart(Integer.parseInt(spl[1]));
8492
b.setEnd(Integer.parseInt(spl[2]));
8593
b.setLocus(spl[3]);
86-
StainType type = StainType.getStainTypeFromString( spl[4]);
87-
if ( type == null)
88-
System.err.println("unknown type: " +spl[4]);
94+
StainType type = StainType.getStainTypeFromString(spl[4]);
95+
if (type == null)
96+
logger.warn("unknown type: {}", spl[4]);
8997
b.setType(type);
9098
cytobands.add(b);
91-
}
99+
}
92100

93101
return cytobands;
94102
}

biojava3-genome/src/main/java/org/biojava3/genome/parsers/geneid/GeneIDXMLReader.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import java.io.File;
88
import java.util.ArrayList;
99
import java.util.LinkedHashMap;
10-
import java.util.logging.Logger;
10+
1111
import org.biojava3.core.sequence.AccessionID;
1212
import org.biojava3.core.sequence.DNASequence;
1313
import org.biojava3.core.sequence.io.FastaWriterHelper;
1414
import org.biojava3.core.sequence.ProteinSequence;
1515
import org.biojava3.core.util.XMLHelper;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618
import org.w3c.dom.Document;
1719
import org.w3c.dom.Element;
1820

@@ -22,19 +24,20 @@
2224
*/
2325
public class GeneIDXMLReader {
2426

25-
private static final Logger log = Logger.getLogger(GeneIDXMLReader.class.getName());
27+
private static final Logger logger = LoggerFactory.getLogger(GeneIDXMLReader.class);
28+
2629
Document geneidDoc = null;
2730

2831
public GeneIDXMLReader(String geneidXMLFile) throws Exception {
29-
log.info("Start read of " + geneidXMLFile);
32+
logger.info("Start read of {}", geneidXMLFile);
3033
geneidDoc = XMLHelper.loadXML(geneidXMLFile);
31-
log.info("Read finished");
34+
logger.info("Read finished");
3235
}
3336

3437
public LinkedHashMap<String, ProteinSequence> getProteinSequences() throws Exception {
3538
LinkedHashMap<String, ProteinSequence> proteinSequenceList = new LinkedHashMap<String, ProteinSequence>();
3639
ArrayList<Element> elementList = XMLHelper.selectElements(geneidDoc.getDocumentElement(), "prediction/gene/protein");
37-
log.info(elementList.size() + " hits");
40+
logger.info("{} hits", elementList.size());
3841

3942
for (Element proteinElement : elementList) {
4043
Element geneElement = (Element) proteinElement.getParentNode();
@@ -51,7 +54,7 @@ public LinkedHashMap<String, ProteinSequence> getProteinSequences() throws Excep
5154
public LinkedHashMap<String, DNASequence> getDNACodingSequences() throws Exception {
5255
LinkedHashMap<String, DNASequence> dnaSequenceList = new LinkedHashMap<String, DNASequence>();
5356
ArrayList<Element> elementList = XMLHelper.selectElements(geneidDoc.getDocumentElement(), "prediction/gene/cDNA");
54-
log.info(elementList.size() + " hits");
57+
logger.info("{} hits", elementList.size());
5558

5659
for (Element dnaElement : elementList) {
5760
Element geneElement = (Element) dnaElement.getParentNode();
@@ -75,7 +78,7 @@ public static void main(String[] args) {
7578
FastaWriterHelper.writeNucleotideSequence(new File("/Users/Scooter/scripps/dyadic/geneid/geneid/c1_geneid.fna"), dnaSequenceHashMap.values());
7679

7780
} catch (Exception e) {
78-
e.printStackTrace();
81+
logger.error("Exception: ", e);
7982
}
8083
}
8184
}

0 commit comments

Comments
 (0)