Skip to content

Commit

Permalink
add option bwa index...todo: a-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
hsnguyen committed Aug 8, 2017
1 parent 3f37020 commit 64334a5
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 30 deletions.
10 changes: 6 additions & 4 deletions src/dev/java/japsadev/bio/hts/newscarf/GraphExplore.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ public static void main(String args[]) {

public GraphExplore() throws IOException{
//System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");
String sample="EcK12S-careful";
// String sample="EcK12S-careful";
// String sample="Kp2146-careful";
// String sample="meta-careful";
String sample="cp_S5";

HybridAssembler ass = new HybridAssembler(spadesFolder+sample+"/assembly_graph.fastg");
BidirectedGraph graph= ass.simGraph;
Expand All @@ -43,8 +45,8 @@ public GraphExplore() throws IOException{


for (Node node : graph) {
node.addAttribute("ui.label", node.getId());
node.setAttribute("ui.style", "text-offset: -10;");
// node.addAttribute("ui.label", node.getId());
// node.setAttribute("ui.style", "text-offset: -10;");
if(BidirectedGraph.isUnique(node))
node.setAttribute("ui.class", "marked");
}
Expand All @@ -57,7 +59,7 @@ public GraphExplore() throws IOException{
try {
HybridAssembler.promptEnterKey();
ass.reduceFromSPAdesPaths(spadesFolder+sample+"/contigs.paths");
// HybridAssembler.promptEnterKey();
HybridAssembler.promptEnterKey();
ass.assembly(spadesFolder+sample+"/assembly_graph.sam");

} catch (IOException e) {
Expand Down
6 changes: 4 additions & 2 deletions src/dev/java/japsadev/bio/hts/newscarf/HybridAssembler.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public void assembly(String bamFile) throws IOException{

if(p!=null)
System.out.println("Final path found: " + p.getId());
reduce2(p);
reduce(p);
// reduce2(p);
samList = new ArrayList<Alignment>();
//readID = myRec.readID;
}
Expand Down Expand Up @@ -102,7 +103,8 @@ public void reduceFromSPAdesPaths(String paths) throws IOException{
if(s.contains("NODE")){
if(flag){
BidirectedPath path=new BidirectedPath(simGraph, curpath);
reduce2(path);
reduce(path);
// reduce2(path);
}
flag=s.contains("'")?false:true;
curpath=new String();
Expand Down
22 changes: 9 additions & 13 deletions src/dev/java/japsadev/tools/GapCloserCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public GapCloserCmd(){
addString("seqFile", null, "Name of the assembly file (sorted by length)",true);

addString("input", "-", "Name of the input file, - for stdin", true);
addString("format", "sam", "format of the input fastq/fasta or sam/bam");
addString("format", "sam", "Format of the input: fastq/fasta or sam/bam", true);
addBoolean("index", true, "Whether to index the contigs sequence by the aligner or not.");

addString("bwaExe", "bwa", "Path to bwa");
Expand Down Expand Up @@ -153,21 +153,20 @@ public static void main(String[] args) throws IOException, InterruptedException
ProcessBuilder pb = new ProcessBuilder(bwaExe).redirectErrorStream(true);
Process process = pb.start();
BufferedReader bf = SequenceReader.openFile(process.getInputStream());
if(process.waitFor()!=0){
System.err.println("bwa failed!");//???
System.exit(1);
}


String line;
String version = "";
Pattern versionPattern = Pattern.compile("^Version:\\s(\\d+\\.\\d+\\.\\d+).*");
Matcher matcher=versionPattern.matcher("");

while ((line = bf.readLine())!=null){
System.out.println(line);
Matcher matcher =versionPattern.matcher(line);
matcher.reset(line);
if (matcher.find()){
System.out.print(line);
version = matcher.group(1);
break;//while
}
break;//while


}
bf.close();
Expand All @@ -187,10 +186,7 @@ public static void main(String[] args) throws IOException, InterruptedException
if(cmdLine.getBooleanVal("index")){
ProcessBuilder pb2 = new ProcessBuilder(bwaExe,"index",sequenceFile);
Process indexProcess = pb2.start();
if(indexProcess.waitFor()!=0){
System.err.println("Indexing failed!");
System.exit(1);
}
indexProcess.waitFor();
}
}catch (IOException e){
System.err.println(e.getMessage());
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/japsa/bio/hts/scaffold/AlignmentRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ public AlignmentRecord(String readID, int refStart, int refEnd, int readLength,
this.score = score;
}
public AlignmentRecord(SAMRecord sam, Contig ctg) {
if(!sam.getReferenceName().equals(ctg.getName())){
System.err.println("Reference in SAM file doesn't agree with contigs name: "
+ sam.getReferenceName() + " != " + ctg.getName());
System.err.println("Hint: SAM file must resulted from alignment between long reads and contigs!");
System.exit(1);
}

// readID = Integer.parseInt(sam.getReadName().split("_")[0]);
readID = sam.getReadName();

Expand Down
44 changes: 33 additions & 11 deletions src/main/java/japsa/tools/bio/np/GapCloserCmd.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author sonnguyen, minhduc
Expand All @@ -67,10 +69,11 @@ public GapCloserCmd(){
setDesc(annotation.scriptDesc());

addString("seqFile", null, "Name of the assembly file (sorted by length)",true);
//addString("bamFile", null, "Name of the bam file", true);

addString("input", "-", "Name of the input file, - for stdin", true);
addString("format", "fastq/fasta", "format of the input fastq/fasta or sam/bam");
addString("format", "sam", "Format of the input: fastq/fasta or sam/bam", true);
addBoolean("index", true, "Whether to index the contigs sequence by the aligner or not.");

addString("bwaExe", "bwa", "Path to bwa");
addInt("bwaThread", 4, "Theads used by bwa");
addBoolean("long", false, "Whether report all sequences, including short/repeat contigs (default) or only long/unique/completed sequences.");
Expand Down Expand Up @@ -135,24 +138,43 @@ public static void main(String[] args) throws
ProcessBuilder pb = new ProcessBuilder(bwaExe).redirectErrorStream(true);
Process process = pb.start();
BufferedReader bf = SequenceReader.openFile(process.getInputStream());


String line;
String version = "";
while ((line = bf.readLine())!=null){
if (line.startsWith("Version: ")){
version = line.substring(9).trim();
break;//while
}
Pattern versionPattern = Pattern.compile("^Version:\\s(\\d+\\.\\d+\\.\\d+).*");
Matcher matcher=versionPattern.matcher("");

while ((line = bf.readLine())!=null){
matcher.reset(line);
if (matcher.find()){
version = matcher.group(1);
break;//while
}


}
bf.close();

if (version.length() == 0){
System.err.println(bwaExe + " is not the rith path to bwa. bwa is required");
LOG.error(bwaExe + " is not the right path to bwa. bwa is required");
System.exit(1);
}else{
if (!version.startsWith("0.7.1")){
System.err.println(" Require bwa of 0.7.11 or above");
LOG.info("bwa version: " + version);
if (version.compareTo("0.7.11") < 0){
LOG.error(" Require bwa of 0.7.11 or above");
System.exit(1);
}
}

//run indexing
if(cmdLine.getBooleanVal("index")){
LOG.info("bwa index running...");
ProcessBuilder pb2 = new ProcessBuilder(bwaExe,"index",sequenceFile);
Process indexProcess = pb2.start();
indexProcess.waitFor();
LOG.info("bwa index finished!");
}
}catch (IOException e){
System.err.println(e.getMessage());
System.exit(1);
Expand All @@ -161,7 +183,7 @@ public static void main(String[] args) throws
}else if (format.startsWith("sam") || format.startsWith("bam")){
// no problem
}else{
System.err.println("I dont understand format " + format);
LOG.error("Unrecognized format: " + format);
System.exit(1);
}

Expand Down

0 comments on commit 64334a5

Please sign in to comment.