/***************************************************************************** # Copyright (C) 1994-2008 by David Gordon. # All rights reserved. # # This software is part of a beta-test version of the Consed/Autofinish # package. It should not be redistributed or # used for any commercial purpose, including commercially funded # sequencing, without written permission from the author and the # University of Washington. # # This software is provided ``AS IS'' and any express or implied # warranties, including, but not limited to, the implied warranties of # merchantability and fitness for a particular purpose, are disclaimed. # In no event shall the authors or the University of Washington be # liable for any direct, indirect, incidental, special, exemplary, or # consequential damages (including, but not limited to, procurement of # substitute goods or services; loss of use, data, or profits; or # business interruption) however caused and on any theory of liability, # whether in contract, strict liability, or tort (including negligence # or otherwise) arising in any way out of the use of this software, even # if advised of the possibility of such damage. # # Building Consed from source is error prone and not simple which is # why I provide executables. Due to time limitations I cannot # provide any assistance in building Consed. Even if you do not # modify the source, you may introduce errors due to using a # different version of the compiler, a different version of motif, # different versions of other libraries than I used, etc. For this # reason, if you discover Consed bugs, I can only offer help with # those bugs if you first reproduce those bugs with an executable # provided by me--not an executable you have built. # # Modifying Consed is also difficult. Although Consed is modular, # some modules are used by many other modules. Thus making a change # in one place can have unforeseen effects on many other features. # It may takes months for you to notice these other side-effects # which may not seen connected at all. It is not feasable for me to # provide help with modifying Consed sources because of the # potentially huge amount of time involved. # #*****************************************************************************/ /** readSCF.c **/ /* *|***************************************************************************|* *| |* *| phred * NOT FOR DISTRIBUTION |* *| Copyright (C) 1995-1999 by Phil Green and Brent Ewing. |* *| All rights reserved. |* *| |* *|***************************************************************************|* */ /* ******************************************************************************* ** ** ** * readSCF.c * ** ** * benefits from ideas in code written by LaDeana Hillier and * ** ** * Tim Gleeson. * ** ** ** ******************************************************************************* */ #include #include #include #include #include #include #include "typeDef.h" #include "rwUtil.h" #include "chromatData.h" #include "freeChromatData.h" #include "readSCF.h" #ifdef ANSI_C static int readSCFHeader( FILE *fp, SCFHeader *h ) #else static int readSCFHeader( fp, h ) FILE *fp; SCFHeader *h; #endif { if( readUint4( fp, &h->magic_number ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->samples ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->samples_offset ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->bases ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->bases_left_clip ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->bases_right_clip ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->bases_offset ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->comments_size ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->comments_offset ) == ERROR ) return( ERROR ); if( fread( h->version, sizeof( h->version ), 1, fp) != 1 ) return( ERROR ); if( readUint4( fp, &h->sample_size ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->code_set ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->private_size ) == ERROR ) return( ERROR ); if( readUint4( fp, &h->private_offset ) == ERROR ) return( ERROR ); return( OK ); } /* ** Read the SCF format sequence with name `fn' into `seq'. */ /* ** status: ** ** 0 = OK ** 1 = file reading error ** 2 = no trace (and no bases assumed) ** 3 = no bases (but there is trace) ** -1 = fatal error */ #ifdef ANSI_C ChromatData *readSCF( char *fn, int *status ) #else ChromatData *readSCF( fn, status ) char *fn; int *status; #endif { int numBase; int numPoint; int versionSwitch; int lstat; SCFHeader header; ChromatData *chromatData; FILE *fp; /* ** Open file for reading. */ fp = fopen( fn, "rb" ); if( fp == NULL ) { fprintf( stderr, "readSCF: unable to open file %s\n", fn ); *status = 1; return( NULL ); } /* ** Read header. */ if( readSCFHeader( fp, &header ) == ERROR ) { fprintf( stderr, "readSCF: unable to read %s header\n", fn ); fclose( fp ); numPoint = 0; numBase = 0; chromatData = allocChromatData( numPoint, numBase ); if( chromatData == NULL ) { fprintf( stderr, "readSCF: unable to allocate memory\n" ); fclose( fp ); *status = -1; return( NULL ); } chromatData->fileType = SCFFormat; chromatData->primerLoc = 0; chromatData->avgSpacing = 0.0; chromatData->machineName[0] = '\0'; chromatData->sampleName[0] = '\0'; chromatData->primerID[0] = '\0'; chromatData->signalStrength[0] = 0; chromatData->signalStrength[1] = 0; chromatData->signalStrength[2] = 0; chromatData->signalStrength[3] = 0; chromatData->gelName[0] = '\0'; chromatData->laneNumber = 0; chromatData->processing[0] = '\0'; chromatData->reTracker[0] = '\0'; chromatData->comment[0] = '\0'; chromatData->convProg[0] = '\0'; chromatData->source[0] = '\0'; strcpy( chromatData->fileName, fn ); memset( chromatData->thumbPrint, 0, 10 * sizeof( char ) ); *status = 1; return( chromatData ); } #define PRIVATE_DATA_MAGIC_NUMBER_SIZE 4 if ( header.private_size >= PRIVATE_DATA_MAGIC_NUMBER_SIZE ) { if( fseek( fp, header.private_offset, 0 ) != 0 ) { fprintf( stderr, "readSCF: bad status: fseek\n" ); *status = -1; return( NULL ); } char cPrivateDataMagicNumber[ PRIVATE_DATA_MAGIC_NUMBER_SIZE ]; if( fread( cPrivateDataMagicNumber, PRIVATE_DATA_MAGIC_NUMBER_SIZE, 1, fp ) == 0 ) { fprintf( stderr, "readSCF: bad file read\n" ); *status = -1; return( NULL ); } fprintf( stderr, "Beckman private data? %c%c%c%c\n", cPrivateDataMagicNumber[0], cPrivateDataMagicNumber[1], cPrivateDataMagicNumber[2], cPrivateDataMagicNumber[3] ); } /* else { */ /* fprintf( stderr, "no private data section\n" ); */ /* } */ numPoint = header.samples; numBase = header.bases; /* ** Allocate chromatData memory. */ chromatData = allocChromatData( numPoint, numBase ); if( chromatData == NULL ) { fprintf( stderr, "readSCF: unable to allocate memory\n" ); fclose( fp ); *status = -1; return( NULL ); } /* ** Initialize values. */ chromatData->fileType = SCFFormat; chromatData->primerLoc = 0; chromatData->avgSpacing = 0.0; chromatData->machineName[0] = '\0'; chromatData->sampleName[0] = '\0'; chromatData->primerID[0] = '\0'; chromatData->signalStrength[0] = 0; chromatData->signalStrength[1] = 0; chromatData->signalStrength[2] = 0; chromatData->signalStrength[3] = 0; chromatData->gelName[0] = '\0'; chromatData->laneNumber = 0; chromatData->processing[0] = '\0'; chromatData->reTracker[0] = '\0'; chromatData->comment[0] = '\0'; chromatData->convProg[0] = '\0'; chromatData->source[0] = '\0'; strcpy( chromatData->fileName, fn ); memset( chromatData->thumbPrint, 0, 10 * sizeof( char ) ); /* ** Check the file version. */ if( strtod( header.version, (char **)NULL ) < 2.0 ) { versionSwitch = 2; header.sample_size = 1; } else if( strtod( header.version, (char **)NULL ) < 3.0 ) { versionSwitch = 2; } else { versionSwitch = 3; } if( versionSwitch == 2 ) { if( readSCF2( fn, fp, &header, chromatData, numPoint, numBase, &lstat ) == ERROR ) { if( lstat == 1 || lstat == 2 ) { chromatData->numPoint = 0; chromatData->numBase = 0; *status = lstat; } else if( lstat == 3 ) { chromatData->numBase = 0; *status = lstat; } else if( lstat == 0 ) { fprintf( stderr, "readSCF: internal inconsistency: readSCF2 returns ERROR with status OK\n" ); chromatData->numPoint = 0; chromatData->numBase = 0; *status = -1; } else if( lstat == -1 ) { chromatData->numPoint = 0; chromatData->numBase = 0; *status = lstat; } else { fprintf( stderr, "readSCF: unknown status: %d\n", lstat ); chromatData->numPoint = 0; chromatData->numBase = 0; *status = -1; } fclose( fp ); return( chromatData ); } } else if( versionSwitch == 3 ) { if( readSCF3( fn, fp, &header, chromatData, numPoint, numBase, &lstat ) == ERROR ) { if( lstat == 1 || lstat == 2 ) { chromatData->numPoint = 0; chromatData->numBase = 0; *status = lstat; } else if( lstat == 3 ) { chromatData->numBase = 0; *status = lstat; } else if( lstat == 0 ) { fprintf( stderr, "readSCF: internal inconsistency: readSCF2 returns ERROR with status OK\n" ); chromatData->numPoint = 0; chromatData->numBase = 0; *status = -1; } else if( lstat == -1 ) { chromatData->numPoint = 0; chromatData->numBase = 0; *status = lstat; } else { fprintf( stderr, "readSCF: unknown status: %d\n", lstat ); chromatData->numPoint = 0; chromatData->numBase = 0; *status = -1; } fclose( fp ); return( chromatData ); } } *status = lstat; /* ** Finished with the file. */ fclose( fp ); return( chromatData ); }