1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
#include "muscle.h"
#include <stdio.h>
#include <ctype.h>
#include "msa.h"
#include "textfile.h"
const unsigned FASTA_BLOCK = 60;
void MSA::FromFASTAFile(TextFile &File)
{
Clear();
FILE *f = File.GetStdioFile();
unsigned uSeqCount = 0;
unsigned uColCount = uInsane;
for (;;)
{
char *Label;
unsigned uSeqLength;
char *SeqData = GetFastaSeq(f, &uSeqLength, &Label, false);
if (0 == SeqData)
break;
AppendSeq(SeqData, uSeqLength, Label);
}
}
void MSA::ToFASTAFile(TextFile &File) const
{
const unsigned uColCount = GetColCount();
assert(uColCount > 0);
const unsigned uLinesPerSeq = (GetColCount() - 1)/FASTA_BLOCK + 1;
const unsigned uSeqCount = GetSeqCount();
for (unsigned uSeqIndex = 0; uSeqIndex < uSeqCount; ++uSeqIndex)
{
File.PutString(">");
File.PutString(GetSeqName(uSeqIndex));
File.PutString("\n");
unsigned n = 0;
for (unsigned uLine = 0; uLine < uLinesPerSeq; ++uLine)
{
unsigned uLetters = uColCount - uLine*FASTA_BLOCK;
if (uLetters > FASTA_BLOCK)
uLetters = FASTA_BLOCK;
for (unsigned i = 0; i < uLetters; ++i)
{
char c = GetChar(uSeqIndex, n);
File.PutChar(c);
++n;
}
File.PutChar('\n');
}
}
}
|