///|
pub fn Annotation::type_report_tsv(self : Annotation) -> String {
  let lines : Array[String] = ["feature_type\tcount\ttotal_bases"]
  for row in self.type_report() {
    lines.push("\{row.feature_type}\t\{row.count}\t\{row.total_bases}")
  }
  lines.join("\n") + "\n"
}

///|
pub fn Annotation::attribute_frequency_tsv(self : Annotation) -> String {
  let lines : Array[String] = ["attribute\tcount"]
  for row in self.attribute_frequencies() {
    lines.push("\{row.key}\t\{row.count}")
  }
  lines.join("\n") + "\n"
}

///|
pub fn TranscriptMetrics::to_tsv_row(self : TranscriptMetrics) -> String {
  [
    self.transcript_id,
    "\{self.exon_count}",
    "\{self.cds_count}",
    "\{self.utr_count}",
    "\{self.exon_bases}",
    "\{self.cds_bases}",
    "\{self.utr_bases}",
    "\{self.intron_count}",
    "\{self.intron_bases}",
    "\{self.span_bases}",
  ].join("\t")
}

///|
pub fn GeneMetrics::to_tsv_row(self : GeneMetrics) -> String {
  [
    self.gene_id,
    "\{self.transcript_count}",
    "\{self.total_exon_bases}",
    "\{self.total_cds_bases}",
    self.longest_transcript_id,
    "\{self.longest_transcript_bases}",
    "\{self.gene_span_bases}",
  ].join("\t")
}

///|
pub fn Annotation::transcript_metrics_tsv(self : Annotation) -> String {
  let lines : Array[String] = [
    "transcript_id\texon_count\tcds_count\tutr_count\texon_bases\tcds_bases\tutr_bases\tintron_count\tintron_bases\tspan_bases",
  ]
  for gene in self.to_gene_models() {
    for tx in gene.transcripts {
      lines.push(tx.metrics().to_tsv_row())
    }
  }
  lines.join("\n") + "\n"
}

///|
pub fn Annotation::gene_metrics_tsv(self : Annotation) -> String {
  let lines : Array[String] = [
    "gene_id\ttranscript_count\ttotal_exon_bases\ttotal_cds_bases\tlongest_transcript_id\tlongest_transcript_bases\tgene_span_bases",
  ]
  for gene in self.to_gene_models() {
    lines.push(gene.metrics().to_tsv_row())
  }
  lines.join("\n") + "\n"
}

///|
pub fn AnnotationMetrics::to_text(self : AnnotationMetrics) -> String {
  [
    "features\t\{self.feature_count}",
    "genes\t\{self.gene_count}",
    "transcripts\t\{self.transcript_count}",
    "exons\t\{self.exon_count}",
    "cds\t\{self.cds_count}",
    "seqids\t\{self.seqid_count}",
    "feature_bases\t\{self.total_feature_bases}",
  ].join("\n") +
  "\n"
}

///|
pub fn ValidationReport::summary_tsv(self : ValidationReport) -> String {
  [
    "severity\tcount",
    "error\t\{self.error_count()}",
    "warning\t\{self.warning_count()}",
    "info\t\{self.info_count()}",
  ].join("\n") +
  "\n"
}

///|
pub fn TypeReportRow::to_tsv_row(self : TypeReportRow) -> String {
  "\{self.feature_type}\t\{self.count}\t\{self.total_bases}"
}

///|
pub fn AttributeFrequency::to_tsv_row(self : AttributeFrequency) -> String {
  "\{self.key}\t\{self.count}"
}