Esempio n. 1
0
int AbstractTwoLevelAgreement::calculateStatisticsOrAnotate() {
    if (!readAnnotations()) {
        return -1;
    }
    int ret=calculateStatisticsHelper();
    compareGlobalGraphs(annotatedGraph,generatedGraph);
    for (int i=0;i<tags.size();i++)
        tags[i].getGraph()->deleteGraph();
    return ret;
}
void AnnotationOutput::updateAnnotations()
{
  m_updateTimer->stop();
  m_currentFileAnnotations->clear();  
  readAnnotations();
  if (Project::ref()->hasProject() && Project::ref()->projectBaseURL().isLocalFile())
  {
    m_files = Project::ref()->files();
    m_fileIndex = 0;
    m_updateTimer->start(0, true);
  }
}
void AnnotationOutput::writeAnnotations(const QString &fileName, const QMap<uint, QPair<QString, QString> > &a_annotations)
{
  m_annotatedFileItems.clear();
  m_fileNames.clear();
  m_lines.clear();
  m_yourFileItems.clear();
  m_yourFileNames.clear();
  m_yourLines.clear();

  bool modified = false;
  QMap<uint, QPair<QString, QString> > annotations = a_annotations;
  QDomDocument *dom = Project::ref()->dom();
  QDomElement annotationElement = dom->firstChild().firstChild().namedItem("annotations").toElement();
  if (annotationElement.isNull())
  {
    annotationElement = dom->createElement("annotations");
    dom->firstChild().firstChild().appendChild(annotationElement);
  }
  QDomNode n = annotationElement.firstChild();
  while ( !n.isNull() ) 
  {
    QDomElement el = n.toElement();
    QString fName = el.attribute("url");
    QDomNode n2 = n.nextSibling();
    if (fileName == fName)    
    {
      QString text = el.attribute("text");
      bool ok;
      int line = el.attribute("line").toInt(&ok, 10);
      if (!annotations.contains(line) || (annotations[line].first != text))
      {
        n.parentNode().removeChild(n);
        modified = true;
      } else
        annotations.remove(line);
    }
    n = n2;
  }
  for (QMap<uint, QPair<QString, QString> >::ConstIterator it = annotations.constBegin(); it != annotations.constEnd(); ++it)
  {
    QDomElement el = dom->createElement("annotation");
    el.setAttribute("url", fileName);
    el.setAttribute("line", it.key());
    el.setAttribute("text", it.data().first);
    el.setAttribute("receiver", it.data().second.lower());
    annotationElement.appendChild(el);
    modified = true;
  }
  if (modified)
    Project::ref()->setModified(true);
  if (m_allAnnotations->isVisible() || m_yourAnnotations->isVisible())
    readAnnotations();
}
bool SwissProtPlainTextFormat::readEntry(ParserState* st, U2SequenceImporter& seqImporter, int& sequenceLen,int& fullSequenceLen, bool merge, int gapSize, U2OpStatus& os) {
    Q_UNUSED(merge);
    Q_UNUSED(gapSize);
    U2OpStatus& si = st->si;
    QString lastTagName;
    bool hasLine = false;
    while (hasLine || st->readNextLine(false)) {
        hasLine = false;
        if (st->entry->name.isEmpty()) {
            readIdLine(st);
            assert(si.hasError() || !st->entry->name.isEmpty());
            if (si.hasError()) {
                break;
            }
            continue;
        }
        //
        if (st->hasKey("FH") || st->hasKey("AH")) {
            continue;
        }
        if (st->hasKey("AC")) { //The AC (ACcession number) line lists the accession number(s) associated with an entry.
            QVariant v = st->entry->tags.value(DNAInfo::ACCESSION);
            QStringList l = st->value().split(QRegExp(";\\s*"), QString::SkipEmptyParts);
            st->entry->tags[DNAInfo::ACCESSION] = QVariantUtils::addStr2List(v, l);
            continue;
        }
        if (st->hasKey("OS")) { //The OS (Organism Species) line specifies the organism(s) which was (were) the source of the stored sequence.
            DNASourceInfo soi;
            soi.name = st->value();
            soi.organism = soi.name;
            while (st->readNextLine()) {
                if (st->hasKey("OS")) {
                    soi.organism.append(" ").append(st->value());
                } else if (!st->hasKey("XX")) {
                    break;
                }
            }
            if (st->hasKey("OC")) { //The OC (Organism Classification) lines contain the taxonomic classification of the source organism.
                soi.taxonomy += st->value();
                while (st->readNextLine()) {
                    if (st->hasKey("OC")) {
                        soi.taxonomy.append(st->value());
                    } else if (!st->hasKey("XX")) {
                        break;
                    }
                }
            }
            if (st->hasKey("OG")) { //The OG (OrGanelle) line indicates if the gene coding for a protein originates from the mitochondria, the chloroplast, a cyanelle, or a plasmid.
                soi.organelle = st->value();
            } else {
                hasLine = true;
            }
            st->entry->tags.insertMulti(DNAInfo::SOURCE, qVariantFromValue<DNASourceInfo>(soi));
            continue;
        }
        if (st->hasKey("RF") || st->hasKey("RN")) { //The RN (Reference Number) line gives a sequential number to each reference citation in an entry.
            while (st->readNextLine() && st->buff[0] == 'R')
            {
                //TODO
            }
            hasLine = true;
            continue;
        }
        /*The FT (Feature Table) lines provide a precise but simple means for the annotation of the sequence data.
          The table describes regions or sites of interest in the sequence.
          In general the feature table lists posttranslational modifications, binding sites, enzyme active sites, local secondary structure or other characteristics reported in the cited references.
        */
        if (st->hasKey("FT", 2)) {
            readAnnotations(st, fullSequenceLen + gapSize);
            hasLine = true;
            continue;
        }
        //read simple tag;
        if (st->hasKey("//", 2)) {
            // end of entry
            return true;
        }
        else if (st->hasKey("SQ", 2)) {
            //reading sequence
            readSequence(st,seqImporter,sequenceLen,fullSequenceLen,os);
            if (fullSequenceLen != st->entry->seqLen && !si.getWarnings().contains(EMBLGenbankAbstractDocument::SEQ_LEN_WARNING_MESSAGE)) {
                si.addWarning(EMBLGenbankAbstractDocument::SEQ_LEN_WARNING_MESSAGE);
            }
            CHECK_OP(os,false);
            return true;
        }

        QString key = st->key().trimmed();
        if (tagMap.contains(key)) {
            key = tagMap.value(key);
        }
        if (lastTagName == key) {
            QVariant v = st->entry->tags.take(lastTagName);
            v = QVariantUtils::addStr2List(v, st->value());
            st->entry->tags.insert(lastTagName, v);
        } else if (st->hasValue()) {
            lastTagName = key;
            st->entry->tags.insertMulti(lastTagName, st->value());
        }
    }
    if (!st->isNull() && !si.isCoR()) {
        si.setError(U2::EMBLGenbankAbstractDocument::tr("Record is truncated."));
    }

    return false;
}
void AnnotationOutput::tabChanged(QWidget *w)
{
 if (w == m_allAnnotations || w == m_yourAnnotations)
  readAnnotations();
}
Esempio n. 6
0
int main(int argc, char *argv[])
{
  int x,m;
  char *qs;
  entry *entries;
    
  int nbTrain,nbVal,nbDims,nbConcepts,c,**trainAnns,**valAnns,ret;
  char **trainList,**valList,**concepts,*name;
  float **trainDescriptors,**valDescriptors;
  
  /* récupération de la chaîne de paramètres */
  qs = get_query_string(argc,argv);

  /* récupération des couples (nom,valeur) */
  entries = get_entries(qs,&m);

  /* émission de l'entête */
  print_html_head("R&eacute;sultat");

  /* affichage éventuel des informations de debug */
  if (DEBUG) print_debug_query(entries,m,qs,argc,argv);

  trainList = readList("/usr/lib/cgi-bin/RIM/images/train/list.txt",&nbTrain);
  if (trainList == NULL) {printf("Failed to read %s file.\n","train/list.txt"); exitfail();}
  if (DEBUG) printf("Read train list, %d images.<BR>\n",nbTrain);
  
  valList = readList("/usr/lib/cgi-bin/RIM/images/val/list.txt",&nbVal);
  if (valList == NULL) {printf("Failed to read %s file.\n","val/list.txt"); exitfail();}
  if (DEBUG) printf("Read val list, %d images.<BR>\n",nbVal);
  
  trainDescriptors = readDescriptors("/usr/lib/cgi-bin/RIM/images/train/descriptors.bin",nbTrain,&nbDims);
  if (trainDescriptors == NULL) {printf("Failed to read %s file.\n","train/descriptors.bin"); exitfail();}
  if (DEBUG) printf("Read train descripors, %d images, %d dimensions.<BR>\n",nbTrain,nbDims);
  
  valDescriptors = readDescriptors("/usr/lib/cgi-bin/RIM/images/val/descriptors.bin",nbVal,&nbDims);
  if (valDescriptors == NULL) {printf("Failed to read %s file.\n","val/descriptors.bin"); exitfail();}
  if (DEBUG) printf("Read val descripors, %d images, %d dimensions.<BR>\n",nbVal,nbDims);
  
  concepts = readList("/usr/lib/cgi-bin/RIM/images/concepts.txt",&nbConcepts);
  if (concepts == NULL) {printf("Failed to read %s file.\n","concepts.txt"); exitfail();}
  if (DEBUG) printf("Read concept list, %d concepts.<BR>\n",nbConcepts);
  
  trainAnns = malloc(nbConcepts*sizeof(int *));
  if (trainAnns == NULL) {printf("malloc() failed.\n"); exitfail();}
  if (DEBUG) printf("Read train annotations:");
  for (c = 0; c < nbConcepts; c ++) {
    ret = asprintf(&name,"/usr/lib/cgi-bin/RIM/images/train/ann/%s.ann",concepts[c]);
    if (ret < 0) {printf("asprintf() failed.\n"); exitfail();}
    trainAnns[c] = readAnnotations(name,nbTrain);
    if (trainAnns[c] == NULL) {printf("Failed to read train/ann%s.ann file.\n",concepts[c]); exitfail();}
    if (DEBUG) printf(" %s",concepts[c]);
  }
  if (DEBUG) printf(".<BR>\n");
  
  valAnns = malloc(nbConcepts*sizeof(int *));
  if (valAnns == NULL) {printf("malloc() failed.\n"); exitfail();}
  if (DEBUG) printf("Read val annotations:");
  for (c = 0; c < nbConcepts; c ++) {
    ret = asprintf(&name,"/usr/lib/cgi-bin/RIM/images/val/ann/%s.ann",concepts[c]);
    if (ret < 0) {printf("asprintf() failed.\n"); exitfail();}
    valAnns[c] = readAnnotations(name,nbVal);
    if (valAnns[c] == NULL) {printf("Failed to read val/ann%s.ann file.\n",concepts[c]); exitfail();}
    if (DEBUG) printf(" %s",concepts[c]);
  }
  if (DEBUG) printf(".<BR>\n");
  
  /* émission de la fin de corps et de document */
  print_html_tail();
    
  exit(0);
}