Repository navigation
surject changes: --diploid-map for long-read placements - #5054
Sagorikanag wants to merge 7 commits into
Conversation
ff5aa7a to
6c1c44d
Compare
049416c to
b0d4981
Compare
067c569 to
e1e3dd0
Compare
7f44980 to
9f40d55
Compare
91a7154 to
c862557
Compare
c862557 to
c755cb9
Compare
c755cb9 to
c862557
Compare
adamnovak
left a comment
There was a problem hiding this comment.
This looks like it's written pretty well.
| if (annotate_with_graph_alignment) { | ||
| annotate_graph_cigar(surjected, source, positions); | ||
| } | ||
| const size_t first_candidate = candidates.size(); |
There was a problem hiding this comment.
The JavaScript-flavored consts on random locals are back.
| if (source.mapping_quality() < 0 || source.mapping_quality() > 255) { | ||
| throw invalid_argument("diploid input MAPQ must be between 0 and 255"); | ||
| } |
There was a problem hiding this comment.
This might be better handled by clamping the input MAPQ, at least on the high end. If someobdy comes up with a tool that decides to send MAPQs of 1024 or something, I don't know that that's a good reason to crash the program. It's allowed by the format.
| } catch (const std::exception& ex) { | ||
| report_exception(ex); | ||
| } |
There was a problem hiding this comment.
Since we have a lot of exceptions that surject_diploid can throw that amount to "Bad user! Don't do that! It's not implemented!", or "Your data file seems incoherent", we might consider giving those their own type that we could catch here. It's best if those sorts of errors are reported as if we expected that they would actually happen in normal operation (i.e. without a stack trace and instructions to report a bug).
| for (const auto& tag : diploid_tags) { | ||
| if (get<1>(tag) == 'Z') { | ||
| bam_aux_append(bam, get<0>(tag).c_str(), 'Z', get<2>(tag).size() + 1, | ||
| reinterpret_cast<const uint8_t*>(get<2>(tag).c_str())); | ||
| } else { | ||
| int32_t quality = stoi(get<2>(tag)); | ||
| bam_aux_append(bam, get<0>(tag).c_str(), 'i', sizeof(quality), | ||
| reinterpret_cast<const uint8_t*>(&quality)); | ||
| } | ||
| } |
There was a problem hiding this comment.
I feel like, instead of getting the diploid-surjection tags, scanning them all for each tag annotation to skip annotation tags with the same names as diploid-surjection tags, doing the big complex loop to write annotation tags according to their types, and then looking at the diploid tags and doing specialized logic to write them according to the types we think they must have (either Z or i), we should instead get all the annotation tags, apply the diploid tags on top, and then serialize that collection of tags.
| auto clear_sa = [](Alignment& aln) { | ||
| if (!has_annotation(aln, "tags")) { | ||
| return; | ||
| } | ||
| string tags = get_annotation<string>(aln, "tags"); | ||
| string retained; | ||
| for (size_t start = 0; start < tags.size();) { | ||
| size_t end = tags.find('\t', start); | ||
| string tag = tags.substr(start, end == string::npos ? end : end - start); | ||
| if (tag.compare(0, 3, "SA:") != 0) { | ||
| if (!retained.empty()) retained += '\t'; | ||
| retained += tag; | ||
| } | ||
| if (end == string::npos) break; | ||
| start = end + 1; | ||
| } | ||
| if (retained.empty()) clear_annotation(aln, "tags"); | ||
| else set_annotation(aln, "tags", retained); | ||
| }; |
There was a problem hiding this comment.
We can build accessors like this to let us use the SA tag inside the tags annotation to store stuff, but if we're going to treat it as somewhere we store important stuff about the alignment that we might need to change later, we should probably consider using a different internal format.
Changelog Entry
vg surjectcan jointly surject multiple graph placements of the same read onto a diploid reference assembly with--diploid-map.Description
This adds diploid long-read surjection for name-grouped GAM/GAF input.
For each read,
vg surject --diploid-map NAME:hp,hq, andaqThe grouped-placement operation lives in
Surjectorrather than the CLI so the selection and quality behavior can be unit tested directly.This layer also rejects unsupported paired/interleaved and GAMP diploid input instead of silently falling back to ordinary surjection.
Depends on:
Stacked on #5052.
Depends on vgteam/libvgio#96.
Testing
vg surjectCLI tests passRemaining work
Stack created with GitHub Stacks CLI • Give Feedback 💬