Skip to content

Commit

Permalink
Added depth of coverage to fasta output
Browse files Browse the repository at this point in the history
  • Loading branch information
douweschulte committed Dec 18, 2023
1 parent a02ff8c commit 1485ae0
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions stitch/Reporting/FASTAReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,32 @@ public class FASTAReport : Report {
/// <param name="parameters">The parameters.</param>
/// <param name="min_score">The minimal score needed to be included in the file.</param>
public FASTAReport(ReportInputParameters parameters, int min_score, RunParameters.Report.OutputType outputType, int maxThreads) : base(parameters, maxThreads) {
MinScore = min_score;
OutputType = outputType;
this.MinScore = min_score;
this.OutputType = outputType;
}

/// <summary> Creates a FASTA file with a score for each path through the graph. The lines will be sorted and the lines can be filtered for a minimal score. </summary>
/// <returns>A string containing the file.</returns>
public override string Create() {
var sequences = new List<(double, string)>();

if (OutputType == RunParameters.Report.OutputType.Recombine) {
sequences.EnsureCapacity(Parameters.RecombinedSegment.Select(a => a.Templates.Count).Sum());
foreach (var template in Parameters.RecombinedSegment.SelectMany(a => a.Templates)) {
if (template.Score >= MinScore)
sequences.Add((template.Score, $">{template.MetaData.Identifier} score:{template.Score}\n{AminoAcid.ArrayToString(template.ConsensusSequence().Item1.SelectMany(i => i.Sequence))}"));
if (this.OutputType == RunParameters.Report.OutputType.Recombine) {
sequences.EnsureCapacity(this.Parameters.RecombinedSegment.Select(a => a.Templates.Count).Sum());
foreach (var template in this.Parameters.RecombinedSegment.SelectMany(a => a.Templates)) {
if (template.Score >= this.MinScore) {
var doc = System.String.Join(',', template.ConsensusSequence().Item2.Select(i => i.ToString("F2")));
sequences.Add((template.Score, $">{template.MetaData.Identifier} score:{template.Score} depth_of_coverage:{doc}\n{AminoAcid.ArrayToString(template.ConsensusSequence().Item1.SelectMany(i => i.Sequence))}"));
}
}
} else // TemplateMatching
{
sequences.EnsureCapacity(Parameters.Groups.Select(a => a.Item2.Count).Sum());
foreach (var (group, dbs) in Parameters.Groups) {
sequences.EnsureCapacity(this.Parameters.Groups.Select(a => a.Segments.Count).Sum());
foreach (var (group, dbs) in this.Parameters.Groups) {
foreach (var template in dbs.SelectMany(a => a.Templates)) {
if (template.Score >= MinScore)
sequences.Add((template.Score, $">{template.MetaData.Identifier} id:{group}-{template.Location.TemplateIndex} score:{template.Score}\n{AminoAcid.ArrayToString(template.ConsensusSequence().Item1.SelectMany(i => i.Sequence))}"));
if (template.Score >= this.MinScore) {
var doc = System.String.Join(',', template.ConsensusSequence().Item2.Select(i => i.ToString("F2")));
sequences.Add((template.Score, $">{template.MetaData.Identifier} id:{group}-{template.Location.TemplateIndex} score:{template.Score} depth_of_coverage:{doc}\n{AminoAcid.ArrayToString(template.ConsensusSequence().Item1.SelectMany(i => i.Sequence))}"));
}
}
}
}
Expand Down

0 comments on commit 1485ae0

Please sign in to comment.