/* * Copyright (C) 2009-2011 by Benedict Paten (benedictpaten@gmail.com) * * Released under the MIT license, see LICENSE.txt */ #include #include #include #include #include #include #include #include "cactus.h" /* */ void usage() { fprintf(stderr, "cactus_getReferenceSeq, version 0.0\n"); fprintf(stderr, "-a --logLevel : Set the log level\n"); fprintf(stderr, "-b --name : name of the reference sequence's event\n"); fprintf(stderr, "-c --cactusDisk : The location of the flower disk directory\n"); fprintf(stderr, "-e --outputFile : Name of output fasta file\n"); fprintf(stderr, "-h --help : Print this help screen\n"); } char *formatSequenceHeader(Sequence *sequence) { const char *sequenceHeader = sequence_getHeader(sequence); if (strlen(sequenceHeader) > 0) { char *cA = st_malloc(sizeof(char) * (1 + strlen(sequenceHeader))); sscanf(sequenceHeader, "%s", cA); return cA; } else { return cactusMisc_nameToString(sequence_getName(sequence)); } } Sequence *getSequenceMatchesHeader(Flower *flower, char *header){ //Returns the first Sequence whose name matches 'header' Flower_SequenceIterator *it = flower_getSequenceIterator(flower); Sequence *sequence; while((sequence = flower_getNextSequence(it)) != NULL){ char *sequenceHeader = formatSequenceHeader(sequence); //if(strcmp(sequenceHeader, header) == 0){ if(strstr(sequenceHeader, header) != NULL){ flower_destructSequenceIterator(it); free(sequenceHeader); return sequence; } } flower_destructSequenceIterator(it); return NULL; } void getReferenceSequences(FILE *fileHandle, Flower *flower, char *name){ //get names of all the sequences in 'flower' that have their names start with 'name' Sequence *sequence; Flower_SequenceIterator * seqIterator = flower_getSequenceIterator(flower); while((sequence = flower_getNextSequence(seqIterator)) != NULL){ char *sequenceHeader = formatSequenceHeader(sequence); st_logInfo("Sequence %s\n", sequenceHeader); if(strstr(sequenceHeader, name) != NULL){ if(sequence_getLength(sequence) == 0){//skip empty sequences free(sequenceHeader); continue; } fprintf(fileHandle, ">%s\n", sequenceHeader); const int32_t lineLength = 10000000; const int32_t end = sequence_getLength(sequence) + sequence_getStart(sequence); for(int32_t i=sequence_getStart(sequence); i