Common::String SciEngine::unwrapFilename(const Common::String &name) const { Common::String prefix = getFilePrefix() + "-"; if (name.hasPrefix(prefix.c_str())) return Common::String(name.c_str() + prefix.size()); else return name; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void WriteImages::readFilterParameters(AbstractFilterParametersReader* reader, int index) { reader->openFilterGroup(this, index); setImagePrefix( reader->readString("ImagePrefix", getImagePrefix()) ); setFilePrefix( reader->readValue("FilePrefix", getFilePrefix()) ); setOutputPath( reader->readString("OutputPath", getOutputPath()) ); setColorsArrayPath( reader->readDataArrayPath("ColorsArrayPath", getColorsArrayPath()) ); setImageFormat( reader->readValue("ImageFormat", getImageFormat()) ); setPlane(reader->readValue("Plane", getPlane())); reader->closeFilterGroup(); }
Common::String SciEngine::wrapFilename(const Common::String &name) const { return getFilePrefix() + "-" + name; }
// ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- void WriteImages::setupFilterParameters() { FilterParameterVector parameters; { ChoiceFilterParameter::Pointer parameter = ChoiceFilterParameter::New(); parameter->setHumanLabel("Image Format"); parameter->setPropertyName("ImageFormat"); QVector<QString> choices; choices.push_back("tif"); choices.push_back("bmp"); choices.push_back("png"); parameter->setChoices(choices); parameter->setCategory(FilterParameter::Parameter); parameters.push_back(parameter); } { ChoiceFilterParameter::Pointer parameter = ChoiceFilterParameter::New(); parameter->setHumanLabel("Plane"); parameter->setPropertyName("Plane"); QVector<QString> choices; choices.push_back("XY"); choices.push_back("XZ"); choices.push_back("YZ"); parameter->setChoices(choices); parameter->setCategory(FilterParameter::Parameter); parameters.push_back(parameter); } { QStringList linkedProps; linkedProps << "ImagePrefix"; parameters.push_back(LinkedBooleanFilterParameter::New("File Prefix", "FilePrefix", getFilePrefix(), linkedProps, FilterParameter::Parameter)); } parameters.push_back(OutputPathFilterParameter::New("Output Directory Path", "OutputPath", getOutputPath(), FilterParameter::Parameter)); parameters.push_back(StringFilterParameter::New("Image File Prefix", "ImagePrefix", getImagePrefix(), FilterParameter::Parameter)); parameters.push_back(SeparatorFilterParameter::New("Cell Data", FilterParameter::RequiredArray)); parameters.push_back(DataArraySelectionFilterParameter::New("Color Data", "ColorsArrayPath", getColorsArrayPath(), FilterParameter::RequiredArray)); setFilterParameters(parameters); }
int main(int argc, char const * argv[]) { // Additional checks seqan::ArgumentParser parser = buildParser(); seqan::ArgumentParser::ParseResult res = seqan::parse(parser, argc, argv); // Check if input was successfully parsed. if (res != seqan::ArgumentParser::PARSE_OK) return res == seqan::ArgumentParser::PARSE_ERROR; // Check if one or two input files (single or paired-end) were given. int fileCount = getArgumentValueCount(parser, 0); if (fileCount < 1) { printShortHelp(parser); return 1; } unsigned int radius = 1; getOptionValue(radius, parser, "r"); seqan::CharString readsFileName; getOptionValue(readsFileName, parser, "i"); // Open input file, BamFileIn can read SAM and BAM files. seqan::BamFileIn bamFileIn(seqan::toCString(readsFileName)); seqan::CharString _filterChromosomes; seqan::getOptionValue(_filterChromosomes, parser, "fc"); std::string filterChromosomes = seqan::toCString(_filterChromosomes); OccurenceMap occurenceMap; Statistics stats; std::cout << "read bam file... "; auto t1 = std::chrono::steady_clock::now(); seqan::BamAlignmentRecord record; seqan::BamHeader header; readHeader(header, bamFileIn); const auto chromosomeFilterSet = calculateChromosomeFilter(filterChromosomes, contigNames(context(bamFileIn))); const auto chromosomes = contigNames(context(bamFileIn)); processBamFile(bamFileIn, chromosomeFilterSet, occurenceMap, stats); auto t2 = std::chrono::steady_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::duration<float>>(t2 - t1).count() << "s" << std::endl; std::vector<std::pair<unsigned int, unsigned int>> hits(radius * 2 + 1); t1 = std::chrono::steady_clock::now(); std::cout << "calculating 5'-ends around peaks... "; for (unsigned int fileIndex = 0;fileIndex < static_cast<unsigned int>(fileCount); ++fileIndex) { seqan::CharString fileName_; getArgumentValue(fileName_, parser, fileIndex, 0); const std::string fileName = seqan::toCString(fileName_); std::ifstream infile(fileName); std::string chromosome, dummy; unsigned int start, end; while (infile >> chromosome >> start >> end >> dummy) { int rID = -1; for (unsigned int i = 0;i < length(chromosomes);++i) if (chromosomes[i] == chromosome) { rID = i; break; } if (rID == -1) { std::cout << "invalid chromosome name: " << chromosome << " in file " << fileName << std::endl; return -1; } seqan::BamAlignmentRecord record; record.beginPos = std::max<int>(start - radius, 0); record.rID = rID; record.flag = 0; unsigned int index = 0; if (start < radius) index += radius - start; while (record.beginPos <= static_cast<__int32>(start + radius)) { BamRecordKey<NoBarcode> pos(record); auto el = occurenceMap.find(pos); if(el != occurenceMap.end()) hits[index].first += el->second; pos.init(pos.getRID(), pos.get5EndPosition(), true); el = occurenceMap.find(pos); if (el != occurenceMap.end()) hits[index].second += el->second; ++record.beginPos; ++index; } } std::string outFilename = getFilePrefix(fileName) + std::string("_5PrimeEnds.tab"); if (seqan::isSet(parser, "o")) { seqan::CharString outFileName_; getOptionValue(outFileName_, parser, "o"); outFilename = seqan::toCString(outFileName_); } std::fstream fs; std::cout << "writing " << outFilename << std::endl; #ifdef _MSC_VER fs.open(outFilename, std::fstream::out, _SH_DENYNO); #else fs.open(outFilename, std::fstream::out); #endif int i = - static_cast<int>(radius); for (const auto& hit : hits) fs << i++ << "\t" << hit.first << "\t" << hit.second << std::endl; fs.close(); } t2 = std::chrono::steady_clock::now(); std::cout << std::chrono::duration_cast<std::chrono::duration<float>>(t2 - t1).count() << "s" << std::endl; return 0; }