-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Sam Header Readgroup Barcode field #1210
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,9 @@ | |
|
||
|
||
import htsjdk.samtools.util.Iso8601Date; | ||
import htsjdk.samtools.util.SamConstants; | ||
|
||
import java.util.Arrays; | ||
import java.util.Date; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.*; | ||
|
||
/** | ||
* Header information about a read group. | ||
|
@@ -51,6 +48,8 @@ public class SAMReadGroupRecord extends AbstractSAMHeaderRecord | |
public static final String PLATFORM_MODEL_TAG = "PM"; | ||
public static final String PLATFORM_UNIT_TAG = "PU"; | ||
public static final String READ_GROUP_SAMPLE_TAG = "SM"; | ||
public static final String BARCODE_TAG = "BC"; | ||
|
||
|
||
/* Platform values for the @RG-PL tag */ | ||
public enum PlatformValue { | ||
|
@@ -63,7 +62,7 @@ public enum PlatformValue { | |
new HashSet<String>(Arrays.asList(READ_GROUP_ID_TAG, SEQUENCING_CENTER_TAG, DESCRIPTION_TAG, | ||
DATE_RUN_PRODUCED_TAG, FLOW_ORDER_TAG, KEY_SEQUENCE_TAG, LIBRARY_TAG, | ||
PROGRAM_GROUP_TAG, PREDICTED_MEDIAN_INSERT_SIZE_TAG, PLATFORM_TAG, PLATFORM_MODEL_TAG, | ||
PLATFORM_UNIT_TAG, READ_GROUP_SAMPLE_TAG)); | ||
PLATFORM_UNIT_TAG, READ_GROUP_SAMPLE_TAG, BARCODE_TAG)); | ||
|
||
public SAMReadGroupRecord(final String id) { mReadGroupId = id; } | ||
|
||
|
@@ -90,6 +89,36 @@ public SAMReadGroupRecord(final String id, final SAMReadGroupRecord srcProgramRe | |
public String getPlatform() { return getAttribute(PLATFORM_TAG); } | ||
public void setPlatform(final String platform) { setAttribute(PLATFORM_TAG, platform); } | ||
|
||
/** | ||
* @return the List of barcodes associated with this read group or null | ||
*/ | ||
public List<String> getBarcodes() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a method using a different barcode separator too (in case it is needed by other implementations), and the one without params should use the default There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @magicDGS
My though was that we should support the recommended mode and not go out of the way to support other modes. You can always get around it by using Are there implementations out there already? Is there a practical need for what you suggest or just a theoretical one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found some FASTQ files with Anyway, I am planning to come back in the real near future to htsjk3, where we can take the decisions about supporting the "recommended" specs alone or all of them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that adding explicit support for non-standard barcode separators adds unnecessary complication. If you need to parse special ones you can always use |
||
final String barcodeString = getAttribute(BARCODE_TAG); | ||
if (barcodeString == null) { | ||
return null; | ||
} else if (barcodeString.isEmpty()) { | ||
return Collections.emptyList(); | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return Arrays.asList(barcodeString.split(SamConstants.BARCODE_SEQUENCE_DELIMITER)); | ||
} | ||
} | ||
|
||
/** | ||
* Set the barcodes associated with this ReadGroup. | ||
* Note that an input of null results in unsetting the attribute while an empty list is set as a tag with an empty value. | ||
* @param barcodes a list of barcodes to associate with this read group | ||
*/ | ||
public void setBarcodes(final List<String> barcodes) { | ||
if (barcodes == null) { | ||
setAttribute(BARCODE_TAG, null); | ||
} else { | ||
if (barcodes.stream().anyMatch(String::isEmpty)) { | ||
throw new IllegalArgumentException("A barcode must not be an empty String"); | ||
} | ||
setAttribute(BARCODE_TAG, String.join(SamConstants.BARCODE_SEQUENCE_DELIMITER, barcodes)); | ||
} | ||
} | ||
|
||
public Date getRunDate() { | ||
final String dt = getAttribute(DATE_RUN_PRODUCED_TAG); | ||
if (dt == null) return null; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be added to
STANDARD_TAGS
(?)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, good idea