@@ -22,7 +22,9 @@ namespace vg {
2222
2323const char * const BAM_DNA_LOOKUP = " =ACMGRSVTWYHKDBN" ;
2424
25- // htslib-based alignment read functions
25+ // htslib-based alignment read functions.
26+ // When encountering read records that don't agree with the graph (i.e. go off
27+ // path ends, etc.), these stop the program and print a useful error message.
2628
2729int hts_for_each (string& filename, function<void (Alignment&)> lambda);
2830int hts_for_each_parallel (string& filename, function<void (Alignment&)> lambda);
@@ -99,11 +101,15 @@ string mapping_string(const string& source, const Mapping& mapping);
99101
100102void cigar_mapping (const bam1_t *b, Mapping& mapping);
101103
104+ // / Convert a BAM record to an Alignment.
105+ // / May throw AlignmentEmbeddingError if the BAM record is inconsistent with
106+ // / the provided graph.
102107Alignment bam_to_alignment (const bam1_t *b,
103108 const map<string, string>& rg_sample,
104109 const map<int , path_handle_t >& tid_path_handle,
105110 const bam_hdr_t *bh,
106111 const PathPositionHandleGraph* graph);
112+ // / Convert a BAM record to an Alignment without a graph.
107113Alignment bam_to_alignment (const bam1_t *b, const map<string, string>& rg_sample, const map<int , path_handle_t >& tid_path_handle);
108114
109115// the CIGAR string of the graph alignment
@@ -286,7 +292,11 @@ void reverse_complement_alignment_in_place(Alignment* aln, const function<int64_
286292vector<Alignment> reverse_complement_alignments (const vector<Alignment>& alns, const function<int64_t (nid_t )>& node_length);
287293int non_match_start (const Alignment& alignment);
288294int non_match_end (const Alignment& alignment);
295+ // / Get the leading softclip from an Alignment, assuming it is coalesced into a
296+ // / single Edit
289297int softclip_start (const Alignment& alignment);
298+ // / Get the trailing softclip from an Alignment, assuming it is coalesced into a
299+ // / single Edit
290300int softclip_end (const Alignment& alignment);
291301int softclip_trim (Alignment& alignment);
292302int query_overlap (const Alignment& aln1, const Alignment& aln2);
@@ -400,15 +410,43 @@ struct AlignmentValidity {
400410// / node lengths or ids. Result can be used like a bool or inspected for
401411// / further details. Does not log anything itself about bad alignments.
402412AlignmentValidity alignment_is_valid (const Alignment& aln, const HandleGraph* hgraph, bool check_sequence = false );
403-
413+
414+ /* *
415+ * Represents a problem when trying to find a path region in a graph as an
416+ * Alignment, or when trying to inject a linear CIGAR-based alignment into the
417+ * graph along an embedded path.
418+ *
419+ * This could be a problem like the alignment trying to go out of range on the
420+ * embedded linear path/reference, or trying to go across the junction of a
421+ * path that isn't really circular.
422+ *
423+ * We expect the user to be able to cause this with bad inputs, so this
424+ * exception should be handled and reported in a helpful way, rather than as a
425+ * crash.
426+ */
427+ class AlignmentEmbeddingError : public std ::runtime_error {
428+ public:
429+ using std::runtime_error::runtime_error;
430+ };
431+
404432// / Make an Alignment corresponding to a subregion of a stored path.
405433// / Positions are 0-based, and pos2 is excluded.
406434// / Respects path circularity, so pos2 < pos1 is not a problem.
407435// / If pos1 == pos2, returns an empty alignment.
436+ // /
437+ // / Throws AlignmentEmbeddingError if the region goes out of range, or tries to
438+ // / go across the junction of a non-circular path. Despite taking 0-based
439+ // / coordinates, error messages will describe 1-based coordinates.
408440Alignment target_alignment (const PathPositionHandleGraph* graph, const path_handle_t & path, size_t pos1, size_t pos2,
409441 const string& feature, bool is_reverse);
410442// / Same as above, but uses the given Mapping, translated directly form a CIGAR string, as a source of edits.
411443// / The edits are inserted into the generated Alignment, cut as necessary to fit into the Alignment's Mappings.
444+ // /
445+ // / Throws AlignmentEmbeddingError if the region goes out of range, or tries to
446+ // / go across the junction of a non-circular path, or if cigar_mapping
447+ // / describes edits that are impossible, like matches past the end of the
448+ // / described region. Despite taking 0-based coordinates, error messages will
449+ // / describe 1-based coordinates.
412450Alignment target_alignment (const PathPositionHandleGraph* graph, const path_handle_t & path, size_t pos1, size_t pos2,
413451 const string& feature, bool is_reverse, Mapping& cigar_mapping);
414452
0 commit comments