deps/kb_meme/meme-5.0.1/src/spamo.c
/**************************************************************************
 * Outputs JSON describing the spacings between a primary and secondary motif.
 **************************************************************************/
Outputs JSON describing the spacings between a primary and secondary motif.
Outputs JSON describing the spacings between a primary and secondary motif .
void output_spacings_json(JSONWR_T *json, SECONDARY_MOTIF_T* smotif) {
  SPACING_T *spacings;
  SIGSPACE_T *sigspace;
  LINKLST_T *sigseqs;
  LINK_T *node;
  int quad, i, nquads;
  bool revcomp;
  if (smotif->sig_count < 1) {
    fprintf(stderr, "WARNING: Skipping motif because it has no significant spacings.\n");
    fprintf(stderr, "This shouldn't happen so please report.\n");
    return;
  }
  revcomp = alph_has_complement(get_motif_alph(smotif->motif));
  nquads = (revcomp ? NQUADS : 2);
  jsonwr_start_object_value(json);
  jsonwr_lng_prop(json, "idx", smotif->idx);
  jsonwr_property(json, "counts");
  jsonwr_start_array_value(json);
  for (quad = 0; quad < nquads; quad++) {
    spacings = &(smotif->spacings[quad]);
    jsonwr_start_array_value(json);
    for (i = 0; i < spacings->bin_count; i++) {
      jsonwr_lng_value(json, spacings->count[i]);
    }
    jsonwr_end_array_value(json);
  }
  jsonwr_end_array_value(json);
  jsonwr_property(json, "spacings");
  jsonwr_start_array_value(json);
  for (i = 0; i < smotif->sig_count; i++) {
    sigspace = &(smotif->sigs[i]);
    jsonwr_start_object_value(json);
    jsonwr_lng_prop(json, "orient", sigspace->orient);
    jsonwr_lng_prop(json, "bin", sigspace->bin);
    jsonwr_dbl_prop(json, "pvalue", sigspace->pvalue);
    jsonwr_property(json, "inferred_pwm");
    output_pwm_json(json, sigspace->inferred_motif);
    jsonwr_property(json, "alignment_pwm");
    jsonwr_start_array_value(json);
    for (quad = 0; quad < nquads; quad++) {
      if (sigspace->alignment_motif[quad] != NULL) {
        output_pwm_json(json, sigspace->alignment_motif[quad]);
      } else {
        jsonwr_null_value(json);
      }
    }
    jsonwr_end_array_value(json);
    jsonwr_property(json, "seqs");
    jsonwr_start_array_value(json);
    sigseqs = smotif->spacings[sigspace->orient].sequences[sigspace->bin];
    for (node = linklst_first(sigseqs); node != NULL; node = linklst_next(node)) {
      jsonwr_lng_value(json, ((SEQUENCE_T*)linklst_get(node))->idx);
    }
    jsonwr_end_array_value(json);
    jsonwr_end_object_value(json);
  }
  jsonwr_end_array_value(json);
  jsonwr_end_object_value(json);
}
void output_spacings_json ( JSONWR_T * json , SECONDARY_MOTIF_T * smotif ) { SPACING_T * spacings ; SIGSPACE_T * sigspace ; LINKLST_T * sigseqs ; LINK_T * node ; int quad , i , nquads ; bool revcomp ; if ( smotif -> sig_count < 1 ) { fprintf ( stderr , " \n " ) ; fprintf ( stderr , " \n " ) ; return ; } revcomp = alph_has_complement ( get_motif_alph ( smotif -> motif ) ) ; nquads = ( revcomp ? NQUADS : 2 ) ; jsonwr_start_object_value ( json ) ; jsonwr_lng_prop ( json , " " , smotif -> idx ) ; jsonwr_property ( json , " " ) ; jsonwr_start_array_value ( json ) ; for ( quad = 0 ; quad < nquads ; quad ++ ) { spacings = & ( smotif -> spacings [ quad ] ) ; jsonwr_start_array_value ( json ) ; for ( i = 0 ; i < spacings -> bin_count ; i ++ ) { jsonwr_lng_value ( json , spacings -> count [ i ] ) ; } jsonwr_end_array_value ( json ) ; } jsonwr_end_array_value ( json ) ; jsonwr_property ( json , " " ) ; jsonwr_start_array_value ( json ) ; for ( i = 0 ; i < smotif -> sig_count ; i ++ ) { sigspace = & ( smotif -> sigs [ i ] ) ; jsonwr_start_object_value ( json ) ; jsonwr_lng_prop ( json , " " , sigspace -> orient ) ; jsonwr_lng_prop ( json , " " , sigspace -> bin ) ; jsonwr_dbl_prop ( json , " " , sigspace -> pvalue ) ; jsonwr_property ( json , " " ) ; output_pwm_json ( json , sigspace -> inferred_motif ) ; jsonwr_property ( json , " " ) ; jsonwr_start_array_value ( json ) ; for ( quad = 0 ; quad < nquads ; quad ++ ) { if ( sigspace -> alignment_motif [ quad ] != NULL ) { output_pwm_json ( json , sigspace -> alignment_motif [ quad ] ) ; } else { jsonwr_null_value ( json ) ; } } jsonwr_end_array_value ( json ) ; jsonwr_property ( json , " " ) ; jsonwr_start_array_value ( json ) ; sigseqs = smotif -> spacings [ sigspace -> orient ] . sequences [ sigspace -> bin ] ; for ( node = linklst_first ( sigseqs ) ; node != NULL ; node = linklst_next ( node ) ) { jsonwr_lng_value ( json , ( ( SEQUENCE_T * ) linklst_get ( node ) ) -> idx ) ; } jsonwr_end_array_value ( json ) ; jsonwr_end_object_value ( json ) ; } jsonwr_end_array_value ( json ) ; jsonwr_end_object_value ( json ) ; }
Outputs JSON describing the spacings between a primary and secondary motif.
Outputs JSON describing the spacings between a primary and secondary motif .