# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 2.0
#
# The contents of this file are subject to the Mozilla Public License Version
# 2.0 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/2.0/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is OMA standalone.
#
# The Initial Developer of the Original Code is CBRG Research Group; 
# ETH Zurich; Switzerland.
# Portions created by the Initial Developer are Copyright (C) 2005-2013
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Christophe Dessimoz <cdessimoz@inf.ethz.ch>
#   Adrian Altenhoff <adrian.altenhoff@inf.ethz.ch>
#   Stefan Zoller <stefan.zoller@inf.ethz.ch>
#   Adrian Schneider <adrian.schneider@inf.ethz.ch>
#   Alexander Roth <alexander.roth@inf.ethz.ch>
#   Gaston Gonnet <gonnet@inf.ethz.ch>
#
# ***** END LICENSE BLOCK *****
# Convert {DNA,Protein} sequences from the current database (DB) into fasta format
#   23.2.2005, C. Dessimoz (based on the code of M. Friberg)

PrintEntryInFasta := proc( e:Entry, seqtag:string )
    option internal;
    printf('>%s_%d\n', SearchTag('5LETTERNAME', DB[string]), GetEntryNumber(e));
    s := SearchTag(seqtag, e);
    for i to length(s) by 80 do
        printf('%s\n', s[i..min(length(s), i+79)]) 
    od;
end;

DbToFasta := proc( fastafile:string, seqtag:string )
    prev := Set(quiet=true);
    OpenWriting(fastafile);
    for e in Entries() do
        PrintEntryInFasta(e, seqtag); 
    od;
    OpenWriting(previous);
    Set(quiet=prev);
end;

