Esempio n. 1
0
double
SortedDistanceComparator::compareStructures(
    const SortedDistanceComparisonData & dist1,
    const SortedDistanceComparisonData & dist2) const
{
  typedef StridedIndexAdapter< size_t> IndexAdapter;

  const size_t numSpecies = dist1.species.size();
  if(numSpecies != dist2.species.size())
    return std::numeric_limits< double>::max(); // Species mismatch

  std::set< std::string> speciesCheck(dist1.species.begin(),
      dist1.species.end());
  std::set< std::string>::const_iterator it;
  BOOST_FOREACH(const std::string & species2, dist2.species)
  {
    it = speciesCheck.find(species2);
    if(it == speciesCheck.end())
      return std::numeric_limits< double>::max(); // Species mismatch
    else
      speciesCheck.erase(it);
  }
  if(!speciesCheck.empty())
    return std::numeric_limits< double>::max(); // Species mismatch

  // Set up the adapters
  const unsigned int leastCommonMultiple = math::leastCommonMultiple(
      dist1.numAtoms, dist2.numAtoms);
  IndexAdapter adapt1(leastCommonMultiple / dist1.numAtoms);
  IndexAdapter adapt2(leastCommonMultiple / dist2.numAtoms);

  spl::math::RunningStats stats;
  common::AtomSpeciesId::Value specI, specJ;
  for(size_t i = 0; i < numSpecies; ++i)
  {
    specI = dist1.species[i];

    // Do others
    const SortedDistanceComparisonData::DistancesMap & distMapI1 =
        dist1.speciesDistancesMap(specI);
    const SortedDistanceComparisonData::DistancesMap & distMapI2 =
        dist2.speciesDistancesMap(specI);
    for(size_t j = i; j < numSpecies; ++j)
    {
      specJ = dist1.species[j];
      calcProperties(stats, *distMapI1(specJ), adapt1, *distMapI2(specJ),
          adapt2);
    }
  }

  return stats.rms();
}
static void AllocationGenerateScriptMips(RsContext con, RsAllocation va) {
    Context *rsc = static_cast<Context *>(con);
    Allocation *texAlloc = static_cast<Allocation *>(va);
    uint32_t numFaces = texAlloc->getType()->getDimFaces() ? 6 : 1;
    for (uint32_t face = 0; face < numFaces; face ++) {
        Adapter2D adapt(rsc, texAlloc);
        Adapter2D adapt2(rsc, texAlloc);
        adapt.setFace(face);
        adapt2.setFace(face);
        for (uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
            adapt.setLOD(lod);
            adapt2.setLOD(lod + 1);
            mip(adapt2, adapt);
        }
    }
}
double SortedDistanceComparator::compareStructures(
		const SortedDistanceComparisonData & dist1,
		const SortedDistanceComparisonData & dist2) const
{
  typedef ::std::vector<double> DistancesVec;
  typedef StridedIndexAdapter<size_t> IndexAdapter;

  const size_t numSpecies = dist1.species.size();

  if(numSpecies != dist2.species.size())
  {
    // Species mismatch!
    return ::std::numeric_limits<double>::max();
  }

  // Set up the adapters
  const unsigned int leastCommonMultiple = math::leastCommonMultiple(dist1.numAtoms, dist2.numAtoms);
  IndexAdapter adapt1(leastCommonMultiple / dist1.numAtoms);
  IndexAdapter adapt2(leastCommonMultiple / dist2.numAtoms);

  double max = ::std::numeric_limits<double>::min();
  double sqSum = 0.0;
  unsigned int totalCompared = 0;
  common::AtomSpeciesId::Value specI, specJ;
  for(size_t i = 0; i < numSpecies - 1; ++i)
  {
    specI = dist1.species[i];
    
    // Do others
    const SortedDistanceComparisonData::DistancesMap & distMapI1 = dist1.speciesDistancesMap(specI);
    const SortedDistanceComparisonData::DistancesMap & distMapI2 = dist2.speciesDistancesMap(specI);
    for(size_t j = i; j < numSpecies; ++j)
    {
      specJ = dist1.species[j];
      calcProperties(*distMapI1(specJ), adapt1, *distMapI2(specJ), adapt2, sqSum, max, totalCompared);
    }
  }

  return sqrt(sqSum / totalCompared);
  //return max;
}
Esempio n. 4
0
int main(int argc, char *argv[])
{
  b_po::variables_map vmgeneral;
  parsecommandlineExtract(argc, argv, vmgeneral);
  ralab::findmf::apps::Params aparam;
  analysisParameters(aparam,vmgeneral);
  int res = 0;
  boost::filesystem::path p1,p2;

  {
    // LOG(INFO)  << "i::::" << i << std::endl;
    p1 = ralab::findmf::createOutputs(aparam.infile,"");
    p2 = ralab::findmf::createOutputs(aparam.infile,"filtered");

    if( !boost::filesystem::exists(aparam.infile) )
    {
      return -1;
    }

    ralab::findmf::datastruct::MSFileInfoPtr sip;
    try{
      ralab::findmf::SwathPropertiesReader swathPropReader(aparam.infile);
      sip = swathPropReader.getSwathInfo();
    } catch(std::exception & e){
      std::cerr << "infile : " << aparam.infile << std::endl;
      std::cerr  << "can't open file: " << e.what() << std::endl;
      return 0;
    }

    double ppm = aparam.ppm;
    pwiz::msdata::MSDataPtr msdataptr = pwiz::msdata::MSDataPtr(new pwiz::msdata::MSDataFile(aparam.infile));
    ralab::findmf::LCMSImageReader sm(msdataptr, sip, ppm, aparam.rt2sum_ );
    ralab::findmf::datastruct::LCMSImage mp;
    sm.getMap( 0 , aparam.minmass, aparam.maxmass, mp);
    // LOG(INFO) << " " << mp.getMZsize() << " " << mp.getRTsize();

    ralab::findmf::datastruct::LCMSImage mp2( mp );
    {
      ralab::findmf::LCMSImageFilterGauss imgf;
      // imgf.filterMap( mp2.getImageMap().getMap() , aparam.mzpixelwidth , aparam.rtpixelwidth, aparam.mzscale, aparam.rtscale);

      imgf.filter( mp2.getImageMap().getMap() , aparam.mzpixelwidth , aparam.rtpixelwidth, aparam.mzscale, aparam.rtscale);
      mp2.getImageMap().updateImageRange();
      std::cout << mp2.getImageMap().getImageMin() << std::endl;
      //imgf.filterMap();
    }

    // feature finding
    ralab::findmf::FeatureFinderLocalMax ff;
    ff.findFeature( mp2.getImageMap().getMap() , aparam.minintensity );

    ralab::findmf::datastruct::FeaturesMap map;
    map.setMapDescription(mp2.getMapDescription());
    ralab::findmf::ComputeFeatureStatistics cfs;
    cfs.extractFeatures(map,mp2.getImageMap().getMap(),ff.getLabels());

    //this writes the accessor....
   cfs.writeFeatures(aparam.outdir , p1.stem().string() );

    ralab::FeaturesMapPrinter fp;
    fp.writeFeatures(aparam.outdir , p1.stem().string(), map);

    ralab::MultiArrayVisSegments<int> mavL( ff.getLabels() );
    //write filtered data into mzML file

    //TODO check why this isn't working
    sm.write( p2.string() , mp2 );

    if(1){
      QApplication app(argc, argv);
      ralab::TwoPaneledImageWidget tpi;
      ralab::MultiArrayVisLog<float> adapt2( mp2.getImageMap().getMap() );

      ralab::MultiArrayVisAsinh<float> adapt1( mp2.getImageMap().getMap() );
      ralab::MultiArrayVisLog<float> adapt0( mp.getImageMap().getMap() );

      tpi.setTopMap(&mavL);
      //tpi.setBottomMap(&adapt0);
      tpi.setBottomMap(&adapt0);

      tpi.show();
      res = app.exec();
    }
  }
  return res;
}