readFASTA static method
Returns sequences from either a file path
or str
in FASTA format.
Each map contains a sequence seq
, ID id
, and description desc
.
Implementation
static Future<List<Map<String, String>>> readFASTA({String? path, String? str}) async {
String? contents;
if (path != null) {
contents = await File(path).readAsString();
} else if (str != null) {
contents = str;
} else {
Errors.invalidFASTAArgs();
}
List<String> lines = contents!.split('\n');
int seqCount = 0;
List<Map<String, String>> fastaMaps = [];
Map<String, String> currentMap = {};
for (var line in lines) {
if (line.startsWith('>')) {
if (seqCount != 0) {
fastaMaps.add(currentMap);
currentMap = {};
}
seqCount++;
currentMap[kSeq] = '';
String topLine = line.split('>')[1];
List<String> topLineList = topLine.split(' ');
currentMap[kId] = topLineList.first;
currentMap[kDesc] = topLineList.sublist(1, topLineList.length).join(" ");
} else {
currentMap[kSeq] = currentMap[kSeq]! + line;
}
}
fastaMaps.add(currentMap);
return fastaMaps;
}