Permalink
Browse files

to demo..

  • Loading branch information...
1 parent 195eb7a commit d6e07c50e21d1ac8ea29a5282683623df7bca71a @hsnguyen hsnguyen committed Jul 9, 2017
@@ -9,8 +9,11 @@
public class Alignment implements Comparable<Alignment> {
public final static int OVERHANG_THRES=1000;
-
- int score;
+ public final static int GOOD_QUAL=60;
+
+ public static int MIN_QUAL=20; //TODO: reduce this by doing self-correction
+
+ int alignLength, quality;
public String readID;
BidirectedNode node;
@@ -37,23 +40,10 @@
//public int readLeft, readRight, readAlign, refLeft, refRight, refAlign;
//left and right are in the direction of the reference sequence
- public Alignment(String readID, int refStart, int refEnd, int readLength,
- int readStart, int readEnd, boolean strand, boolean useful, BidirectedNode node, int score){
- this.readID = readID;
- this.node = node;
- this.refStart = refStart;
- this.refEnd = refEnd;
-
- this.readLength = readLength;
- this.readStart = readStart;//1-index
- this.readEnd = readEnd;//1-index
- this.strand = strand;
- this.useful = useful;
- this.score = score;
- }
public Alignment(SAMRecord sam, BidirectedNode node) {
// readID = Integer.parseInt(sam.getReadName().split("_")[0]);
readID = sam.getReadName();
+ quality = sam.getMappingQuality();
prime=!sam.getNotPrimaryAlignmentFlag();
this.node = node;
@@ -104,7 +94,7 @@ public Alignment(SAMRecord sam, BidirectedNode node) {
int refLeft = refStart - 1;
int refRight = ((Sequence) node.getAttribute("seq")).length() - refEnd;
- score = refEnd + 1 - refStart;
+ alignLength = refEnd + 1 - refStart;
if (sam.getReadNegativeStrandFlag()){
strand = false;
//need to convert the alignment position on read the correct direction
@@ -118,9 +108,10 @@ public Alignment(SAMRecord sam, BidirectedNode node) {
)
goodMargin=true;
- if( goodMargin &&
+ if ( goodMargin
//prime && //TODO: should be separated as another attribute for further consideration??
- score > BidirectedGraph.getKmerSize() //FIXME:
+ && alignLength > BidirectedGraph.getKmerSize() //FIXME:
+ && quality >= MIN_QUAL
)
useful = true;
@@ -386,8 +386,23 @@ public static void setKmerSize(int kmer){
//traverse(tmp, dest, retval, distance+source.getSeq().length()+dest.getSeq().length());
traverse(tmp, dstNode, possiblePaths, distance, from.strand, to.strand, 0);
//only get the best ones
- if(possiblePaths.isEmpty())
- return null;
+ if(possiblePaths.isEmpty()){
+ //if a path couldn't be found between 2 dead-ends but alignments quality are insane high
+ //FIXME: return a pseudo path having an nanopore edge
+ if(isUnique(srcNode) && isUnique(dstNode) && srcNode.getDegree() == 1 && dstNode.getDegree()==1 &&
+ Math.min(from.quality, to.quality) >= Alignment.GOOD_QUAL)
+ {
+ BidirectedEdge pseudoEdge = new BidirectedEdge(srcNode, dstNode, from.strand, to.strand);
+ //TODO: save the corresponding content of long reads to this edge
+ pseudoEdge.setAttribute("pseudo", distance);
+ tmp.add(pseudoEdge);
+ retval.add(tmp);
+ System.out.println("pseudo path from " + srcNode.getId() + " to " + dstNode.getId());
+// HybridAssembler.promptEnterKey();
+ return retval;
+ }else
+ return null;
+ }
double bestScore=possiblePaths.get(0).getDeviation();
for(int i=0;i<possiblePaths.size();i++){
BidirectedPath p = possiblePaths.get(i);
@@ -5,8 +5,8 @@
import org.graphstream.graph.*;
public class GraphExplore {
- public static String spadesFolder="/home/sonhoanghguyen/Projects/scaffolding/data/spades_3.7/";
-
+ //public static String spadesFolder="/home/sonhoanghguyen/Projects/scaffolding/data/spades_3.7/";
+ public static String spadesFolder="/home/hoangnguyen/workspace/data/spades/"; //sony
public static void main(String args[]) {
try {
new GraphExplore();
@@ -49,8 +49,8 @@ public GraphExplore() throws IOException{
//TODO: debug: search output for 125657_channel_96_read_33_twodimentional
// assign distance to edge (not just -127 anymore but the path)
ass.reduceFromSPAdesPaths(spadesFolder+sample+"/contigs.paths");
- HybridAssembler.promptEnterKey();
- ass.assembly(spadesFolder+sample+"/assembly_graph.sam", 1);
+// HybridAssembler.promptEnterKey();
+ ass.assembly(spadesFolder+sample+"/assembly_graph.sam");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -38,7 +38,7 @@ public HybridAssembler(String graphFile) throws IOException{
}
- public void assembly(String bamFile, int qual) throws IOException{
+ public void assembly(String bamFile) throws IOException{
SamReaderFactory.setDefaultValidationStringency(ValidationStringency.SILENT);
SamReader reader;
@@ -57,8 +57,8 @@ public void assembly(String bamFile, int qual) throws IOException{
SAMRecord rec = iter.next();
if (rec.getReadUnmappedFlag())
continue;
- if (rec.getMappingQuality() < qual)
- continue;
+// if (rec.getMappingQuality() < qual)
+// continue;
String refID = rec.getReferenceName().split("_")[1];
Alignment myRec = new Alignment(rec, simGraph.getNode(refID)); //FIXME: optimize
@@ -249,7 +249,7 @@ public static void main(String[] argv) throws IOException{
//For SAM file, run bwa first on the edited assembly_graph.fastg by running:
//awk -F '[:;]' -v q=\' 'BEGIN{flag=0;}/^>/{if(index($1,q)!=0) flag=0; else flag=1;}{if(flag==1) print $1;}' ../EcK12S-careful/assembly_graph.fastg > Eck12-careful.fasta
//TODO: need to make this easier
- hbAss.assembly(GraphExplore.spadesFolder+"bwa/EcK12S-careful.sam", 30);
+ hbAss.assembly(GraphExplore.spadesFolder+"bwa/EcK12S-careful.sam");
}
}
@@ -7,6 +7,7 @@
import japsa.util.CommandLine;
import japsa.util.deploy.Deployable;
+import japsadev.bio.hts.newscarf.Alignment;
import japsadev.bio.hts.newscarf.BidirectedGraph;
import japsadev.bio.hts.newscarf.HybridAssembler;
@@ -32,7 +33,7 @@ public static void main(String[] args) throws IOException{
CommandLine cmdLine = new NewScarfCmd ();
args = cmdLine.stdParseLine(args);
- int qual = cmdLine.getIntVal("qual");
+ Alignment.MIN_QUAL = cmdLine.getIntVal("qual");
String fastgFile = cmdLine.getStringVal("fastg");
String samFile = cmdLine.getStringVal("sam");
String pathFile = cmdLine.getStringVal("path");
@@ -79,7 +80,7 @@ public static void main(String[] args) throws IOException{
try {
if(pathFile!=null)
hbAss.reduceFromSPAdesPaths(pathFile);
- hbAss.assembly(samFile, qual);
+ hbAss.assembly(samFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

0 comments on commit d6e07c5

Please sign in to comment.