Exemplo n.º 1
0
int main(int argc, char *argv[]) {
    FILE *fileHandle;
    struct List *seqs;
    struct List *seqLengths;
    struct List *seqNames;
    int32_t i;

    assert(argc == 3);

    seqs = constructEmptyList(0, free);
    seqLengths = constructEmptyList(0, (void (*)(void *))destructInt);
    seqNames = constructEmptyList(0, free);

    fileHandle = fopen(argv[1], "r");
    fastaRead(fileHandle, seqs, seqLengths, seqNames);
    fclose(fileHandle);

    fileHandle = fopen(argv[2], "w");
    for(i=0; i < seqs->length; i++) {
        assert(strlen(seqs->list[i]) == *((int32_t *)seqLengths->list[i]));
        fastaWrite(seqs->list[i], seqNames->list[i], fileHandle);
    }
    fclose(fileHandle);

    return 0;
}
Exemplo n.º 2
0
static void getReferenceSequences(FILE *fileHandle, Flower *flower, char *referenceEventString){
   //get names of all the sequences in 'flower' for event with name 'referenceEventString'
   Sequence *sequence;
   Flower_SequenceIterator * seqIterator = flower_getSequenceIterator(flower);
   while((sequence = flower_getNextSequence(seqIterator)) != NULL)
   {
      Event* event = sequence_getEvent(sequence);
      const char* eventName = event_getHeader(event);
      if (strcmp(eventName, referenceEventString) == 0 &&
          sequence_getLength(sequence) > 0 &&
          !metaSequence_isTrivialSequence(sequence_getMetaSequence(sequence))) {
         const char *sequenceHeader = formatSequenceHeader(sequence);
         st_logInfo("Sequence %s\n", sequenceHeader);
         char *string = sequence_getString(sequence, sequence_getStart(sequence), sequence_getLength(sequence), 1);
         fastaWrite(string, (char *)sequenceHeader, fileHandle);
         free(string);
      }
   }
   flower_destructSequenceIterator(seqIterator);
   return;
}