Skip to content

Commit

Permalink
Merge branch 'read-quietly' into lr-giraffe
Browse files Browse the repository at this point in the history
  • Loading branch information
adamnovak committed Jul 31, 2024
2 parents 0adfea0 + 94fc9b2 commit 2bbd62b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
35 changes: 24 additions & 11 deletions src/alignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,7 @@ void normalize_alignment(Alignment& alignment) {
if (doing_normalization) {
// we found things we needed to normalize away, so we must have built the normalized
// path, now replace the original with it
*alignment.mutable_path() = move(normalized);
*alignment.mutable_path() = std::move(normalized);
}
}

Expand Down Expand Up @@ -1902,6 +1902,15 @@ void parse_bed_regions(istream& bedstream,
const PathPositionHandleGraph* graph,
vector<Alignment>* out_alignments) {
out_alignments->clear();
parse_bed_regions(bedstream, graph, [&](Alignment& aln) {
out_alignments->emplace_back(std::move(aln));
});
}

void parse_bed_regions(istream& bedstream,
const PathPositionHandleGraph* graph,
const std::function<void(Alignment&)>& callback) {

if (!bedstream) {
cerr << "Unable to open bed file." << endl;
return;
Expand Down Expand Up @@ -2147,8 +2156,7 @@ void parse_bed_regions(istream& bedstream,
// Make the Alignment
Alignment alignment = target_alignment(graph, path_handle, sbuf, ebuf, name, is_reverse);
alignment.set_score(score);

out_alignments->push_back(alignment);
callback(alignment);

// if more subpaths need to be written, write them now
while (!other_seqs.empty()){
Expand All @@ -2163,17 +2171,25 @@ void parse_bed_regions(istream& bedstream,
path_handle = graph->get_path_handle(seq);
alignment = target_alignment(graph, path_handle, sbuf, ebuf, name, is_reverse);
alignment.set_score(score);
out_alignments->push_back(alignment);
callback(alignment);
}

vg::io::write_buffered(cout, *out_alignments, 1000);
}
}

void parse_gff_regions(istream& gffstream,
const PathPositionHandleGraph* graph,
vector<Alignment>* out_alignments) {
out_alignments->clear();
parse_gff_regions(gffstream, graph, [&](Alignment& aln) {
out_alignments->emplace_back(std::move(aln));
});
}

void parse_gff_regions(istream& gffstream,
const PathPositionHandleGraph* graph,
const std::function<void(Alignment&)>& callback) {


if (!gffstream) {
cerr << "Unable to open gff3/gtf file." << endl;
return;
Expand Down Expand Up @@ -2431,8 +2447,7 @@ void parse_gff_regions(istream& gffstream,
}

Alignment alignment = target_alignment(graph, graph->get_path_handle(seq), sbuf, ebuf, name, is_reverse);

out_alignments->push_back(alignment);
callback(alignment);

// if more subpaths need to be written, write them now
while (!other_seqs.empty()){
Expand All @@ -2445,10 +2460,8 @@ void parse_gff_regions(istream& gffstream,
other_ends.pop_back();
// get alignment
alignment = target_alignment(graph, graph->get_path_handle(seq), sbuf, ebuf, name, is_reverse);
out_alignments->push_back(alignment);
callback(alignment);
}

vg::io::write_buffered(cout, *out_alignments, 1000);
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/alignment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,19 @@ void normalize_alignment(Alignment& alignment);
// quality information; a kind of poor man's pileup
map<id_t, int> alignment_quality_per_node(const Alignment& aln);

/// Parse regions from the given BED file into Alignments in a vector.
/// Parse regions from the given BED file and call the given callback with each.
/// Does *not* write them to standard output.
/// Reads the optional name, is_reverse, and score fields if present, and populates the relevant Alignment fields.
/// Skips and warns about malformed or illegal BED records.
void parse_bed_regions(istream& bedstream, const PathPositionHandleGraph* graph, const std::function<void(Alignment&)>& callback);
/// Parse regions from the given GFF file and call the given callback with each.
/// Does *not* write them to standard output.
void parse_gff_regions(istream& gtfstream, const PathPositionHandleGraph* graph, const std::function<void(Alignment&)>& callback);
/// Parse regions from the given BED file into the given vector.
/// Does *not* write them to standard output.
void parse_bed_regions(istream& bedstream, const PathPositionHandleGraph* graph, vector<Alignment>* out_alignments);
/// Parse regions from the given GFF file into the given vector.
/// Does *not* write them to standard output.
void parse_gff_regions(istream& gtfstream, const PathPositionHandleGraph* graph, vector<Alignment>* out_alignments);

Position alignment_start(const Alignment& aln);
Expand Down
23 changes: 15 additions & 8 deletions src/subcommand/annotate_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,24 +479,31 @@ int main_annotate(int argc, char** argv) {
}
}
else {
// We are converting annotations to GAM.
// Set up GAM output.
// TODO: use AlignmentEmitter?
vector<Alignment> buffer;
auto emit_alignment = [&](Alignment& aln) {
// Buffer and possibly write each record
buffer.emplace_back(std::move(aln));
vg::io::write_buffered(cout, buffer, 1000);
};

for (auto& bed_name : bed_names) {
// Convert each BED file to GAM
get_input_file(bed_name, [&](istream& bed_stream) {
vector<Alignment> buffer;
parse_bed_regions(bed_stream, xg_index, &buffer);
vg::io::write_buffered(cout, buffer, 0); // flush
parse_bed_regions(bed_stream, xg_index, emit_alignment);
});

// TODO: We'll get an EOF marker per input file.
}

for (auto& gff_name : gff_names) {
get_input_file(gff_name, [&](istream& gff_stream) {
vector<Alignment> buffer;
parse_gff_regions(gff_stream, xg_index, &buffer);
vg::io::write_buffered(cout, buffer, 0); // flush
parse_gff_regions(gff_stream, xg_index, emit_alignment);
});
}

// Flush the remaining stuff in the buffer
vg::io::write_buffered(cout, buffer, 0);
}
}

Expand Down

1 comment on commit 2bbd62b

@adamnovak
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vg CI tests complete for branch lr-giraffe. View the full report here.

15 tests passed, 1 tests failed and 0 tests skipped in 15941 seconds

Failed tests:

  • test_sim_yeast_cactus (209 seconds)

Please sign in to comment.