source: branches/alilink/GDE/MUSCLE/src/fasta.cpp

Last change on this file was 10390, checked in by aboeckma, 12 years ago

added muscle sourcles amd makefile

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