-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
formats: improve samtools/flagstat support, #187
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...c/main/java/org/opencb/biodata/formats/alignment/samtools/io/SamtoolsFlagstatsParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.opencb.biodata.formats.alignment.samtools.io; | ||
|
||
import org.opencb.biodata.formats.alignment.samtools.SamtoolsFlagstats; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
public class SamtoolsFlagstatsParser { | ||
|
||
public static SamtoolsFlagstats parse(Path path) throws IOException { | ||
|
||
SamtoolsFlagstats flagstats = new SamtoolsFlagstats(); | ||
|
||
FileReader fr = new FileReader(path.toFile()); | ||
BufferedReader br = new BufferedReader(fr); | ||
|
||
String line; | ||
|
||
while ((line = br.readLine()) != null) { | ||
String[] splits = line.split(" "); | ||
int passed = Integer.parseInt(splits[0]); | ||
int failed = Integer.parseInt(splits[2]); | ||
if (line.contains("QC-passed")) { | ||
flagstats.setTotalQcPassed(passed); | ||
flagstats.setTotalReads(passed + failed); | ||
} else if (line.contains("secondary")) { | ||
flagstats.setSecondaryAlignments(passed); | ||
} else if (line.contains("supplementary")) { | ||
flagstats.setSupplementary(passed); | ||
} else if (line.contains("duplicates")) { | ||
flagstats.setDuplicates(passed); | ||
} else if (line.contains("mapped")) { | ||
flagstats.setMapped(passed); | ||
} else if (line.contains("paired in sequencing")) { | ||
flagstats.setPairedInSequencing(passed); | ||
} else if (line.contains("read1")) { | ||
flagstats.setRead1(passed); | ||
} else if (line.contains("read2")) { | ||
flagstats.setRead2(passed); | ||
} else if (line.contains("properly paired")) { | ||
flagstats.setProperlyPaired(passed); | ||
} else if (line.contains("with itself and mate mapped")) { | ||
flagstats.setSelfAndMateMapped(passed); | ||
} else if (line.contains("singletons")) { | ||
flagstats.setSingletons(passed); | ||
} else if (line.contains("mapQ>=5")) { | ||
flagstats.setDiffChrMapQ5(passed); | ||
} else if (line.contains("with mate mapped")) { | ||
flagstats.setMateMappedToDiffChr(passed); | ||
} | ||
} | ||
|
||
return flagstats; | ||
} | ||
} |