From b4f26c12cc8bea6a051ef8953515c1c7b87e6f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Sj=C3=B6lund?= Date: Thu, 6 Feb 2020 09:59:14 +0100 Subject: [PATCH] Import version 1.2 from https://sourceforge.net/projects/abi2xml/ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Github provides better functionality than Sourceforge. Instead of using https://sourceforge.net/projects/abi2xml/ the development of abi2xml will continue at https://github.com/eriksjolund/abi2xml The file abi2xml-1.2.tar.gz was downloaded from https://sourceforge.net/projects/abi2xml/files/abi2xml/1.2/ and its contents were added to this git commit. According to the Sourceforge page the file was modified 3 April 2006. Signed-off-by: Erik Sjölund --- AUTHORS | 17 + COPYING | 340 ++++++++++++ ChangeLog | 16 + INSTALL | 18 + README | 44 ++ TODO | 15 + abi2xml.pro | 8 + src/abi2xml.cpp | 146 ++++++ src/abi2xml.h | 65 +++ src/datarecord.cpp | 411 +++++++++++++++ src/datarecord.h | 217 ++++++++ src/datarecordmaker.cpp | 192 +++++++ src/datarecordmaker.h | 72 +++ src/gengetopt/abi2xml.ggo | 27 + src/gengetopt/cmdline.c | 489 ++++++++++++++++++ src/gengetopt/cmdline.h | 68 +++ src/main.cpp | 168 ++++++ src/params.h | 40 ++ src/src.pro | 18 + xslt_examples/find_filename.xslt | 29 ++ .../find_unrecognized_data_structures.xslt | 41 ++ 21 files changed, 2441 insertions(+) create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 ChangeLog create mode 100644 INSTALL create mode 100644 README create mode 100644 TODO create mode 100644 abi2xml.pro create mode 100644 src/abi2xml.cpp create mode 100644 src/abi2xml.h create mode 100644 src/datarecord.cpp create mode 100644 src/datarecord.h create mode 100644 src/datarecordmaker.cpp create mode 100644 src/datarecordmaker.h create mode 100644 src/gengetopt/abi2xml.ggo create mode 100644 src/gengetopt/cmdline.c create mode 100644 src/gengetopt/cmdline.h create mode 100644 src/main.cpp create mode 100644 src/params.h create mode 100644 src/src.pro create mode 100644 xslt_examples/find_filename.xslt create mode 100644 xslt_examples/find_unrecognized_data_structures.xslt diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..30f847a --- /dev/null +++ b/AUTHORS @@ -0,0 +1,17 @@ +Design and implementation: Erik Sjolund +( Erik Sjönd ) +email: erik.sjolund@gmail.com + +in assignment from: +Martti Tammi and Erik Arner +Karolinska Insitutet, Stockholm, Sweden ( http://www.ki.se ) + +Many thanks to Martti Tammi and Erik Arner who gave me expert advice concerning +the Abi format. + +Many thanks to Clark Tibbetts for describing the ABI format in his publication +( see README file ) + +Erik Arner also provided valuable feedback and ideas about "polishing" the end +product. Some new command line flags arose that way. + diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..60549be --- /dev/null +++ b/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..2a90f95 --- /dev/null +++ b/ChangeLog @@ -0,0 +1,16 @@ +2005-11-26 Erik Sjolund + + * Release 1.1 + + * AUTHORS: typo fix + + * src/main.cpp: Add functionality to convert a whole directory of abi files + * src/gengetopt/abi2xml.ggo: Add command line flags for directory processing + +2006-03-30 Erik Sjolund + + * Release 1.2 + + * : ported the code to Qt 4.1 + + diff --git a/INSTALL b/INSTALL new file mode 100644 index 0000000..5cf9054 --- /dev/null +++ b/INSTALL @@ -0,0 +1,18 @@ +Prerequisites: You must have the qt library ( version >= 4.1 ) installed ( see http://www.trolltech.com ) + +For instance Fedora Core 4 is a Linux distribution where abi2xml is known to build. But first you need to download, build +and install Qt-4.1 first, as it is not included in Fedora Core 4. + +abi2xml is also known to build on Windows with Qt-4.1. The qt library is also available on MacOS, so abi2xml should probably work there too although +this has not yet been tested. + +To install this program on a Unix platform ( e.g. Linux ), follow these steps: + +1. qmake +2. make +3. make install + +You should then find the executable in the bin subdirectory. + + + diff --git a/README b/README new file mode 100644 index 0000000..3527000 --- /dev/null +++ b/README @@ -0,0 +1,44 @@ +This program parses the binary file format coming from a +ABI PRISM TM 377 DNA Sequencer and writes the information in +plain text to an xml file. + +The ABI file binary format is described in this publication: +http://www.cs.cmu.edu/afs/cs/project/genome/WWW/Papers/clark.html + + ------------------------------------------- + + Raw Data File Formats, + and the Digital and Analog Raw Data Streams + of the ABI PRISM TM 377 DNA Sequencer + + A preliminary technical examination + + by + + Clark Tibbetts, Ph. D. + Professor of Microbiology + + A5217 Medical Center North + Vanderbilt University + Nashville, TN 37232-2363 + + August 1995 + + ---------------------------------------------- + + +Usage: + abi2xml -i binaryfile -o xmlfile + +Other option flags are also available. To list them type "abi2xml --help". + +An xslt script can be useful when you want to retrieve information from the xml file. +Take a look in the xslt_examples sub directory. There you find some example scripts. + +You run a xslt script like this: +xsltproc xsltscript abi2xml-generated-xmlfile + +( xsltproc is a command line utility from the package libxslt ) + + + diff --git a/TODO b/TODO new file mode 100644 index 0000000..b4dc653 --- /dev/null +++ b/TODO @@ -0,0 +1,15 @@ +Todo list: + +* implement datarecord "KUKU" +* implement datarecord "THUM" +* implement datarecord "GELT" + +* implement a command line flag to list available codecs. + + Qt 4.0 has a new function to list available codecs. + http://doc.trolltech.com/4.0/qtextcodec.html + "QList availableCodecs ()" + + + + diff --git a/abi2xml.pro b/abi2xml.pro new file mode 100644 index 0000000..6e84908 --- /dev/null +++ b/abi2xml.pro @@ -0,0 +1,8 @@ +# File generated by kdevelop's qmake manager. +# ------------------------------------------- +# Subdir relative project main directory: . +# Target is a subdirs project + +TEMPLATE=subdirs +SUBDIRS += src + diff --git a/src/abi2xml.cpp b/src/abi2xml.cpp new file mode 100644 index 0000000..d3b434a --- /dev/null +++ b/src/abi2xml.cpp @@ -0,0 +1,146 @@ + + +/******************************************************************************* + * * + * Copyright (C) 2003 Erik Sjolund, (Erik Sjölund) * + * Center for Genomics and Bioinformatics, * + * Karolinska Institutet, * + * Stockholm, * + * Sweden * + * * + * Author: Erik Sjolund * + * Email: erik.sjolund@adivo.se * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + ******************************************************************************* + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include + +#include +#include + +#include "abi2xml.h" +#include "datarecordmaker.h" +#include "datarecord.h" +#include + +Abi2xml::Abi2xml( QDataStream & stream_, QDomElement parseRoot, Params *params_ ) + : stream ( stream_ ), params( params_ ) +{ + device = stream.device(); + domDoc = parseRoot.ownerDocument(); + domDataStructs = domDoc.createElement( "dataStructures" ); + parseRoot.appendChild( domDataStructs ); + parseInfo = domDoc.createElement( "parseInfo" ); + parseRoot.appendChild( parseInfo ); +} + Abi2xml::~Abi2xml() +{ +} + +void Abi2xml::parse() +{ + m_offset_to_ABIF = offset_to_ABIF(); + qint32 num_rec = num_records(); + qint32 offset_to_first = offset_to_first_record(); + quint16 blk_size = block_size(); + if ( blk_size != 28 ) + { + std::cerr << "Warning: Blocksize is not 28. Maybe you passed a non-valid indata file." << std::endl; + exit(1); + } + parseInfo.setAttribute("block_size" , blk_size); + parseInfo.setAttribute("offset_to_first_record",offset_to_first); + parseInfo.setAttribute("read_num_tagged_file_records",num_rec); + for ( int i=0 ; i< num_rec; ++i ) + { + qlonglong offset = offset_to_first + i * blk_size; + device->seek( offset ); + DataRecord * record = DataRecordMaker::newDataRecord( stream, m_offset_to_ABIF, params ); + Q_ASSERT( record ); + if ( record ) + { + QDomElement elem = domDoc.createElement( record->xmlElementName() ); + domDataStructs.appendChild( elem ); + record->produceDom( elem ); + } else + { + exit( 1 ); + } + } +} + +quint16 Abi2xml::block_size() +{ + device->seek( 16 + m_offset_to_ABIF ); + quint16 number; + stream >> number; + return number; +} + +qint32 Abi2xml::num_records() +{ + qint32 number = read_int32_at( 18 + m_offset_to_ABIF ); + return number; +} + +qint32 Abi2xml::offset_to_first_record() +{ + qint32 number = read_int32_at( 26 + m_offset_to_ABIF ); + return number + m_offset_to_ABIF; +} + +qint32 Abi2xml::read_int32_at( qlonglong offset ) +{ + device->seek( offset ); + qint32 number; + stream >> number; + return number; +} + +qint32 Abi2xml::offset_to_ABIF() +{ + qint32 index = 0; + qint32 size = device->size(); + int len = 5; + bool found = false; + while ( ( ! found && ( index <= size - len )) ) + { + device->seek( index ); + char array[ len ]; + stream.readRawData(&array[0], len ); + array[ len -1 ] = '\0'; + QString str = QString(&array[0]); + if ( str == "ABIF" ) { + found = true; + break; + } + ++index; + } + if ( ! found ) + { + std::cerr << "could not find a qualitive guess of the start position" << std::endl; + exit(1); + } + return index; +} diff --git a/src/abi2xml.h b/src/abi2xml.h new file mode 100644 index 0000000..4781e1a --- /dev/null +++ b/src/abi2xml.h @@ -0,0 +1,65 @@ +/******************************************************************************* + * * + * Copyright (C) 2003 Erik Sjolund, (Erik Sjölund) * + * Center for Genomics and Bioinformatics, * + * Karolinska Institutet, * + * Stockholm, * + * Sweden * + * * + * Author: Erik Sjolund * + * Email: erik.sjolund@adivo.se * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + ******************************************************************************* + */ + +#ifndef ABI2XML_H +#define ABI2XML_H + +// include files for QT + +#include +#include +#include + +class QDataStream; +class DataRecord; +struct Params; + +class Abi2xml +{ +public: + Abi2xml( QDataStream & stream, QDomElement, Params *params ); + ~Abi2xml(); + void parse(); + quint16 block_size(); + qint32 num_records( ); + qint32 offset_to_first_record(); + qint32 offset_to_ABIF(); +protected: + qint32 read_int32_at( qlonglong offset ); + QIODevice * device; + QDataStream & stream; + DataRecord * dataRecord; + QDomElement domDataStructs; + QDomElement parseInfo; + qint32 m_offset_to_ABIF; + QDomDocument domDoc; + Params *params; +}; + +#endif + diff --git a/src/datarecord.cpp b/src/datarecord.cpp new file mode 100644 index 0000000..8ee4bdf --- /dev/null +++ b/src/datarecord.cpp @@ -0,0 +1,411 @@ +/******************************************************************************* + * * + * Copyright (C) 2003 Erik Sjolund, (Erik Sjölund) * + * Center for Genomics and Bioinformatics, * + * Karolinska Institutet, * + * Stockholm, * + * Sweden * + * * + * Author: Erik Sjolund * + * Email: erik.sjolund@adivo.se * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + ******************************************************************************* + */ + +#include +#include +#include + +#include +#include +#include +#include +#include "datarecord.h" +#include "params.h" + +DataRecord::DataRecord( QDataStream & stream, qint32 offset_to_ABIF, Params * params_ ) +{ + params = params_; + QIODevice * dev = stream.device(); + original_offset = dev->pos(); + + tag_name[4]='\0'; /* let the fifth byte already have the null + to terminate the string */ + + stream.readRawData(&tag_name[0], 4); + stream + >> tag_number + >> data_type + >> element_length + >> number_of_elements + >> record_length; + + qlonglong data_record_offset = dev->pos(); + + stream >> data_record + >> cryptic_variable; + + if( record_length <= 4 ) + { + offset_to_data = data_record_offset; + } + else + { + offset_to_data = static_cast ( data_record + offset_to_ABIF ); + } + + /* the sub classes of DataRecord get a stream with the current position set + to where the data resides */ + if ( ! dev->seek( offset_to_data ) ) + { + qFatal("Couldn't seek to a data record in the file.\nThe file doesn't seem to follow the normal trace file layout\n"); + } +} + +void DataRecord::sanity_check( const qint32 * const tag_number_wanted, + const qint16 * const data_type_wanted, + const qint16 * const element_length_wanted, + const qint32 * const number_of_elements_wanted, + const qint32 * const record_length_wanted, + const qint32 * const data_record_wanted, + const qint32 * const cryptic_variable_wanted) +{ + if ( tag_number_wanted ) + sanity_check_value( tag_number, *tag_number_wanted, "tag_number"); + if ( data_type_wanted ) + sanity_check_value(data_type, *data_type_wanted, "data_type"); + if ( element_length_wanted ) + sanity_check_value(element_length, *element_length_wanted , "element_length"); + if ( number_of_elements_wanted ) + sanity_check_value( number_of_elements, *number_of_elements_wanted, "number_of_elements"); + if ( record_length_wanted ) + sanity_check_value( record_length, *record_length_wanted, "record_length"); + if ( data_record_wanted ) + sanity_check_value(data_record, *data_record_wanted , "data_record"); + if ( cryptic_variable_wanted ) + sanity_check_value( cryptic_variable, *cryptic_variable_wanted, "cryptic_variable"); +} + +void DataRecord::sanity_check_value( qint32 actual, qint32 correct, QString type ) +{ + if ( actual != correct ) + { + qFatal("Error: %s is %d but %d was expected for the %s",qPrintable(type),actual,correct,qPrintable(errorInfo())); + } +} + +QString DataRecord::errorInfo() +{ + QString str; + QTextStream ts( &str, QIODevice::WriteOnly ); + ts << " Datarecord parsed at offset=" << original_offset << " with " << endl + << " tag_name=" << tag_name << endl + << " tag_number" << tag_number << endl + << " data_type=" << data_type << endl + << " element_length=" << element_length << endl + << " number_of_elements=" << number_of_elements << endl + << " record_length=" << record_length << endl + << " data_record=" << data_record << endl + << " cryptic_variable=" << cryptic_variable << endl; + return str; +} + +void DataRecord::produceDom( QDomElement node ) { + node.setAttribute("tag_number", tag_number ); + QDomDocument doc = node.ownerDocument(); + QDomElement common = doc.createElement("common_data_struct"); + node.appendChild( common ); + common.setAttribute("name", tag_name ); + common.setAttribute("tag_number", tag_number ); + common.setAttribute("data_type", data_type ); + common.setAttribute("element_length" , element_length ); + common.setAttribute("number_of_elements", number_of_elements ); + common.setAttribute("record_length", record_length ); + common.setAttribute("data_record" , data_record ); + common.setAttribute("cryptic_variable", cryptic_variable ); + common.setAttribute("calculated_offset_to_data", static_cast< qint32 >( offset_to_data )); + + produceSpecialDom( node ); +} + +CStringDataRecord::CStringDataRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params_, qint16 data_type_wanted ) + : DataRecord( stream, offset_to_ABIF, params_ ) +{ + qint16 element_length_wanted = 1; + sanity_check( NULL, + &data_type_wanted, + &element_length_wanted); + char array[record_length + 1]; + stream.readRawData(&array[0], record_length ); + array[ record_length ] = '\0'; + Q_ASSERT( params->codec ); + str = params->codec->toUnicode( &array[0] ); +} + +void CStringDataRecord::produceSpecialDom( QDomElement node ) { + node.setAttribute( "string", str ); +} + +Int8VectorDataRecord::Int8VectorDataRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params_ ) + : DataRecord( stream, offset_to_ABIF, params_ ) +{ + qint16 data_type_wanted = 13; + qint16 element_length_wanted = 1; + sanity_check( NULL, + &data_type_wanted, + &element_length_wanted); + for ( int i = 0; i < number_of_elements ; ++i ) + { + qint8 value; + stream >> value; + dataVector.append( value ); + } +} + +void Int8VectorDataRecord::produceSpecialDom( QDomElement elem ) { + QVector::iterator it; + QDomDocument doc = elem.ownerDocument(); + + if ( params->int_vector_as_attribute ) + { + QString v; + it = dataVector.begin(); + while ( it != dataVector.end() ) + { + QString num; + num = num.setNum( *it ); + v.append( num ); + it++; + if ( it != dataVector.end() ) + { + v.append(" "); + } + } + elem.setAttribute("Int8Vector", v ); + } else + { + for( it = dataVector.begin(); it != dataVector.end(); ++it ) + { + QDomElement elem2 = doc.createElement("int8"); + elem.appendChild( elem2 ); + elem2.setAttribute("value", *it ); + } + } +}; + +Int16VectorDataRecord::Int16VectorDataRecord( QDataStream & stream, qint32 offset_to_ABIF , Params *params_ ) + : DataRecord( stream, offset_to_ABIF, params_ ) +{ + qint16 data_type_wanted = 4; + qint16 element_length_wanted = 2; + + /** There seems to be a bug in the ABI binary file format. + It is not following the scheme that rest of the elements have. + + Comparing + + name="LANE" tag_number="1" data_type="4" element_length="1" number_of_elements="2" record_length="2" + + with + + name="LPOS" tag_number="1" data_type="4" element_length="2" number_of_elements="1" record_length="2" + + my guess is that element_length and number_of_elements were accidently swapped. + **/ + + if ( xmlElementName() == "LANE" && tag_number == 1 && data_type == 4 && element_length == 1 + && number_of_elements == 2 && record_length == 2 ) + { + number_of_elements = 1; + element_length = 2; + } + + sanity_check( NULL, + &data_type_wanted, + &element_length_wanted); + + for ( int i = 0; i < number_of_elements ; ++i ) + { + qint16 value; + stream >> value; + dataVector.append( value ); + } +}; + +void Int16VectorDataRecord::produceSpecialDom( QDomElement elem ) { + QVector< qint16 >::iterator it; + QDomDocument doc = elem.ownerDocument(); + + if ( params->int_vector_as_attribute ) + { + QString v; + it = dataVector.begin(); + while ( it != dataVector.end() ) + { + QString num; + num = num.setNum( *it ); + v.append( num ); + it++; + if ( it != dataVector.end() ) + { + v.append(" "); + } + } + elem.setAttribute("Int16Vector", v ); + } else + { + for( it = dataVector.begin(); it != dataVector.end(); ++it ) + { + QDomElement elem2 = doc.createElement("int16"); + elem.appendChild( elem2 ); + elem2.setAttribute("value", *it ); + } + } +}; + +QString S_N_Record::xmlElementName() { + // If I recall correctly, this was because "S/N%" couldn't be used as an xml element name. + return QString( "S_divide_N_percent" ); +} + +PascalStringDataRecord::PascalStringDataRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params_ ) : DataRecord( stream, offset_to_ABIF, params_ ) +{ + qint16 data_type_wanted = 18; + qint16 element_length_wanted = 1; + + sanity_check( NULL, + &data_type_wanted, + &element_length_wanted); + str = getPascalString( stream, record_length, QString( tag_name ), params->codec ); +} + +void PascalStringDataRecord::produceSpecialDom( QDomElement node ) { + node.setAttribute( "string", str ); +} + +QString getPascalString( QDataStream & stream, qint32 record_len, QString tag_name, QTextCodec * codec ) +{ + char array[record_len + 1]; + array[ record_len ] = '\0'; + stream.readRawData(&array[0], record_len ); + qint8 length = ( char ) array[0]; /* pascal string has length stored */ + if ( length + 1 != record_len ) + { + qCritical("The first position of the pascal string doesn't match with recordlength\n( pascal string length %d + 1 != record_length %d\nThe error occured for tag name=\"%s\"",( qint16 ) length, record_len, qPrintable(tag_name)); + } + Q_ASSERT( codec ); + QString str = codec->toUnicode( &array[1] ); + return str; +} + +RUNDRecord::RUNDRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params_ ) + : DataRecord( stream, offset_to_ABIF, params_ ) +{ + qint16 data_type_wanted = 10; + qint16 element_length_wanted = 4; + qint32 number_of_elements_wanted = 1; + qint32 record_length_wanted = 4; + sanity_check( NULL, + &data_type_wanted, + &element_length_wanted, + &number_of_elements_wanted, + &record_length_wanted); + + stream >> year >> month >> day; +} + +RUNTRecord::RUNTRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params_ ) + : DataRecord( stream, offset_to_ABIF, params_ ) +{ + qint16 data_type_wanted = 11; + qint16 element_length_wanted = 4; + qint32 number_of_elements_wanted = 1; + qint32 record_length_wanted = 4; + sanity_check( NULL, + &data_type_wanted, + &element_length_wanted, + &number_of_elements_wanted, + &record_length_wanted); + + stream >> hour >> minute >> second; +} + +void RUNDRecord::produceSpecialDom( QDomElement node ) { + node.setAttribute( "year", year ); + node.setAttribute( "month", month ); + node.setAttribute( "day", day ); +} + +void RUNTRecord::produceSpecialDom( QDomElement node ) { + node.setAttribute( "hour", hour ); + node.setAttribute( "minute", minute ); + node.setAttribute( "second", second ); +} + +SPACRecord::SPACRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params_ ) + : DataRecord( stream, offset_to_ABIF, params_ ) +{ + /* This Tagged_Data_Record with the tag_name "SPAC" + is odd. The other data structs all have one single + data_type. But "SPAC" occurs with both data_type=7 + ( float ) and data_type=18 ( pascal string ). + Therefore we have to write this class with + "if"-cases. To let them be separated in the xml-output + we give the pascal string case a new element name - + "SPACSTRING". + */ + + if ( data_type == 18 && element_length == 1) + { + str = getPascalString( stream, record_length, QString( tag_name), params->codec ); + } + else + { + qint16 data_type_wanted = 7; + qint16 element_length_wanted = 4; + qint32 number_of_elements_wanted = 1; + qint32 record_length_wanted = 4; + sanity_check( NULL, + &data_type_wanted, + &element_length_wanted, + &number_of_elements_wanted, + &record_length_wanted); + + stream >> number; + } +} + +void SPACRecord::produceSpecialDom( QDomElement node ) +{ + if ( data_type == 18 && element_length == 1) + { + node.setAttribute( "string", str ); + } + else + node.setAttribute( "float", number ); +} + +QString SPACRecord::xmlElementName() +{ + if ( data_type == 18 && element_length == 1) + return QString("SPACSTRING"); + else + return QString("SPAC"); +} + +void UnknownRecord::produceSpecialDom( QDomElement ) { return; } +QString UnknownRecord::xmlElementName() { return QString( "Unknown" ); } diff --git a/src/datarecord.h b/src/datarecord.h new file mode 100644 index 0000000..875a275 --- /dev/null +++ b/src/datarecord.h @@ -0,0 +1,217 @@ + +/******************************************************************************* + * * + * Copyright (C) 2003 Erik Sjolund, (Erik Sjölund) * + * Center for Genomics and Bioinformatics, * + * Karolinska Institutet, * + * Stockholm, * + * Sweden * + * * + * Author: Erik Sjolund * + * Email: erik.sjolund@adivo.se * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + ******************************************************************************* + */ + +#ifndef DATARECORD_H +#define DATARECORD_H + +#include +#include + +class QTextCodec; +class QDataStream; + +struct Params; + +#include + + + + + +class DataRecord +{ +public: + DataRecord( QDataStream &, qint32 offset_to_ABIF, Params *params ); + virtual ~DataRecord() {} + virtual QString xmlElementName() { return QString( tag_name ); } + void produceDom( QDomElement ); +protected: + QString errorInfo(); + virtual void produceSpecialDom( QDomElement ) =0; + void sanity_check_value( qint32, qint32, QString ); + void sanity_check( const qint32 * const tag_number_wanted, + const qint16 * const data_type_wanted = NULL, + const qint16 * const element_length_wanted = NULL, + const qint32 * const number_of_elements_wanted = NULL, + const qint32 * const record_length_wanted = NULL, + const qint32 * const data_record_wanted = NULL, + const qint32 * const cryptic_variable_wanted = NULL); + qlonglong original_offset; + char tag_name[5]; + qint32 tag_number; + qint16 data_type; + qint16 element_length; + qint32 number_of_elements; + qint32 record_length; + qint32 data_record; + qint32 cryptic_variable; + qlonglong offset_to_data; + Params * params; +}; + +class CStringDataRecord : public DataRecord +{ +public: + CStringDataRecord( QDataStream & stream, qint32 offset_to_ABIF , Params *params, qint16 type = ( qint16 ) 2 ); + void produceSpecialDom( QDomElement ); +protected: + QString str; +}; + +class GELPRecord : public CStringDataRecord +{ + /* GELP has data type 18 and that would mean it has a pascal string + if it followed the pattern used elsewhere. The GELP + Tagged_Data_Record is also described as a pascal string in + the publication: + + ------------------------------------------- + + Raw Data File Formats, + and the Digital and Analog Raw Data Streams + of the ABI PRISM TM 377 DNA Sequencer + + A preliminary technical examination + + by + + Clark Tibbetts, Ph. D. + Professor of Microbiology + + A5217 Medical Center North + Vanderbilt University + Nashville, TN 37232-2363 + + August 1995 + tibbetts@ctrvax.vanderbilt.edu + + ---------------------------------------------- + + But it is a c string if you look at some + of the ABI files we have. Therefore we have + to inherit CStringDataRecord with additional + passing of data_type argument = 18 to + CStringDataRecord constructor. + */ +public: + GELPRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params ) : CStringDataRecord( stream, offset_to_ABIF , params, 18 ) {} +}; + +class PROJRecord : public CStringDataRecord +{ +public: + PROJRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params ) : CStringDataRecord( stream, offset_to_ABIF, params, 19 ) {} +}; + + +class Int8VectorDataRecord : public DataRecord +{ +public: + Int8VectorDataRecord( QDataStream & stream, qint32 offset_to_ABIF , Params *params ); + void produceSpecialDom( QDomElement ); +protected: + QVector dataVector; +}; + + +class Int16VectorDataRecord : public DataRecord +{ +public: + Int16VectorDataRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params ); + void produceSpecialDom( QDomElement ); +protected: + QVector< qint16 > dataVector; +}; + +class S_N_Record : public Int16VectorDataRecord +{ +public: + S_N_Record( QDataStream & stream, qint32 offset_to_ABIF, Params *params ) : Int16VectorDataRecord( stream, offset_to_ABIF, params) {} + QString xmlElementName(); +}; + + +class PascalStringDataRecord : public DataRecord +{ +public: + PascalStringDataRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params ); + void produceSpecialDom( QDomElement ); +protected: + QString str; +}; + +QString getPascalString( QDataStream & stream, qint32 record_len, QString, QTextCodec * ); + + +class RUNDRecord : public DataRecord +{ +public: + RUNDRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params ); + void produceSpecialDom( QDomElement ); +protected: + qint16 year; + qint8 month; + qint8 day; +}; + +class RUNTRecord : public DataRecord +{ +public: + RUNTRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params ); + void produceSpecialDom( QDomElement ); +protected: + /* the record_length is 4 but we have 3 qint8. Is it correct? */ + qint8 hour; + qint8 minute; + qint8 second; +}; + +class SPACRecord : public DataRecord +{ +public: + SPACRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params ); + ~SPACRecord() {} + void produceSpecialDom( QDomElement ); + QString xmlElementName(); +protected: + float number; + QString str; +}; + +class UnknownRecord : public DataRecord +{ + public: + /* this class is there to represent a datastructure that has not been recognized*/ + + UnknownRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params ) : DataRecord( stream, offset_to_ABIF, params ) {} + void produceSpecialDom( QDomElement ); + QString xmlElementName(); +}; + +#endif diff --git a/src/datarecordmaker.cpp b/src/datarecordmaker.cpp new file mode 100644 index 0000000..d381256 --- /dev/null +++ b/src/datarecordmaker.cpp @@ -0,0 +1,192 @@ +/******************************************************************************* + * * + * Copyright (C) 2003 Erik Sjolund, (Erik Sjölund) * + * Center for Genomics and Bioinformatics, * + * Karolinska Institutet, * + * Stockholm, * + * Sweden * + * * + * Author: Erik Sjolund * + * Email: erik.sjolund@adivo.se * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + ******************************************************************************* + */ + + +#include + +#include +#include +#include + +#include "datarecordmaker.h" +#include "datarecord.h" + +DataRecordMaker::MakerMap & DataRecordMaker::registry() { + /* from c++ faq lite + [10.12] How do I prevent the "static initialization order fiasco"? + We use this because static instances of sub classes of DataRecordMaker + make use of this map */ + static DataRecordMaker::MakerMap map; + return map; +} + +QString DataRecordMaker::getTagName( QDataStream & stream ) +{ + char tag_name[5]; + QIODevice * dev = stream.device(); + qlonglong offset = dev->pos(); + tag_name[4]='\0'; /* let the fifth byte already have the null + to terminate the string */ + stream.readRawData(tag_name, 4); + + // rewind, so that the DataRecord constructor also can read the tag_name + dev->seek( offset ); + return QString( tag_name ); +} + +DataRecord* DataRecordMaker::newDataRecord( QDataStream & stream, qint32 offset_to_ABIF, Params *params ) { + + + QString tag_name = getTagName(stream); + + DataRecord * rec = NULL; + + MakerMap::iterator iter; + + iter = registry().find( tag_name ); + + if ( iter != registry().end() ) + { + DataRecordMaker* maker = iter->second; + rec = maker->makeDataRecord( stream, offset_to_ABIF, params ); + } + else + { + rec = new UnknownRecord( stream, offset_to_ABIF, params ); + } + return rec; +} + +DataRecordMaker::DataRecordMaker( const QString & className ){ + registry().insert( std::make_pair(className, this) ); +} + +DataRecordMaker::~DataRecordMaker(){ +} + +/* +For explanation on: +How can I pass a "string literal" to a template? +see: +Comeau C++ Template FAQ +http://www.comeaucomputing.com/techtalk/templates/#stringliteral +*/ + + + + +char AEPt[]="AEPt"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char ASPF[]="ASPF"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char ASPt[]="ASPt"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char AUTO[]="AUTO"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char B1Pt[]="B1Pt"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char CAGT[]="CAGT"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char CMBF[]="CMBF"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char CMNT[]="CMNT"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char CTTL[]="CTTL"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char DATA[]="DATA"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char drty[]="drty"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char EVNT[]="EVNT"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char FWO_[]="FWO_"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char GELN[]="GELN"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char GELP[]="GELP"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char LANE[]="LANE"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char LIMC[]="LIMC"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char LIMS[]="LIMS"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char LPOS[]="LPOS"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char MTRX[]="MTRX"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char NAVG[]="NAVG"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char NLNE[]="NLNE"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char PBAS[]="PBAS"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char PDMF[]="PDMF"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char PLOC[]="PLOC"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char PPOS[]="PPOS"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char PROJ[]="PROJ"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char RUND[]="RUND"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char RUNT[]="RUNT"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char S_N_[]="S/N%"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char SMOD[]="SMOD"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char SMPL[]="SMPL"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char SPAC[]="SPAC"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char TRKC[]="TRKC"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char TRKP[]="TRKP"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char MCHN[]="MCHN"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char MODL[]="MODL"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char MTXF[]="MTXF"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char NChn[]="NChn"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char RSPN[]="RSPN"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char SRKP[]="SRKP"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char SVER[]="SVER"; +template const DataRecordMakerTP< PascalStringDataRecord ,SVER> DataRecordMakerTP::registerThis; +char TRKI[]="TRKI"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; +char User[]="User"; +template const DataRecordMakerTP DataRecordMakerTP::registerThis; + + diff --git a/src/datarecordmaker.h b/src/datarecordmaker.h new file mode 100644 index 0000000..cad6c0d --- /dev/null +++ b/src/datarecordmaker.h @@ -0,0 +1,72 @@ +/******************************************************************************* + * * + * Copyright (C) 2003 Erik Sjolund, (Erik Sjölund) * + * Center for Genomics and Bioinformatics, * + * Karolinska Institutet, * + * Stockholm, * + * Sweden * + * * + * Author: Erik Sjolund * + * Email: erik.sjolund@adivo.se * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + ******************************************************************************* + */ + +#ifndef DATARECORDMAKER_H +#define DATARECORDMAKER_H + +#include +class QDataStream; +class DataRecord; +struct Params; +/** + *@author + */ +class DataRecordMaker { +public: + static DataRecord* newDataRecord( QDataStream &, qint32 offset, Params *params ); + virtual ~DataRecordMaker(); +protected: + DataRecordMaker( const QString & className ); + typedef std::map MakerMap; + virtual DataRecord* makeDataRecord( QDataStream &, qint32 offset, Params *params ) const = 0; +private: + static QString getTagName( QDataStream & stream ); + static MakerMap & registry(); +}; + +template +class DataRecordMakerTP : public DataRecordMaker { +public: + ~DataRecordMakerTP() {} +private: + DataRecord* makeDataRecord( QDataStream &, qint32 offset, Params *params ) const; + DataRecordMakerTP( ) : DataRecordMaker( str ) {} + static const DataRecordMakerTP< T, str > registerThis; +}; + +template +DataRecord* DataRecordMakerTP::makeDataRecord( QDataStream & stream, qint32 offset, Params *params ) const +{ + return new T( stream, offset, params ); +} + +template const DataRecordMakerTP< T, str > DataRecordMakerTP< T, str >::registerThis; + + + +#endif diff --git a/src/gengetopt/abi2xml.ggo b/src/gengetopt/abi2xml.ggo new file mode 100644 index 0000000..3ddcfc5 --- /dev/null +++ b/src/gengetopt/abi2xml.ggo @@ -0,0 +1,27 @@ +# file abi2xml.ggo +# This file is used by the open source "gengetopt" program +# available from http://www.gnu.org +# Usage of that program +# does not impose any particular license on the generated code: +# +# This file is used to generate the files "cmdline.c" and +# "cmdline.c" + +package "abi2xml" +version "1.2" +purpose "This program parses the binary file format coming from an +ABI PRISM TM 377 DNA Sequencer and writes the information out as +an xml file" + +option "input-file" i "input abi file" string no +option "output-file" o "output xml file" string no +option "input-dir" I "input dir with abi files" string no +option "output-dir" O "output dir" string no +option "abi-file-suffix" s "suffix of abi files ( used with --input-dir )" string default="abi" no + +option "int-vector-as-attribute" a "write integer vectors inside attributes ( It makes file size smaller )" no + +option "input-encoding" e "input string encoding. Available encodings listed at: http://doc.trolltech.com/3.0/qtextcodec.html" string default="Apple Roman" no + +# Maybe add later? Not implemented right now. +# option "comments" c "write xml comments" no diff --git a/src/gengetopt/cmdline.c b/src/gengetopt/cmdline.c new file mode 100644 index 0000000..261b969 --- /dev/null +++ b/src/gengetopt/cmdline.c @@ -0,0 +1,489 @@ +/* + File autogenerated by gengetopt version 2.14 + generated with the following command: + /tmp/gengetopt-2.14/inst/bin/gengetopt -i abi2xml.ggo + + The developers of gengetopt consider the fixed text that goes in all + gengetopt output files to be in the public domain: + we make no copyright claims on it. +*/ + +/* If we use autoconf. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "getopt.h" + +#include "cmdline.h" + +static +void clear_given (struct gengetopt_args_info *args_info); +static +void clear_args (struct gengetopt_args_info *args_info); + +static int +cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error); + + +static char * +gengetopt_strdup (const char *s); + +static +void clear_given (struct gengetopt_args_info *args_info) +{ + args_info->help_given = 0 ; + args_info->version_given = 0 ; + args_info->input_file_given = 0 ; + args_info->output_file_given = 0 ; + args_info->input_dir_given = 0 ; + args_info->output_dir_given = 0 ; + args_info->abi_file_suffix_given = 0 ; + args_info->int_vector_as_attribute_given = 0 ; + args_info->input_encoding_given = 0 ; +} + +static +void clear_args (struct gengetopt_args_info *args_info) +{ + args_info->input_file_arg = NULL; + args_info->input_file_orig = NULL; + args_info->output_file_arg = NULL; + args_info->output_file_orig = NULL; + args_info->input_dir_arg = NULL; + args_info->input_dir_orig = NULL; + args_info->output_dir_arg = NULL; + args_info->output_dir_orig = NULL; + args_info->abi_file_suffix_arg = gengetopt_strdup ("abi"); + args_info->abi_file_suffix_orig = NULL; + args_info->input_encoding_arg = gengetopt_strdup ("Apple Roman"); + args_info->input_encoding_orig = NULL; + +} + +void +cmdline_parser_print_version (void) +{ + printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); +} + +void +cmdline_parser_print_help (void) +{ + cmdline_parser_print_version (); + printf("\n%s\n", "This program parses the binary file format coming from an\nABI PRISM TM 377 DNA Sequencer and writes the information out as \nan xml file"); + printf("\nUsage: abi2xml [OPTIONS]...\n\n"); + printf("%s\n"," -h, --help Print help and exit"); + printf("%s\n"," -V, --version Print version and exit"); + printf("%s\n"," -i, --input-file=STRING input abi file"); + printf("%s\n"," -o, --output-file=STRING output xml file"); + printf("%s\n"," -I, --input-dir=STRING input dir with abi files"); + printf("%s\n"," -O, --output-dir=STRING output dir"); + printf("%s\n"," -s, --abi-file-suffix=STRING suffix of abi files ( used with --input-dir ) \n (default=`abi')"); + printf("%s\n"," -a, --int-vector-as-attribute write integer vectors inside attributes ( It \n makes file size smaller )"); + printf("%s\n"," -e, --input-encoding=STRING input string encoding. Available encodings \n listed at: \n http://doc.trolltech.com/3.0/qtextcodec.html \n (default=`Apple Roman')"); + +} + +void +cmdline_parser_init (struct gengetopt_args_info *args_info) +{ + clear_given (args_info); + clear_args (args_info); +} + +static void +cmdline_parser_release (struct gengetopt_args_info *args_info) +{ + + if (args_info->input_file_arg) + { + free (args_info->input_file_arg); /* free previous argument */ + args_info->input_file_arg = 0; + } + if (args_info->input_file_orig) + { + free (args_info->input_file_orig); /* free previous argument */ + args_info->input_file_orig = 0; + } + if (args_info->output_file_arg) + { + free (args_info->output_file_arg); /* free previous argument */ + args_info->output_file_arg = 0; + } + if (args_info->output_file_orig) + { + free (args_info->output_file_orig); /* free previous argument */ + args_info->output_file_orig = 0; + } + if (args_info->input_dir_arg) + { + free (args_info->input_dir_arg); /* free previous argument */ + args_info->input_dir_arg = 0; + } + if (args_info->input_dir_orig) + { + free (args_info->input_dir_orig); /* free previous argument */ + args_info->input_dir_orig = 0; + } + if (args_info->output_dir_arg) + { + free (args_info->output_dir_arg); /* free previous argument */ + args_info->output_dir_arg = 0; + } + if (args_info->output_dir_orig) + { + free (args_info->output_dir_orig); /* free previous argument */ + args_info->output_dir_orig = 0; + } + if (args_info->abi_file_suffix_arg) + { + free (args_info->abi_file_suffix_arg); /* free previous argument */ + args_info->abi_file_suffix_arg = 0; + } + if (args_info->abi_file_suffix_orig) + { + free (args_info->abi_file_suffix_orig); /* free previous argument */ + args_info->abi_file_suffix_orig = 0; + } + if (args_info->input_encoding_arg) + { + free (args_info->input_encoding_arg); /* free previous argument */ + args_info->input_encoding_arg = 0; + } + if (args_info->input_encoding_orig) + { + free (args_info->input_encoding_orig); /* free previous argument */ + args_info->input_encoding_orig = 0; + } + + clear_given (args_info); +} + +int +cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info) +{ + FILE *outfile; + int i = 0; + + outfile = fopen(filename, "w"); + + if (!outfile) + { + fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename); + return EXIT_FAILURE; + } + + if (args_info->help_given) { + fprintf(outfile, "%s\n", "help"); + } + if (args_info->version_given) { + fprintf(outfile, "%s\n", "version"); + } + if (args_info->input_file_given) { + if (args_info->input_file_orig) { + fprintf(outfile, "%s=\"%s\"\n", "input-file", args_info->input_file_orig); + } else { + fprintf(outfile, "%s\n", "input-file"); + } + } + if (args_info->output_file_given) { + if (args_info->output_file_orig) { + fprintf(outfile, "%s=\"%s\"\n", "output-file", args_info->output_file_orig); + } else { + fprintf(outfile, "%s\n", "output-file"); + } + } + if (args_info->input_dir_given) { + if (args_info->input_dir_orig) { + fprintf(outfile, "%s=\"%s\"\n", "input-dir", args_info->input_dir_orig); + } else { + fprintf(outfile, "%s\n", "input-dir"); + } + } + if (args_info->output_dir_given) { + if (args_info->output_dir_orig) { + fprintf(outfile, "%s=\"%s\"\n", "output-dir", args_info->output_dir_orig); + } else { + fprintf(outfile, "%s\n", "output-dir"); + } + } + if (args_info->abi_file_suffix_given) { + if (args_info->abi_file_suffix_orig) { + fprintf(outfile, "%s=\"%s\"\n", "abi-file-suffix", args_info->abi_file_suffix_orig); + } else { + fprintf(outfile, "%s\n", "abi-file-suffix"); + } + } + if (args_info->int_vector_as_attribute_given) { + fprintf(outfile, "%s\n", "int-vector-as-attribute"); + } + if (args_info->input_encoding_given) { + if (args_info->input_encoding_orig) { + fprintf(outfile, "%s=\"%s\"\n", "input-encoding", args_info->input_encoding_orig); + } else { + fprintf(outfile, "%s\n", "input-encoding"); + } + } + + fclose (outfile); + + i = EXIT_SUCCESS; + return i; +} + +void +cmdline_parser_free (struct gengetopt_args_info *args_info) +{ + cmdline_parser_release (args_info); +} + + +/* gengetopt_strdup() */ +/* strdup.c replacement of strdup, which is not standard */ +char * +gengetopt_strdup (const char *s) +{ + char *result = NULL; + if (!s) + return result; + + result = (char*)malloc(strlen(s) + 1); + if (result == (char*)0) + return (char*)0; + strcpy(result, s); + return result; +} + +int +cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info) +{ + return cmdline_parser2 (argc, argv, args_info, 0, 1, 1); +} + +int +cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required) +{ + int result; + + result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL); + + if (result == EXIT_FAILURE) + { + cmdline_parser_free (args_info); + exit (EXIT_FAILURE); + } + + return result; +} + +int +cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name) +{ + return EXIT_SUCCESS; +} + +int +cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error) +{ + int c; /* Character of the parsed option. */ + + int error = 0; + struct gengetopt_args_info local_args_info; + + if (initialize) + cmdline_parser_init (args_info); + + cmdline_parser_init (&local_args_info); + + optarg = 0; + optind = 1; + opterr = 1; + optopt = '?'; + + while (1) + { + int option_index = 0; + char *stop_char; + + static struct option long_options[] = { + { "help", 0, NULL, 'h' }, + { "version", 0, NULL, 'V' }, + { "input-file", 1, NULL, 'i' }, + { "output-file", 1, NULL, 'o' }, + { "input-dir", 1, NULL, 'I' }, + { "output-dir", 1, NULL, 'O' }, + { "abi-file-suffix", 1, NULL, 's' }, + { "int-vector-as-attribute", 0, NULL, 'a' }, + { "input-encoding", 1, NULL, 'e' }, + { NULL, 0, NULL, 0 } + }; + + stop_char = 0; + c = getopt_long (argc, argv, "hVi:o:I:O:s:ae:", long_options, &option_index); + + if (c == -1) break; /* Exit from `while (1)' loop. */ + + switch (c) + { + case 'h': /* Print help and exit. */ + cmdline_parser_print_help (); + cmdline_parser_free (&local_args_info); + exit (EXIT_SUCCESS); + + case 'V': /* Print version and exit. */ + cmdline_parser_print_version (); + cmdline_parser_free (&local_args_info); + exit (EXIT_SUCCESS); + + case 'i': /* input abi file. */ + if (local_args_info.input_file_given) + { + fprintf (stderr, "%s: `--input-file' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->input_file_given && ! override) + continue; + local_args_info.input_file_given = 1; + args_info->input_file_given = 1; + if (args_info->input_file_arg) + free (args_info->input_file_arg); /* free previous string */ + args_info->input_file_arg = gengetopt_strdup (optarg); + if (args_info->input_file_orig) + free (args_info->input_file_orig); /* free previous string */ + args_info->input_file_orig = gengetopt_strdup (optarg); + break; + + case 'o': /* output xml file. */ + if (local_args_info.output_file_given) + { + fprintf (stderr, "%s: `--output-file' (`-o') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->output_file_given && ! override) + continue; + local_args_info.output_file_given = 1; + args_info->output_file_given = 1; + if (args_info->output_file_arg) + free (args_info->output_file_arg); /* free previous string */ + args_info->output_file_arg = gengetopt_strdup (optarg); + if (args_info->output_file_orig) + free (args_info->output_file_orig); /* free previous string */ + args_info->output_file_orig = gengetopt_strdup (optarg); + break; + + case 'I': /* input dir with abi files. */ + if (local_args_info.input_dir_given) + { + fprintf (stderr, "%s: `--input-dir' (`-I') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->input_dir_given && ! override) + continue; + local_args_info.input_dir_given = 1; + args_info->input_dir_given = 1; + if (args_info->input_dir_arg) + free (args_info->input_dir_arg); /* free previous string */ + args_info->input_dir_arg = gengetopt_strdup (optarg); + if (args_info->input_dir_orig) + free (args_info->input_dir_orig); /* free previous string */ + args_info->input_dir_orig = gengetopt_strdup (optarg); + break; + + case 'O': /* output dir. */ + if (local_args_info.output_dir_given) + { + fprintf (stderr, "%s: `--output-dir' (`-O') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->output_dir_given && ! override) + continue; + local_args_info.output_dir_given = 1; + args_info->output_dir_given = 1; + if (args_info->output_dir_arg) + free (args_info->output_dir_arg); /* free previous string */ + args_info->output_dir_arg = gengetopt_strdup (optarg); + if (args_info->output_dir_orig) + free (args_info->output_dir_orig); /* free previous string */ + args_info->output_dir_orig = gengetopt_strdup (optarg); + break; + + case 's': /* suffix of abi files ( used with --input-dir ). */ + if (local_args_info.abi_file_suffix_given) + { + fprintf (stderr, "%s: `--abi-file-suffix' (`-s') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->abi_file_suffix_given && ! override) + continue; + local_args_info.abi_file_suffix_given = 1; + args_info->abi_file_suffix_given = 1; + if (args_info->abi_file_suffix_arg) + free (args_info->abi_file_suffix_arg); /* free previous string */ + args_info->abi_file_suffix_arg = gengetopt_strdup (optarg); + if (args_info->abi_file_suffix_orig) + free (args_info->abi_file_suffix_orig); /* free previous string */ + args_info->abi_file_suffix_orig = gengetopt_strdup (optarg); + break; + + case 'a': /* write integer vectors inside attributes ( It makes file size smaller ). */ + if (local_args_info.int_vector_as_attribute_given) + { + fprintf (stderr, "%s: `--int-vector-as-attribute' (`-a') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->int_vector_as_attribute_given && ! override) + continue; + local_args_info.int_vector_as_attribute_given = 1; + args_info->int_vector_as_attribute_given = 1; + break; + + case 'e': /* input string encoding. Available encodings listed at: http://doc.trolltech.com/3.0/qtextcodec.html. */ + if (local_args_info.input_encoding_given) + { + fprintf (stderr, "%s: `--input-encoding' (`-e') option given more than once%s\n", argv[0], (additional_error ? additional_error : "")); + goto failure; + } + if (args_info->input_encoding_given && ! override) + continue; + local_args_info.input_encoding_given = 1; + args_info->input_encoding_given = 1; + if (args_info->input_encoding_arg) + free (args_info->input_encoding_arg); /* free previous string */ + args_info->input_encoding_arg = gengetopt_strdup (optarg); + if (args_info->input_encoding_orig) + free (args_info->input_encoding_orig); /* free previous string */ + args_info->input_encoding_orig = gengetopt_strdup (optarg); + break; + + + case 0: /* Long option with no short option */ + case '?': /* Invalid option. */ + /* `getopt_long' already printed an error message. */ + goto failure; + + default: /* bug: option not considered. */ + fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : "")); + abort (); + } /* switch */ + } /* while */ + + + + + cmdline_parser_release (&local_args_info); + + if ( error ) + return (EXIT_FAILURE); + + return 0; + +failure: + + cmdline_parser_release (&local_args_info); + return (EXIT_FAILURE); +} diff --git a/src/gengetopt/cmdline.h b/src/gengetopt/cmdline.h new file mode 100644 index 0000000..8879775 --- /dev/null +++ b/src/gengetopt/cmdline.h @@ -0,0 +1,68 @@ +/* cmdline.h */ + +/* File autogenerated by gengetopt version 2.14 */ + +#ifndef CMDLINE_H +#define CMDLINE_H + +/* If we use autoconf. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#ifndef CMDLINE_PARSER_PACKAGE +#define CMDLINE_PARSER_PACKAGE "abi2xml" +#endif + +#ifndef CMDLINE_PARSER_VERSION +#define CMDLINE_PARSER_VERSION "1.2" +#endif + +struct gengetopt_args_info +{ + char * input_file_arg; /* input abi file. */ + char * input_file_orig; /* input abi file original value given at command line. */ + char * output_file_arg; /* output xml file. */ + char * output_file_orig; /* output xml file original value given at command line. */ + char * input_dir_arg; /* input dir with abi files. */ + char * input_dir_orig; /* input dir with abi files original value given at command line. */ + char * output_dir_arg; /* output dir. */ + char * output_dir_orig; /* output dir original value given at command line. */ + char * abi_file_suffix_arg; /* suffix of abi files ( used with --input-dir ) (default='abi'). */ + char * abi_file_suffix_orig; /* suffix of abi files ( used with --input-dir ) original value given at command line. */ + char * input_encoding_arg; /* input string encoding. Available encodings listed at: http://doc.trolltech.com/3.0/qtextcodec.html (default='Apple Roman'). */ + char * input_encoding_orig; /* input string encoding. Available encodings listed at: http://doc.trolltech.com/3.0/qtextcodec.html original value given at command line. */ + + int help_given ; /* Whether help was given. */ + int version_given ; /* Whether version was given. */ + int input_file_given ; /* Whether input-file was given. */ + int output_file_given ; /* Whether output-file was given. */ + int input_dir_given ; /* Whether input-dir was given. */ + int output_dir_given ; /* Whether output-dir was given. */ + int abi_file_suffix_given ; /* Whether abi-file-suffix was given. */ + int int_vector_as_attribute_given ; /* Whether int-vector-as-attribute was given. */ + int input_encoding_given ; /* Whether input-encoding was given. */ + +} ; + +int cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info); +int cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required); +int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info); + +void cmdline_parser_print_help(void); +void cmdline_parser_print_version(void); + +void cmdline_parser_init (struct gengetopt_args_info *args_info); +void cmdline_parser_free (struct gengetopt_args_info *args_info); + +int cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name); + + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* CMDLINE_H */ diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..0b70526 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,168 @@ +/******************************************************************************* + * * + * Copyright (C) 2003 Erik Sjolund, (Erik Sjölund) * + * Center for Genomics and Bioinformatics, * + * Karolinska Institutet, * + * Stockholm, * + * Sweden * + * * + * Author: Erik Sjolund * + * Email: erik.sjolund@adivo.se * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + ******************************************************************************* + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gengetopt/cmdline.h" +#include "abi2xml.h" +#include "params.h" + + +void convert(QString ifile, QString ofile); + +void convert(QString ifilename, QString ofilename, Params * params ) +{ + + QFile ifile( ifilename ); + if ( ! ifile.open( QIODevice::ReadOnly ) ) + { + qFatal( "could not open input file: %s\n",qPrintable(ifilename)); + } + + QDataStream stream( &ifile ); // read the data serialized from the file + stream.setByteOrder( QDataStream::BigEndian ); + + QDomDocument domDoc("Abi2xml"); + QString content(""); + domDoc.setContent(content); + + QString commentStr = QString(" This file was generated by abi2xml %2 ").arg( CMDLINE_PARSER_VERSION ); + QDomComment comment = domDoc.createComment( commentStr ); + domDoc.appendChild( comment ); + + QDomElement rootElem = domDoc.createElement("root"); + domDoc.appendChild( rootElem ); + + QDomElement abiFileElem = domDoc.createElement("abiFile"); + rootElem.appendChild( abiFileElem ); + abiFileElem.setAttribute("filename",ifilename); + + Abi2xml parser( stream, abiFileElem, params ); + parser.parse(); + + QFile ofile( ofilename ); + if ( ! ofile.open( QIODevice::WriteOnly ) ) + { + qFatal( "could not open output file: %s\n",qPrintable(ofilename)); + } + + QTextStream ostream( &ofile ); // read the data serialized from the file + ostream.setCodec( QTextCodec::codecForName("UTF-8") ); + QString xml = domDoc.toString(); + ostream << xml << endl; +}; + + +int main(int argc, char *argv[]) +{ + /* Here we are using gengetopt to parse our command line arguments + * for more info see http://www.gnu.org/software/gengetopt/gengetopt.html + */ + + gengetopt_args_info args_info; + if (cmdline_parser (argc, argv, &args_info) != 0) + { + exit(1) ; + } + + QTextCodec *codec; + + codec = QTextCodec::codecForName( args_info.input_encoding_arg ); + if ( ! codec ) + { + QString allCodecs; + QList availableCodecs = QTextCodec::availableCodecs(); + for (int i = 0; i < availableCodecs.size(); ++i ) + { + allCodecs.append( availableCodecs[i] ).append("\n"); + } + qFatal("The QTextCodec class does not support the encoding \"%s\"\nThe available encodings are:\n %s", args_info.input_encoding_arg, qPrintable(allCodecs) ); + } + Params params; + params.codec = codec; + params.int_vector_as_attribute = args_info.int_vector_as_attribute_given; + + if (( args_info.input_file_given || args_info.output_file_given ) && + ( args_info.input_dir_given || args_info.output_dir_given )) + { + qFatal("Use either the flag combination -i and -o or the combination -O and -I" ); + } + if ( args_info.input_dir_given && ! args_info.output_dir_given ) + { + qFatal("The --input-dir flag requries the --output-dir flag"); + } + if ( ! args_info.input_dir_given && args_info.output_dir_given ) + { + qFatal("The --output-dir flag requries the --input-dir flag"); + } + if ( args_info.input_dir_given && args_info.output_dir_given ) + { + QDir d( args_info.input_dir_arg ); + d.setFilter( QDir::Files ); + QString suffix = QString( args_info.abi_file_suffix_arg ); + QRegExp rx( "\\W" ); /** matches any non-word-character **/ + if ( rx.indexIn( suffix ) != -1 ) + { + qFatal("--abi-file-suffix can only contain letters, numbers and _"); + } + + QStringList list = d.entryList( QStringList("*." + suffix) ); + for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + QString ofilename = *it; + ofilename.truncate( ofilename.length() - suffix.length() ); + ofilename.append( "xml" ); + QString ifilename2 = QString( args_info.input_dir_arg ) + QDir::separator () + *it; + QString ofilename2 = QString( args_info.output_dir_arg ) + QDir::separator () + ofilename; + convert( ifilename2 , ofilename2 , ¶ms ); + } + } + if ( args_info.input_file_given && ! args_info.output_file_given ) + { + qFatal("The --input-file flag requries the --output-file flag"); + } + if ( ! args_info.input_file_given && args_info.output_file_given ) + { + qFatal("The --output-file flag requries the --input-file flag"); + } + if ( args_info.input_file_given && args_info.output_file_given ) + { + if ( args_info.abi_file_suffix_given ) + { + qFatal("The flag --abi-file-suffix can not be used with --input-file"); + } + convert( QString( args_info.input_file_arg ), QString( args_info.output_file_arg ) , ¶ms ); + } +} + diff --git a/src/params.h b/src/params.h new file mode 100644 index 0000000..601f9bf --- /dev/null +++ b/src/params.h @@ -0,0 +1,40 @@ +/******************************************************************************* + * * + * Copyright (C) 2003 Erik Sjolund, (Erik Sjölund) * + * Center for Genomics and Bioinformatics, * + * Karolinska Institutet, * + * Stockholm, * + * Sweden * + * * + * Author: Erik Sjolund * + * Email: erik.sjolund@adivo.se * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the Free Software * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * * + ******************************************************************************* + */ + +#ifndef PARAMS_H +#define PARAMS_H + +#include + +struct Params +{ + QTextCodec *codec; + bool int_vector_as_attribute; +}; + +#endif diff --git a/src/src.pro b/src/src.pro new file mode 100644 index 0000000..bb467d6 --- /dev/null +++ b/src/src.pro @@ -0,0 +1,18 @@ +TEMPLATE+=app +TARGET=../bin/abi2xml +DEFINES += HAVE_GETOPT_LONG HAVE_STRDUP + + +SOURCES += main.cpp \ + abi2xml.cpp \ + datarecord.cpp \ + datarecordmaker.cpp \ + gengetopt/cmdline.c +HEADERS += abi2xml.h \ + datarecord.h \ + datarecordmaker.h \ + gengetopt/cmdline.h \ + params.h +CONFIG += qt console + +QT += xml diff --git a/xslt_examples/find_filename.xslt b/xslt_examples/find_filename.xslt new file mode 100644 index 0000000..f720dfe --- /dev/null +++ b/xslt_examples/find_filename.xslt @@ -0,0 +1,29 @@ + + + + + + Filename= + + + + + diff --git a/xslt_examples/find_unrecognized_data_structures.xslt b/xslt_examples/find_unrecognized_data_structures.xslt new file mode 100644 index 0000000..6e8a224 --- /dev/null +++ b/xslt_examples/find_unrecognized_data_structures.xslt @@ -0,0 +1,41 @@ + + + + + + +Here is a list of all datatstructures that were not recognized. +You have to modify the source code to add functionality for these. +( The list may be empty ) +------------------------------------------------------------------ + + + name= + + data_type= + + tag_number= + + + + + +