toFASTA method

Future<void> toFASTA({
  1. required String path,
  2. required String filename,
})

Saves this sequence to a local file in FASTA format.

dna.toFASTA(path: '../deliverables', filename: 'fasta_output');

Implementation

Future<void> toFASTA({required String path, required String filename}) async {
  final String metadata = '>${this._id} ${this._desc}\n';
  String seq = '';
  int lineLen = 0;
  for (var mon in this._seq.split('')) {
    lineLen++;
    // Each sequence line should be at most 60 characters long.
    if (lineLen % 60 == 0) {
      // [lineLen] is a multiple of 60 so start a new line.
      seq += '$mon\n';
    } else {
      seq += '$mon';
    }
  }
  final String fileData = metadata + seq;
  final String filen = filename.toLowerCase().trim();
  await File('$path/$filen.txt').writeAsString(fileData);
}