Ejemplo n.º 1
0
int DBEntryAdaptor_fetchAllByTranscript(DBEntryAdaptor *dbea, Transcript *trans) {
  char qStr[512];
  StatementHandle *sth;
  ResultRow *row;
  Vector *transLinks;
  int i;

  sprintf(qStr, 
    "SELECT t.canonical_translation_id" 
    " FROM transcript t"
    " WHERE t.transcript_id = " IDFMTSTR,
    Transcript_getDbID(trans));
  
  sth = dbea->prepare((BaseAdaptor *)dbea,qStr,strlen(qStr));

  sth->execute(sth);

  // 
  // Did this to be consistent with fetch_by_Gene, but don't like
  // it (filling in the object). I think returning the array would
  // be better. Oh well. EB
  //
  
  while ((row = sth->fetchRow(sth))) {
    IDType translationId = row->getLongLongAt(row,0);
    Vector *translatLinks = DBEntryAdaptor_fetchByObjectType(dbea, translationId,"Translation");
    for (i=0;i<Vector_getNumElement(translatLinks); i++) {
      Transcript_addDBLink(trans,Vector_getElementAt(translatLinks,i));
    }
    Vector_free(translatLinks);
  }

  sth->finish(sth);

  transLinks = DBEntryAdaptor_fetchByObjectType(dbea, Transcript_getDbID(trans),"Transcript");
      fprintf(stderr,"transLinks\n");
  for (i=0;i<Vector_getNumElement(transLinks); i++) {
    Transcript_addDBLink(trans,Vector_getElementAt(transLinks,i));
  }
  Vector_free(transLinks);

  return 1;
}
Ejemplo n.º 2
0
Vector *AttributeAdaptor_fetchAllByTranscript(AttributeAdaptor *ata, Transcript *transcript, char *code) {
  Vector *result = NULL;
  if (transcript == NULL) {
    fprintf(stderr,"Error: NULL Transcript in AttributeAdaptor_fetchAllByTranscript\n");
  } else {

    char *type  = "transcript";
    char *table = "transcript";
    IDType id   = Transcript_getDbID(transcript);

    result = AttributeAdaptor_doFetchAllByTypeAndTableAndID(ata, type, table, id, code);
  }
  return result;
}
/* 
=head2 store_transcript_linkage

  Arg[1]      : Bio::EnsEMBL::IntronSupportingEvidence Evidence to link
  Arg[2]      : Bio::EnsEMBL::Transcript Transcript to link
  Arg[3]      : Integer an optional ID to give if the Transcript's own ID is possibly incorrect
  Example     : $isea->store_transcript_linkage($ise, $transcript);
                $isea->store_transcript_linkage($ise, $transcript, $tid);
  Description : Links a Transcript to a portion of Intron evidence
  Returntype  : None
  Exceptions  : Thrown if the given object is not a Transcript, if the 
                transcript is not stored, if the supporting evidence is not
                stored and for any DB exception. 

=cut
*/
void IntronSupportingEvidenceAdaptor_storeTranscriptLinkage(IntronSupportingEvidenceAdaptor *isea, 
                                                            IntronSupportingEvidence *sf,
                                                            Transcript *transcript,
                                                            IDType transcriptId) {
 
  if (sf == NULL || transcript == NULL) {
    fprintf(stderr,"sf or transcript is NULL in IntronSupportingEvidenceAdaptor_storeTranscriptLinkage\n");
    exit(1);
  }

  Class_assertType(CLASS_INTRONSUPPORTINGEVIDENCE, sf->objectType);
  Class_assertType(CLASS_TRANSCRIPT, transcript->objectType);
  
  if (! IntronSupportingEvidence_isStored(sf, isea->dba)) {
    fprintf(stderr,"Cannot perform the link. The IntronSupportingEvidence must be persisted first\n");
    exit(1);
  }

// Moved up so can use in sprintf
  Intron *intron = IntronSupportingEvidence_getIntron(sf, transcript);
  Exon *prevExon = Intron_getPrevExon(intron);
  Exon *nextExon = Intron_getNextExon(intron);

  if (!transcriptId) {
    transcriptId = Transcript_getDbID(transcript);
  }

  char qStr[1024];
  sprintf(qStr, "INSERT IGNORE INTO transcript_intron_supporting_evidence "
          "(transcript_id, intron_supporting_evidence_id, previous_exon_id, next_exon_id) "
          "VALUES ("IDFMTSTR","IDFMTSTR","IDFMTSTR","IDFMTSTR")", 
          transcriptId, IntronSupportingEvidence_getDbID(sf), Exon_getDbID(prevExon), Exon_getDbID(nextExon));

  StatementHandle *sth = isea->prepare((BaseAdaptor *)isea,qStr,strlen(qStr));
  
  sth->execute(sth);
  sth->finish(sth);

  Intron_free(intron);
  
  return;
}
/*
=head2 fetch_all_by_Transcript

  Arg[1]      : Bio::EnsEMBL::Transcript Transcript to search with
  Example     : my $ises = $isea->fetch_all_by_Transcript($transcript);
  Description : Uses the given Transcript to search for all instances of
                IntronSupportingEvidence linked to the transcript in the 
                database 
  Returntype  : ArrayRef of IntronSupportingEvidence objects
  Exceptions  : Thrown if arguments are not as stated and for DB errors 

=cut
*/
Vector *IntronSupportingEvidenceAdaptor_fetchAllByTranscript(IntronSupportingEvidenceAdaptor *isea, Transcript *transcript) {
  char qStr[1024];

  sprintf(qStr,"SELECT intron_supporting_evidence_id "
                 "FROM transcript_intron_supporting_evidence "
                "WHERE transcript_id = "IDFMTSTR, Transcript_getDbID(transcript));

  StatementHandle *sth = isea->prepare((BaseAdaptor *)isea,qStr,strlen(qStr));
  sth->execute(sth);

  Vector *idVec = Vector_new();
  ResultRow *row;
  while ((row = sth->fetchRow(sth))) {
    IDType id = row->getLongLongAt(row, 0);
    IDType *idP;

    if ((idP = calloc(1,sizeof(IDType))) == NULL) {
      fprintf(stderr, "Failed allocating space for a id\n");
      exit(1);
    }

    *idP = id;
    Vector_addElement(idVec, idP);
  }
  sth->finish(sth);

  Vector *out;
  if (Vector_getNumElement(idVec) > 0) {
    out = IntronSupportingEvidenceAdaptor_fetchAllByDbIDList(isea, idVec, NULL); 
  } else {
    out = Vector_new();
  }
 
  // Free ids vector
  Vector_setFreeFunc(idVec, free);
  Vector_free(idVec);

  return out;
}
// Switch to passing two element array to fill in as an argument, so don't have to allocate it
IDType *IntronSupportingEvidenceAdaptor_fetchFlankingExonIds(IntronSupportingEvidenceAdaptor *isea, IntronSupportingEvidence *ise, Transcript *transcript, IDType *flanks) {
  char qStr[1024];

  sprintf(qStr,"SELECT previous_exon_id, next_exon_id "
                 "FROM transcript_intron_supporting_evidence "
                "WHERE transcript_id ="IDFMTSTR" and intron_supporting_evidence_id ="IDFMTSTR, 
          Transcript_getDbID(transcript), IntronSupportingEvidence_getDbID(ise));

  StatementHandle *sth = isea->prepare((BaseAdaptor *)isea,qStr,strlen(qStr));
  sth->execute(sth);

  if (sth->numRows(sth) == 0) {
    return NULL;
  }
  
  ResultRow *row = sth->fetchRow(sth);

  flanks[0] = row->getLongLongAt(row, 0);
  flanks[1] = row->getLongLongAt(row, 1);

  sth->finish(sth);

  return flanks;
}