Skip to content

Commit

Permalink
core: add filterFlag for AlignmentDataset, #68
Browse files Browse the repository at this point in the history
  • Loading branch information
jtarraga committed Aug 25, 2016
1 parent d066306 commit f6d7aa9
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,18 @@ public AlignmentDataset alignmentLengthFilter(String value) {
query.put("alen", value);
return this;
}

// alignment length filter
public AlignmentDataset flagFilter(String value) {
return flagFilter(value, false);
}

public AlignmentDataset flagFilter(String value, Boolean exclude) {
if (exclude) {
query.put("filtering-flag", value);
} else {
query.put("required-flag", value);
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,11 @@ public String parse(Query query, QueryOptions queryOptions, String viewName) {
case "alen": // alignment length
filters.add(processFilter("length(alignedSequence)", value, false, false));
break;
case "flag":
processFlagQuery(value);
case "required-flag":
processFlagQuery(value, false);
break;
case "filtering-flag":
processFlagQuery(value, true);
break;
case "region":
processRegionQuery(value, "alignment.position.referenceName",
Expand All @@ -74,7 +77,7 @@ public String parse(Query query, QueryOptions queryOptions, String viewName) {



private void processFlagQuery(String value) {
private void processFlagQuery(String value, Boolean exclude) {

String[] values = value.split("[,;]");

Expand All @@ -83,67 +86,72 @@ private void processFlagQuery(String value) {
flag |= Integer.parseInt(values[i]);
}

if (exclude) {
flag ^= 0xFF;
}
//System.out.println("---------> flag = " + flag);

StringBuilder filter = new StringBuilder();

if ((flag & 1) > 0) {
// template having multiple segments in sequencing
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 2) > 0) {
// each segment properly aligned according to the aligner
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 4) > 0) {
// segment unmapped
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 8) > 0) {
// next segment in the template unmapped
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 16) > 0) {
// SEQ being reverse complemented
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 32) > 0) {
// SEQ of the next segment in the template being reverse complemented
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 64) > 0) {
// the rst segment in the template
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 128) > 0) {
// the last segment in the template
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 256) > 0) {
// secondary alignment
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 512) > 0) {
// not passing lters, such as platform/vendor quality controls
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 1024) > 0) {
// PCR or optical duplicate
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}
if ((flag & 2048) > 0) {
// supplementary alignment
System.err.println("Filter by SAM flag 1, not implemented yet. Aborting!");
System.exit(-1);
//System.exit(-1);
}

filters.add(filter.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void initDataset() {
String filename = "/home/jtarraga/CAM/data/test.bam.avro";
System.out.println(">>>> opening file " + filename);
ad.load(filename, sparkSession);
//ad.printSchema();
ad.printSchema();
ad.createOrReplaceTempView("bam");
} catch (Exception e) {
e.printStackTrace();
Expand Down Expand Up @@ -106,4 +106,23 @@ public void alenFilter() {

System.out.println("--------------------------------------");
}


@Test
public void flagFilter() {
System.out.println(">>>> Running flagFilter...");

long count;

System.out.println("-------------------------------------- using flagFilter");

initDataset();
//sparkSession.sql("select * from bam").show();
ad.flagFilter("147,99").show();

initDataset();
ad.flagFilter("83", true).show();

System.out.println("--------------------------------------");
}
}

0 comments on commit f6d7aa9

Please sign in to comment.