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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
/* asndhuff.c
* ===========================================================================
*
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information
*
* This software/database is a "United States Government Work" under the
* terms of the United States Copyright Act. It was written as part of
* the author's official duties as a United States Government employee and
* thus cannot be copyrighted. This software/database is freely available
* to the public for use. The National Library of Medicine and the U.S.
* Government have not placed any restriction on its use or reproduction.
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the NLM and the U.S.
* Government do not and cannot warrant the performance or results that
* may be obtained by using this software or data. The NLM and the U.S.
* Government disclaim all warranties, express or implied, including
* warranties of performance, merchantability or fitness for any particular
* purpose.
*
* Please cite the author in any work or product based on this material.
*
* ===========================================================================
*
* RCS $Id: asndhuff.c,v 6.1 1998/06/12 19:27:02 kans Exp $
*
* Author: Greg Schuler
*
* Version Creation Date: 9/23/92
*
* File Description:
asndhuff -- decompresses a compressed ASN,1 (CASN) file.
A Simple program to demonstrate the functions in casn.c
*
* Modifications:
* --------------------------------------------------------------------------
* Date Name Description of modification
* -------- ---------- -----------------------------------------------------
* 03-22-95 Schuler Added cases for all current doc types
* 03-22-95 Schuler Use MonitorPtr instead of Handles for Monitors
*
* ==========================================================================
*/
#include <casn.h>
#define REVISION_STR "$Revision: 6.1 $"
void do_medline PROTO((CASN_Handle casnh, AsnIoPtr aout));
void do_sequence PROTO((CASN_Handle casnh, AsnIoPtr aout));
void stream_medline PROTO((AsnIoPtr ain));
void stream_sequence PROTO((AsnIoPtr ain));
#define NUMARGS 2
Args myargs[NUMARGS] = {
{ "Input file", NULL, NULL, NULL, FALSE, 'i', ARG_FILE_IN, 0.0,0,NULL},
{ "Output file", NULL, NULL, NULL, TRUE, 'o', ARG_FILE_OUT, 0.0,0,NULL}};
Int2 Main (void)
{
CASN_Handle casnh;
AsnIoPtr aout, ain;
if (! GetArgs("AsnDHuff 1.0", NUMARGS, myargs))
return 1;
if (! SeqEntryLoad())
{
ErrShow();
return 1;
}
if ((casnh = CASN_Open(myargs[0].strvalue)) == NULL)
{
ErrShow();
return 1;
}
/*****************************************************************
*
* this part reads complete entries from compressed file and writes
* them to an uncompressed file
* if output file not given, it skips this step
******************************************************************/
if (myargs[1].strvalue != NULL)
{
if ((aout = AsnIoOpen(myargs[1].strvalue,"wb")) ==NULL)
{
Message(MSG_FATAL, "Can't create %s\n", myargs[1].strvalue);
return 1;
}
switch (CASN_DocType(casnh))
{
case CASN_TypeMed : /* obsolete */
case CASN_Type_ml :
do_medline(casnh,aout);
break;
case CASN_TypeSeq : /* obsolete */
case CASN_Type_aa :
case CASN_Type_nt :
do_sequence(casnh,aout);
break;
default :
Message(MSG_ERROR,"Unknown document type");
break;
}
AsnIoClose(aout);
CASN_Close(casnh); /* close and reopen file */
if ((casnh = CASN_Open(myargs[0].strvalue)) == NULL)
{
ErrShow();
return 1;
}
}
/*************************************************************************
*
* This part processes the compressed file as a regular asn stream
* displaying title lines for sequence or medline records.
* if output file IS given, it skips this step
*
*************************************************************************/
if (myargs[1].strvalue == NULL)
{
ain = CASN_GetAsnIoPtr(casnh); /* get the stream pointer */
switch (CASN_DocType(casnh))
{
case CASN_TypeMed : /* obsolete */
case CASN_Type_ml :
stream_medline(ain);
break;
case CASN_TypeSeq : /* obsolete */
case CASN_Type_aa :
case CASN_Type_nt :
stream_sequence(ain);
break;
default :
Message(MSG_ERROR,"Unknown document type");
break;
}
}
CASN_Close(casnh);
return 0;
}
void do_medline (CASN_Handle casnh, AsnIoPtr aout)
{
MedlineEntryPtr entry;
DataVal val;
Int4 total, count;
AsnModulePtr amp = AsnAllModPtr();
AsnTypePtr typePubSet = AsnTypeFind(amp,"Pub-set");
AsnTypePtr typeMedline = AsnTypeFind(amp,"Pub-set.medline");
AsnTypePtr typeMedlineE = AsnTypeFind(amp,"Pub-set.medline.E");
Monitor *pmonitor;
total = CASN_DocCount(casnh);
pmonitor = MonitorIntNew("MEDLINE Entries Decompressed", 0, total);
AsnWrite(aout,typePubSet,&val);
AsnStartStruct(aout,typeMedline);
for (count=0; entry=CASN_NextMedlineEntry(casnh); ++count)
{
MedlineEntryAsnWrite(entry,aout,typeMedlineE);
MedlineEntryFree(entry);
MonitorIntValue(pmonitor, count+1);
}
AsnEndStruct(aout,typeMedline);
MonitorFree(pmonitor);
if (count != total)
ErrPost(1,1, "Only %ld of %ld records read", count, total);
return;
}
void do_sequence (CASN_Handle casnh, AsnIoPtr aout)
{
SeqEntryPtr entry;
DataVal val;
Int4 total, count;
AsnModulePtr amp = AsnAllModPtr();
AsnTypePtr typeSet = AsnTypeFind(amp,"Bioseq-set");
AsnTypePtr typeSetSet = AsnTypeFind(amp,"Bioseq-set.seq-set");
AsnTypePtr typeSetSetE = AsnTypeFind(amp,"Bioseq-set.seq-set.E");
Monitor *pmonitor;
if (typeSet==NULL || typeSetSet==NULL || typeSetSetE==NULL)
{
Message(MSG_ERROR, "one or more atp's is NULL\n");
return;
}
total = CASN_DocCount(casnh);
pmonitor = MonitorIntNew("SEQUENCE Entries Decompressed", 0, total);
AsnStartStruct(aout,typeSet);
AsnStartStruct(aout,typeSetSet);
for (count=0; entry=CASN_NextSeqEntry(casnh); ++count)
{
SeqEntryAsnWrite(entry,aout,typeSetSetE);
SeqEntryFree(entry);
MonitorIntValue(pmonitor, count+1);
}
AsnEndStruct(aout,typeSetSet);
AsnEndStruct(aout,typeSet);
MonitorFree(pmonitor);
if (count != total)
ErrPost(1,1, "Only %ld of %ld records read", count, total);
return;
}
void stream_medline (AsnIoPtr ain)
{
AsnTypePtr atp;
DataVal val;
AsnModulePtr amp = AsnAllModPtr();
AsnTypePtr typePubSet = AsnTypeFind(amp,"Medline-entry");
AsnTypePtr title = AsnTypeFind(amp,"Title.E.name");
Monitor *pmonitor;
pmonitor = MonitorStrNew("MEDLINE Titles Decompressed", 60);
atp = typePubSet;
while ((atp = AsnReadId(ain, amp, atp)) != NULL)
{
if (atp == title)
{
AsnReadVal(ain, atp, &val);
MonitorStrValue(pmonitor, (CharPtr)val.ptrvalue);
MemFree(val.ptrvalue);
}
else
AsnReadVal(ain, atp, NULL);
}
MonitorFree(pmonitor);
return;
}
void stream_sequence (AsnIoPtr ain)
{
AsnTypePtr atp;
DataVal val;
AsnModulePtr amp = AsnAllModPtr();
AsnTypePtr typeSeqEntry = AsnTypeFind(amp,"Seq-entry");
AsnTypePtr title = AsnTypeFind(amp,"Seq-descr.E.title");
Monitor *pmonitor;
pmonitor = MonitorStrNew("Sequence Titles Decompressed", 60);
atp = typeSeqEntry;
while ((atp = AsnReadId(ain, amp, atp)) != NULL)
{
if (atp == title)
{
AsnReadVal(ain, atp, &val);
MonitorStrValue(pmonitor, (CharPtr)val.ptrvalue);
MemFree(val.ptrvalue);
}
else
AsnReadVal(ain, atp, NULL);
if (! AsnGetLevel(ain)) /* finished reading a Seq-entry */
atp = typeSeqEntry; /* reset to start next one */
}
MonitorFree(pmonitor);
return;
}
|