Пример #1
0
Файл: fill.c Проект: cgd/hmmSNP
/*******************************************************************************
 * fill_and_save - fill in missing genotypes and save the result
 *
 * INPUTS: snp_t *snps - array of snp_t structs
 *         em_params_t *em_params - input parameters for hmm_em()
 *         em_out_t *em_out - output of hmm_em()
 *         int path_option - which path algorithm was used
 *         int sort_option - state sorting option (for path output)
 *         double threshold - confidence threshold for filtered output
 *         int num_emission_types - 2 or 3 depending if missing is a valid emission type
 *         int chromosome - which chromosome was processed
 *         int smooth_out - boolean value to instruct maxSmthPath to write out
 *             the smoothness information
 *         double **fill_probability_matrix - pointer to memory to store filling probabilities 
 *         
 *
 * RETURNS:
 *      funciton returns void, filling probabilities returned via parameter
 *
 * ASSUMES:
 *
 * EFFECTS:  modifies contents of fill_probability_matrix, writes filled file and path file
 *
 * ERROR CONDITIONS:
 *
 * COMMENTS:
 *
 ******************************************************************************/
void fill_and_save(snp_t *snps, em_params_t *em_params, em_out_t *em_out, 
                   int path_option, int sort_option, double threshold,
                   int num_emission_types, int chromosome, int smooth_out,
                   double **fill_probability_matrix)
{
  clock_t tStart;
  clock_t tEnd;
  int **path_matrix;
  double **log_prob_matrix = NULL;

  assert(path_option == PATH_VITERBI || path_option == PATH_MAXSMTH);
  
  path_matrix = allocate2Di(em_params->num_snps, em_params->num_strains);

  tStart = clock();
  
  if (path_option == PATH_VITERBI)
  {
    printf("Calculating Viterbi path...");
    log_prob_matrix = allocate2Dd(em_params->num_snps, em_params->num_strains);

    viterbiPath(em_params, em_out, path_matrix, log_prob_matrix,
               fill_probability_matrix);
  }
  else
  {
    printf("Calculating max smooth path...");
    maxSmthPath(em_params, em_out, em_params->file_prefix, smooth_out, 
                path_matrix, fill_probability_matrix);
  }
  
  tEnd = clock();
  
  printf("Done (%.2fs)\n", ((double)(tEnd - tStart)) / CLOCKS_PER_SEC);
          
  /* write the path to a file */                
  writePath(snps, path_matrix, em_params->num_snps, 
            em_params->num_strains, em_params->file_prefix, 
            path_option, chromosome, sort_option, 
            em_out->last_emission_matrix);
  
  /* if random missing then fill in using path */
  if ( em_params->miss_option > 0)
  {
    fillin(em_params->snps,  path_matrix, em_out->last_emission_matrix, 
           em_params->num_snps, em_params->num_strains, num_emission_types, 
           fill_probability_matrix);
  
    writeFilledData(snps, chromosome, fill_probability_matrix,
                    em_params->file_prefix, path_option, sort_option, 
                    threshold, em_params->num_snps);
  }

  free2Di(path_matrix, em_params->num_snps);
  if (path_option == PATH_VITERBI)
  {
    free2Dd(log_prob_matrix, em_params->num_snps);
  }
}
int PathPlanner::runRRT(){
	this->RRT();
	calcPathLength();
	writePath();
	writeMetadata();
	cout<<"Estimated path length: "<<this->pathLength<<"\n";
	return 0;
}
void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
{
    writeClip();

    Path p (path);
    p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
    writePath (p);
    out << "clip\n";
}
int PathPlanner::runSquareSpiral(){
	Points spiralpath = this->getSpiralPath();	
	this->setPath(spiralpath);
	calcPathLength();
	writePath();
	writeMetadata();
	cout<<"Estimated path length: "<<this->pathLength<<"\n";
	return 0;
}
//In a perfect world these would have some kind of error checking. I like to live dangerously....
int PathPlanner::runTrace(){
	vector<Polygon_2> all = this->linearShrink();
	this->setPath(all);
	calcPathLength();
	writePath();
	writeMetadata();
	cout<<"Estimated path length: "<<this->pathLength<<"\n";
	return 0;
}
//==============================================================================
void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
{
    if (stateStack.getLast()->fillType.isColour())
    {
        writeClip();

        Path p (path);
        p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
                                        (float) stateStack.getLast()->yOffset));
        writePath (p);

        writeColour (stateStack.getLast()->fillType.colour);

        out << "fill\n";
    }
    else if (stateStack.getLast()->fillType.isGradient())
    {
        // this doesn't work correctly yet - it could be improved to handle solid gradients, but
        // postscript can't do semi-transparent ones.
        notPossibleInPostscriptAssert   // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file

        writeClip();
        out << "gsave ";

        {
            Path p (path);
            p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
            writePath (p);
            out << "clip\n";
        }

        const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());

        // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
        // time-being, this just fills it with the average colour..
        writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
        out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";

        out << "grestore\n";
    }
}
Пример #7
0
bool side::enter()
{
	if (filesPath.size() < 2 && !(_stricmp(files[indexFile].name, "..")))
		return false;
	else if (!(_stricmp(files[indexFile].name, "..")))  //..
	{
		string tName(filesPath.back());
		filesPath.pop_back();
		makePath();
		if (!fillFiles())
			throw string("Can't read the directory: " + path);
		indexFile = getIndexByNameInCurrent(tName);
		if (indexFile >= side::countFiles)  // не вміщається в першу (значить хз :) десь посерединці поставимо :))
		{
			indexRow = 10;
			upIndexFile = indexFile - 10;
		}
		else // ваміщається в перший комлект
		{
			upIndexFile = 0;
			indexRow = indexFile;
		}
		show();
		writePath();
		return true;
	}
	else if ((_stricmp(files[indexFile].name, "..")) && !(files[indexFile].attrib & _A_SUBDIR))
		return false;
	else   // not .. but folder
	{
		filesPath.emplace_back(files[indexFile].name);
		makePath();
		if (!fillFiles())
			throw string("Can't read the directory: " + path);
		clearIndex();
		show();
		writePath();
		return true;
	}
	
}
Пример #8
0
bool QgsProject::write()
{
  clearError();

  // if we have problems creating or otherwise writing to the project file,
  // let's find out up front before we go through all the hand-waving
  // necessary to create all the Dom objects
  if ( !imp_->file.open( QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate ) )
  {
    imp_->file.close();         // even though we got an error, let's make
    // sure it's closed anyway

    setError( tr( "Unable to save to file %1" ).arg( imp_->file.fileName() ) );
    return false;
  }
  QFileInfo myFileInfo( imp_->file );
  if ( !myFileInfo.isWritable() )
  {
    // even though we got an error, let's make
    // sure it's closed anyway
    imp_->file.close();
    setError( tr( "%1 is not writable. Please adjust permissions (if possible) and try again." )
              .arg( imp_->file.fileName() ) );
    return false;
  }

  QDomImplementation DomImplementation;

  QDomDocumentType documentType =
    DomImplementation.createDocumentType( "qgis", "http://mrcc.com/qgis.dtd",
                                          "SYSTEM" );
  std::auto_ptr < QDomDocument > doc =
    std::auto_ptr < QDomDocument > ( new QDomDocument( documentType ) );


  QDomElement qgisNode = doc->createElement( "qgis" );
  qgisNode.setAttribute( "projectname", title() );
  qgisNode.setAttribute( "version", QString( "%1" ).arg( QGis::QGIS_VERSION ) );

  doc->appendChild( qgisNode );

  // title
  QDomElement titleNode = doc->createElement( "title" );
  qgisNode.appendChild( titleNode );

  QDomText titleText = doc->createTextNode( title() );  // XXX why have title TWICE?
  titleNode.appendChild( titleText );

  // let map canvas and legend write their information
  emit writeProject( *doc );

  // within top level node save list of layers
  QMap<QString, QgsMapLayer*> & layers = QgsMapLayerRegistry::instance()->mapLayers();

  // Iterate over layers in zOrder
  // Call writeXML() on each
  QDomElement projectLayersNode = doc->createElement( "projectlayers" );
  projectLayersNode.setAttribute( "layercount", qulonglong( layers.size() ) );

  QMap<QString, QgsMapLayer*>::iterator li = layers.begin();
  while ( li != layers.end() )
  {
    //QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer(*li);
    QgsMapLayer* ml = li.value();

    if ( ml )
    {
      QString externalProjectFile = layerIsEmbedded( ml->id() );
      QHash< QString, QPair< QString, bool> >::const_iterator emIt = mEmbeddedLayers.find( ml->id() );
      if ( emIt == mEmbeddedLayers.constEnd() )
      {
        ml->writeXML( projectLayersNode, *doc );
      }
      else //layer defined in an external project file
      {
        //only save embedded layer if not managed by a legend group
        if ( emIt.value().second )
        {
          QDomElement mapLayerElem = doc->createElement( "maplayer" );
          mapLayerElem.setAttribute( "embedded", 1 );
          mapLayerElem.setAttribute( "project", writePath( emIt.value().first ) );
          mapLayerElem.setAttribute( "id", ml->id() );
          projectLayersNode.appendChild( mapLayerElem );
        }
      }
    }
    li++;
  }

  qgisNode.appendChild( projectLayersNode );

  // now add the optional extra properties

  dump_( imp_->properties_ );

  QgsDebugMsg( QString( "there are %1 property scopes" ).arg( static_cast<int>( imp_->properties_.count() ) ) );

  if ( !imp_->properties_.isEmpty() ) // only worry about properties if we
    // actually have any properties
  {
    imp_->properties_.writeXML( "properties", qgisNode, *doc );
  }

  // now wrap it up and ship it to the project file
  doc->normalize();             // XXX I'm not entirely sure what this does

  //QString xml = doc->toString(4); // write to string with indentation of four characters
  // (yes, four is arbitrary)

  // const char * xmlString = xml; // debugger probe point
  // qDebug( "project file output:\n\n" + xml );

  QTextStream projectFileStream( &imp_->file );

  //projectFileStream << xml << endl;
  doc->save( projectFileStream, 4 );  // save as utf-8
  imp_->file.close();

  // check if the text stream had no error - if it does
  // the user will get a message so they can try to resolve the
  // situation e.g. by saving project to a volume with more space
  //
  if ( projectFileStream.pos() == -1  || imp_->file.error() != QFile::NoError )
  {
    setError( tr( "Unable to save to file %1. Your project "
                  "may be corrupted on disk. Try clearing some space on the volume and "
                  "check file permissions before pressing save again." )
              .arg( imp_->file.fileName() ) );
    return false;
  }

  dirty( false );               // reset to pristine state

  emit projectSaved();

  return true;
} // QgsProject::write