Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyasoifer committed May 24, 2023
1 parent 6af743a commit 5395d75
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@
import java.util.LinkedHashMap;
import java.util.Map;


/**
* utility class for flow based read
* Utility class for working with flow-based reads
*
* The main member static class is {@code ReadGroupInfo} that contains methods that allow
* working with headers of flow based reads and extracting the flow order and the maximal hmer class called.
* It also contains methods to check how the read was clipped ({@code readEndMarkedUnclipped}, {@code readEndMarkedUncertain})
* Lastly, {@code FlowBasedReadUtils.isFlowPlatform} is **the** function to determine if the data are flow-based
*
*/
public class FlowBasedReadUtils {

Expand All @@ -37,20 +44,19 @@ public ReadGroupInfo(final SAMReadGroupRecord readGroup) {
isFlowPlatform = false;
} else if (NGSPlatform.fromReadGroupPL(readGroup.getPlatform())==NGSPlatform.UNKNOWN){
isFlowPlatform = false;
} else {
//old Ultima data can have PLATFORM==LS454
// we require also FO field to consider ReadGroup to come from the flow
boolean tmp = (NGSPlatform.fromReadGroupPL(readGroup.getPlatform()) == NGSPlatform.LS454) ||
(NGSPlatform.fromReadGroupPL(readGroup.getPlatform()) == NGSPlatform.ULTIMA);
tmp = tmp & (readGroup!=null);
tmp = tmp & (readGroup.getFlowOrder()!=null);
isFlowPlatform = tmp;

//in addition validate that the ultima data has FO tag, otherwise break
if ((NGSPlatform.fromReadGroupPL(readGroup.getPlatform()) == NGSPlatform.ULTIMA) & (!isFlowPlatform)){
} else if (NGSPlatform.fromReadGroupPL(readGroup.getPlatform()) == NGSPlatform.LS454) {
//old Ultima data can have PLATFORM==LS454 and not have FO tag
isFlowPlatform = true;
} else if (NGSPlatform.fromReadGroupPL(readGroup.getPlatform()) == NGSPlatform.ULTIMA){
if (readGroup.getFlowOrder()!=null) {
isFlowPlatform = true;
} else {
throw new RuntimeException("Malformed Ultima read group identified, aborting: " + readGroup);
}
} else {
isFlowPlatform = false;
}

if (isFlowPlatform) {
this.flowOrder = readGroup.getFlowOrder();
String mc = readGroup.getAttribute(FlowBasedRead.MAX_CLASS_READ_GROUP_TAG);
Expand Down Expand Up @@ -154,6 +160,14 @@ public static boolean hasFlowTags(final SAMRecord rec) {

}

/**
*
* This is the function to run if you want to ask if the data are flow-based
*
* @param hdr - file header
* @param read - the read
* @return true if the read is flow-based
*/
public static boolean isFlowPlatform(final SAMFileHeader hdr, final GATKRead read) {
if (!hasFlowTags(read)){
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Object[][] getIsFlowPlatformInputs() {
rg3.setPlatform("LS454");
read3.setReadGroup("rg3");
hdr.addReadGroup(rg3);
tests.add(new Object[]{hdr, read3, false});
tests.add(new Object[]{hdr, read3, true});

GATKRead read4 = makeRead(new byte[]{'T','A','G','C','G','A'}, false);
read4.setAttribute("tp",new byte[6]);
Expand All @@ -108,6 +108,16 @@ Object[][] getIsFlowPlatformInputs() {
hdr.addReadGroup(rg4);
tests.add(new Object[]{hdr, read4, true});

GATKRead read5 = makeRead(new byte[]{'T','A','G','C','G','A'}, false);
read5.setAttribute("tp",new byte[6]);
SAMReadGroupRecord rg5 = new SAMReadGroupRecord("rg5");
rg5.setPlatform("LS454");
rg5.setAttribute("FO","TGCATGCA");
read5.setReadGroup("rg5");
hdr.addReadGroup(rg5);
tests.add(new Object[]{hdr, read5, true});


return tests.toArray(new Object[][]{});
}

Expand Down

0 comments on commit 5395d75

Please sign in to comment.