SOM_Scope short  SOMLINK removeItem(Day *somSelf,  Environment *ev,
                                string start, string end, string desc)
{
    DayData *somThis = DayGetData(somSelf);
    short    i;
    WorkItem *item;
    DayMethodDebug("Day","removeItem");

    for (i=0; i < sequenceLength(somThis->workList); i++ )
    {
      item = sequenceElement(somThis->workList,i);

      if ( (strcmp(start, item->_get_startTime(ev)) == 0) &&
           (strcmp(end, item->_get_endTime(ev)) == 0) &&
           (strcmp(desc, item->_get_task(ev)) == 0) )
      {
         sequenceLength(somThis->workList)--;
                                                                         
         for (i; i < sequenceLength(somThis->workList); i++)
         {
           sequenceElement(somThis->workList,i) =
             sequenceElement(somThis->workList, i+1);
         }

         somSelf->sompSetDirty(ev);
         return 0;
      }
    }
    return -1L;       // item not found
}
testSequence()
{
  Environment *ev = somGetGlobalEnvironment();    
  Employee *emp1, *emp2;
  Company  *comp;
  _IDL_SEQUENCE_Employee list;
  short i;

  emp1 = new Employee;
  emp1->_set_name(ev, "Mary");

  emp2 = new Employee;
  emp2->_set_name(ev, "John");

  comp = new Company;
  comp->addEmployee(ev, emp1);
  comp->addEmployee(ev, emp2);
  
  list = comp->_get_empList(ev);
                                                 
  for (i=0; i < sequenceLength(list); i++)
  {
    cout << sequenceElement(list,i)->_get_name(ev) << "\n";
  }
}
SOM_Scope void  SOMLINK somInit(Day *somSelf)
{
    DayData *somThis = DayGetData(somSelf);
    DayMethodDebug("Day","somInit");

    Day_parent_SOMPPersistentObject_somInit(somSelf);

    sequenceMaximum(somThis->workList) = MAXITEM;
    sequenceLength(somThis->workList) = 0;
    somThis->workList._buffer =
       (WorkItem**) SOMMalloc(sizeof (WorkItem *) * MAXITEM);
}
SOM_Scope short  SOMLINK book(Day *somSelf,  Environment *ev,
                              WorkItem* entry)
{
    DayData *somThis = DayGetData(somSelf);
    short rc;
    DayMethodDebug("Day","book");

    if (sequenceLength(somThis->workList) < sequenceMaximum(somThis->workList))
    {
      sequenceElement(somThis->workList,
                      sequenceLength(somThis->workList)) = entry;
      sequenceLength(somThis->workList)++;

      somSelf->sompSetDirty(ev);
      entry->sompInitNearObject(ev, somSelf);

      rc = 0L;
    }
    else
      rc = -1L;

    return rc;
}
Esempio n. 5
0
int main()
{
    long long longestLength = 1;
    long long maxStart = 1;
    long long i, length;
    for(i = 2; i < 1000000; i++){
        length = sequenceLength(i);
        if(length > longestLength){
            longestLength = length;
            maxStart = i;
        }
    }
    printf("%lld\n", maxStart);
    return 0;
}
Esempio n. 6
0
int main(int argc, char const ** argv)
{
    double startTime = 0;
    
    // Parse command line.
    FxFaidxOptions options;
    seqan::ArgumentParser::ParseResult res = parseArgs(options, argc, argv);
    if (res != seqan::ArgumentParser::PARSE_OK)
        return res == seqan::ArgumentParser::PARSE_ERROR;  // 1 on errors, 0 otherwise

    // ---------------------------------------------------------------------------
    // Index I/O
    // ---------------------------------------------------------------------------

    // Load index, create if necessary.
    startTime = sysTime();
    seqan::FaiIndex faiIndex;
    if (load(faiIndex, toCString(options.inFastaPath), toCString(options.inFaiPath)) != 0)
    {
        if (options.verbosity >= 2)
            std::cerr << "Building Index        " << options.inFaiPath << " ...";
        if (buildIndex(toCString(options.inFastaPath), toCString(options.inFaiPath), seqan::Fai()) != 0)
        {
            std::cerr << "Could not build FAI index at " << options.inFaiPath
                      << " for FASTA file " << options.inFastaPath << "\n";
            return 1;
        }
        if (load(faiIndex, toCString(options.inFastaPath), toCString(options.inFaiPath)) != 0)
        {
            std::cerr << "Could not load FAI index we just build.\n";
            return 1;
        }
    }
    if (options.verbosity >= 3)
        std::cerr << "Took " << (startTime - sysTime()) << " s\n";

    // ---------------------------------------------------------------------------
    // Parse and Fetch Regions.
    // ---------------------------------------------------------------------------

    if (empty(options.regions))
        return 0;

    // Parse out regions.
    seqan::String<Region> regions;
    for (unsigned i = 0; i < length(options.regions); ++i)
    {
        Region region;
        if (!parseRegion(region, options.regions[i]))
        {
            std::cerr << "Could not parse region " << options.regions[i] << "\n";
            return 1;
        }
        unsigned seqId;
        if (!getIdByName(faiIndex, region.seqName, seqId))
        {
            std::cerr << "Unknown sequence for region " << options.regions[i] << "\n";
            return 1;
        }
        region.seqId = seqId;
        if (region.seqId < 0 || (unsigned)region.seqId >= length(faiIndex.indexEntryStore))
        {
            std::cerr << "Invalid region " << options.regions[i] << "\n";
            return 1;
        }
        appendValue(regions, region);
    }

    // Open output file.
    std::ostream * outPtr = &std::cout;
    std::ofstream outF;
    if (!empty(options.outFastaPath))
    {
        outF.open(toCString(options.outFastaPath), std::ios::binary | std::ios::out);
        if (!outF.good())
        {
            std::cerr << "Could not open output file " << options.outFastaPath << "\n";
            return 1;
        }
    }

    // Retrieve output infixes and write to result.
    for (unsigned i = 0; i < length(regions); ++i)
    {
        Region const & region = regions[i];
        seqan::CharString id = options.regions[i];
        seqan::CharString seq;
        unsigned beginPos = 0;
        if (region.beginPos > 0)
            beginPos = region.beginPos;
        unsigned endPos = sequenceLength(faiIndex, (unsigned)region.seqId);
        if (region.endPos > 0 && (unsigned)region.endPos < endPos)
            endPos = region.endPos;
        if (beginPos > endPos)
            endPos = beginPos;
        getSequenceInfix(seq, faiIndex, region.seqId, beginPos, endPos);
        if (writeRecord(*outPtr, id, seq, seqan::Fasta()) != 0)
        {
            std::cerr << "Could not write infix for region " << options.regions[i] << " to output.\n";
            return 1;
        }
    }

    return 0;
}
Esempio n. 7
0
int main(int argc, char const ** argv)
{
    double startTime = 0;
    
    // -----------------------------------------------------------------------
    // Parse command line.
    // -----------------------------------------------------------------------
    FxSamCoverageOptions options;
    seqan::ArgumentParser::ParseResult res = parseArgs(options, argc, argv);
    if (res != seqan::ArgumentParser::PARSE_OK)
        return res == seqan::ArgumentParser::PARSE_ERROR;  // 1 on errors, 0 otherwise

    // -----------------------------------------------------------------------
    // Show options.
    // -----------------------------------------------------------------------
    if (options.verbosity >= 1)
    {
        std::cerr << "____OPTIONS___________________________________________________________________\n"
                  << "\n"
                  << "VERBOSITY    " << options.verbosity << "\n"
                  << "GENOME       " << options.inGenomePath << "\n"
                  << "SAM          " << options.inSamPath << "\n"
                  << "OUT          " << options.outPath << "\n"
                  << "WINDOW SIZE  " << options.windowSize << "\n";
    }

    // -----------------------------------------------------------------------
    // Load Genome FAI Index
    // -----------------------------------------------------------------------

    std::cerr << "\n"
              << "___PREPRATION_____________________________________________________________________\n"
              << "\n"
              << "Indexing GENOME file  " << options.inGenomePath << " ...";
    seqan::FaiIndex faiIndex;
    if (build(faiIndex, toCString(options.inGenomePath)) != 0)
    {
        std::cerr << "Could not build FAI index.\n";
        return 1;
    }
    std::cerr << " OK\n";

    // Prepare bins.
    seqan::String<seqan::String<BinData> > bins;
    resize(bins, numSeqs(faiIndex));

    // -----------------------------------------------------------------------
    // Compute C+G content 
    // -----------------------------------------------------------------------

    std::cerr << "\n"
              << "___C+G CONTENT COMPUTATION________________________________________________________\n"
              << "\n";

    for (unsigned i = 0; i < numSeqs(faiIndex); ++i)
    {
        std::cerr << "[" << sequenceName(faiIndex, i) << "] ...";
        unsigned numBins = (sequenceLength(faiIndex, i) + options.windowSize - 1) / options.windowSize;
        resize(bins[i], numBins);
        seqan::Dna5String contigSeq;
        if (readSequence(contigSeq, faiIndex, i) != 0)
        {
            std::cerr << "\nERROR: Could not read sequence " << sequenceName(faiIndex, i) << " from file!\n";
            return 1;
        }

        for (unsigned bin = 0; bin < numBins; ++bin)
        {
            unsigned cgCounter = 0;
            unsigned binSize = 0;
            bins[i][bin].length = options.windowSize;
            if ((bin + 1) * options.windowSize > length(contigSeq))
                bins[i][bin].length = length(contigSeq) - bin * options.windowSize;
            for (unsigned pos = bin * options.windowSize; pos < length(contigSeq) && pos < (bin + 1) * options.windowSize; ++pos, ++binSize)
                cgCounter += (contigSeq[pos] == 'C' || contigSeq[pos] == 'G');
            bins[i][bin].cgContent = 1.0 * cgCounter / binSize;
        }
        std::cerr << "DONE\n";
    }

    // -----------------------------------------------------------------------
    // Compute Coverage
    // -----------------------------------------------------------------------

    std::cerr << "\n"
              << "___COVERAGE COMPUATATION________________________________________________________\n"
              << "\n"
              << "Computing Coverage...";

    seqan::BamStream bamStream(toCString(options.inSamPath));
    if (!isGood(bamStream))
    {
        std::cerr << "Could not open " << options.inSamPath << "!\n";
        return 1;
    }

    seqan::BamAlignmentRecord record;
    while (!atEnd(bamStream))
    {
        if (readRecord(record, bamStream) != 0)
        {
            std::cerr << "ERROR: Could not read record from BAM file!\n";
            return 1;
        }

        if (hasFlagUnmapped(record) || hasFlagSecondary(record) || record.rId == seqan::BamAlignmentRecord::INVALID_REFID)
            continue;  // Skip these records.

        int contigId = 0;
        seqan::CharString const & contigName = nameStore(bamStream.bamIOContext)[record.rId];
        if (!getIdByName(faiIndex, contigName, contigId))
        {
            std::cerr << "ERROR: Alignment to unknown contig " << contigId << "!\n";
            return 1;
        }
        unsigned binNo = record.pos / options.windowSize;
        bins[contigId][binNo].coverage += 1;
    }

    std::cerr << "DONE\n";

    // -----------------------------------------------------------------------
    // Write Output
    // -----------------------------------------------------------------------

    std::ostream * out = &std::cout;
    std::ofstream outFile;
    if (options.outPath != "-")
    {
        outFile.open(toCString(options.outPath), std::ios::binary | std::ios::out);
        if (!outFile.good())
        {
            std::cerr << "ERROR: Could not open output file " << options.outPath << "!\n";
            return 1;
        }
        out = &outFile;
    }

    (*out) << "#BIN\tREF_NAME\tREF_BIN\tBIN_BEGIN\tBIN_LENGTH\tCOVERAGE\tCG_CONTENT\n";
    for (unsigned i = 0, globalBin = 0; i < length(bins); ++i)
    {
        for (unsigned refBin = 0; refBin < length(bins[i]); ++refBin, ++globalBin)
        {
            (*out) << globalBin << '\t'
                   << sequenceName(faiIndex, i) << '\t'
                   << refBin << '\t'
                   << refBin * options.windowSize << '\t'
                   << bins[i][refBin].length << '\t'
                   << bins[i][refBin].coverage << '\t'
                   << bins[i][refBin].cgContent << '\n';
        }
    }

    if (options.verbosity >= 2)
        std::cerr << "Took " << (sysTime() - startTime) << " s\n";

    return 0;
}
Esempio n. 8
0
//**************************************************************************
//                         1                   2                   3       *
// Col-> 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2   *
// Row                                                                     *
//  1    -----------------   Appointment                                   *
//  2    |               |              ---------------------              *
//  3    |               |   Phone :   |                    |              *
//  4    |               |              ---------------------              *
//  5    |               |              ---------------------              *
//  6    |               |   Location: |                    |              *
//  7    |               |              ---------------------              *
//  8    |               |             ----------------------              *
//  9    |               |   Subject:  |                    |              *
// 10    |               |             |                    |              *
// 11    |               |             |                    |              *
// 12    -----------------             |                    |              *
// 13                                  ----------------------              *
// 14    Users:       ��������������������������������������������Ŀ       *
// 15                 �                                            �       *
// 16                 �                                            �       *
// 17                 �                                            �       *
// 18                 �                                            �       *
// 19                 �                                            �       *
// 20                 ����������������������������������������������       *
// 21   ������������Ŀ  ������������Ŀ  ������������Ŀ                     *
// 22   �            �  �            �  �            �                     *
// 23   ��������������  ��������������  ��������������                     *
//**************************************************************************
// UpdlDialog :: UpdlDialog - Get a book name                              *
//**************************************************************************
UpdlDialog :: UpdlDialog(_IDL_SEQUENCE_Appointment apptList, long *index,
                         unsigned long windowId, IWindow * ownerWnd)
            : IFrameWindow(windowId,
                           desktopWindow(), // parent
                           ownerWnd,        // owner
                           IRectangle(500,  // width
                                      400), // height
                           IWindow::synchPaint
                            |IWindow::clipSiblings
                            |IWindow::saveBits
                            |systemMenu
                            |titleBar
                            |dialogBorder
                            |dialogBackground
                           ),
              clientCanvas(WND_CANVAS_UPDLDIALOG,this,this),
              buttons(WND_CANVAS_UPDLDIALOGBTN,this,this),
              listBox(LB_APPTS,&clientCanvas,&clientCanvas,IRectangle()),
              multicCanvas(WND_CANVAS_UPDLMCDIALOG,
                               &clientCanvas, &clientCanvas, IRectangle()),
              txtAppointment(STR_APPOINTMENT,&multicCanvas,&multicCanvas),
              txtPhone(STR_PHONE,&multicCanvas,&multicCanvas),
              txtLocation(STR_LOCATION,&multicCanvas,&multicCanvas),
              txtSubject(STR_SUBJECT,&multicCanvas,&multicCanvas),
              fldPhone(DDL_PHONE,&multicCanvas,&multicCanvas),
              fldLocation(DDL_LOCATION,&multicCanvas,&multicCanvas),
              fldSubject(DDL_SUBJECT,&multicCanvas,&multicCanvas),
//            UserCanvas(WND_CANVAS_UPDLUSERDIALOG, &clientCanvas, &clientCanvas),
//            lboxUsers(LB_USERS,&UserCanvas,&UserCanvas),
//            txtUsers(TXT_USERS,&UserCanvas,&UserCanvas),
              btnOk(DID_OK,&buttons,&buttons),
              btnCancel(DID_CANCEL,&buttons,&buttons),
              btnSelect(DID_SELECT,&buttons,&buttons),
              apptList(apptList),
              IDValue(index)
{
  string bp;
  strstream ss;
  Appointment *appt;

  Environment *ev = somGetGlobalEnvironment();

  setClient(&clientCanvas);
  clientCanvas.setOrientation(ISplitCanvas::verticalSplit);
  clientCanvas.setSplitWindowPercentage(&multicCanvas, 60);
  clientCanvas.setSplitWindowPercentage(&listBox, 40);

//UserCanvas.setOrientation(ISplitCanvas::horizontalSplit);

  IWindow::enable(1);
  IHandler::enable(1);
  listBox.enable(1);
  ICommandHandler::handleEventsFor(this); // Set self as command event handler

  if (sequenceLength(apptList)>0) {
     for (int i=0; sequenceLength(apptList)>i; i++) {
        appt = sequenceElement(apptList,i);
        ss << ITime(appt->_get_start(ev)) << " to " << ITime(appt->_get_end(ev)) << endl;
        listBox.addAsLast(bp=ss.str());
        ss.rdbuf()->seekoff(0, ios::beg, ios::in|ios::out);
     }
     ss.rdbuf()->freeze(0); // release string buffer
  }

  txtAppointment.setText(STR_APPOINTMENT);
  txtPhone.setText(STR_PHONE);
  txtLocation.setText(STR_LOCATION);
  txtSubject.setText(STR_SUBJECT);

                                  // Disable until the appointment is selected
  fldLocation.disable();
  fldPhone.disable();
  fldSubject.disable();
  *IDValue = -1;  // Initialize the IDValue

//txtUsers.setText(STR_USERS);

  btnOk.setText(STR_OK);
  btnOk.disable();    // disable until a selection is made
  btnCancel.setText(STR_CANCEL);
  btnSelect.setText(STR_SELECT);
  if (windowId == WND_DELAPPTDIALOG) {     // Set everything to read only
    fldPhone.enableDataUpdate(false);
    fldLocation.enableDataUpdate(false);
    fldSubject.enableDataUpdate(false);
  }

  //                      Field              Col  Row  #Col  #Row
  multicCanvas.addToCell(&txtAppointment  ,    2,   2,   12,   1);

  multicCanvas.addToCell(&txtPhone        ,    2,   3,    2,   1);
  multicCanvas.addToCell(&txtLocation     ,    2,   6,    2,   1);
  multicCanvas.addToCell(&txtSubject      ,    2,   9,    2,   1);

  multicCanvas.addToCell(&fldPhone        ,    6,   3,   10,   1);
  multicCanvas.addToCell(&fldLocation     ,    6,   6,   10,   1);
  multicCanvas.addToCell(&fldSubject      ,    6,   9,   10,   1);

  setFocus();
  buttons.setMargin(ISize());            // Set Canvas Margins to zero
  buttons.setPad(ISize());               // Set Button Canvas Pad to zero
  addExtension(&buttons, IFrameWindow::belowClient,
               (unsigned long)buttons.minimumSize().height()+10);
  listBox.setFocus();
}
Esempio n. 9
0
//**************************************************************************
// NameDialog :: command - Process Commands                               *
//**************************************************************************
Boolean UpdlDialog :: command(ICommandEvent& cmdevt)
{
  long index=-1;
  Appointment *appt;
  Environment *ev = somGetGlobalEnvironment();

  switch(cmdevt.commandId()) {
    case DID_OK:
                       // If a selection was made
      if ( *IDValue >= 0 ) {
                  // Ok is pressed get the modifications if there are some
        if (sequenceLength(apptList)>0) {
          appt = sequenceElement(apptList,*IDValue);
          if (appt->somIsA(_ConferenceCall)) {
                                              // Check to see if the entry changed
            if (fldPhone.hasChanged()) {
              fldPhone.selectRange();
              new_phone=fldPhone.selectedText();
            }
          } else {
            if (fldLocation.hasChanged()) {
              fldLocation.selectRange();
              new_location=fldLocation.selectedText();
            }
          }
          if (fldSubject.hasChanged()) {
            fldSubject.selectRange();
              new_subject=fldSubject.selectedText();
          }
        } /* endif */
      }
      dismiss(DID_OK);
      return(true);
      break;

    case DID_CANCEL:
      dismiss(DID_CANCEL);
      return(true);
      break;

    case DID_SELECT:
      index = listBox.selection();  // return index to selection
      if (sequenceLength(apptList)>0) {
         btnOk.enable();    // enable ok since a selection is made
         if (index >= 0) {
           appt = sequenceElement(apptList,index);
           if (!fldPhone.isEmpty()) {
             fldPhone.selectRange();
             fldPhone.clear();
           }
           if (!fldLocation.isEmpty()) {
             fldLocation.selectRange();
             fldLocation.clear();
           }
           if (!fldSubject.isEmpty()) {
             fldSubject.selectRange();
             fldSubject.clear();
           }
           if (appt->somIsA(_ConferenceCall)) {
             fldPhone.enable();
             fldPhone.setText(((ConferenceCall *)appt)->_get_phoneNumber(ev));
             fldLocation.disable();
           } else {
             fldLocation.enable();
             fldLocation.setText(((Meeting *)appt)->_get_location(ev));
             fldPhone.disable();
           }
           fldSubject.enable();
           fldSubject.setText(appt->_get_subject(ev));
           *IDValue = index;
         }
      }
      return(true);
      break;
  }/* end switch */

  return(false);  //Allow Default Processing to occur
}