Пример #1
0
	bool CSVData::loadFromTextReader(TextReader& reader, const StringView separators, const StringView quotes, const StringView escapes)
	{
		if (!reader)
		{
			return false;
		}

		const boost::escaped_list_separator<char32> separator(escapes.to_string(), separators.to_string(), quotes.to_string());

		String str;

		m_data.clear();

		while (reader.readLine(str))
		{
			try
			{
				const boost::tokenizer<boost::escaped_list_separator<char32>, String::const_iterator, String> tokens(str, separator);

				m_data.emplace_back(tokens.begin(), tokens.end());
			}
			catch (boost::exception&)
			{
				str.replace(U"\\", U"\\\\");

				const boost::tokenizer<boost::escaped_list_separator<char32>, String::const_iterator, String> tokens(str, separator);

				m_data.emplace_back(tokens.begin(), tokens.end());
			}
		}

		return true;
	}
Пример #2
0
void SplitBam(const BamRecord& record
              , BamRecord& outbam
              , const StringView& run_name
              , const StringView& zmw
              , int left_start
              , int right_end
              , const StripedSmithWaterman::Alignment& alignment
             ) {
    // name
    stringstream name;
    name << run_name.to_string() << '/' << zmw << '/';
    if (is_left) {
        name << left_start << '_' << (left_start + alignment.ref_begin);
    } else {
        name << (left_start + alignment.ref_end + 1) << '_' << right_end;
    }
    outbam.Impl().Name(name.str());
    // sequence
    outbam.Impl().SetSequenceAndQualities(
        is_left ?
        record.Sequence().substr(0, alignment.ref_begin) :
        record.Sequence().substr(alignment.ref_end + 1)
        , ""
    );
    // tags
    const auto& original_tags = record.Impl().Tags();
    TagCollection newtags;
    // direct copy tags
    for (auto t  : {"RG", "np", "rq", "sn", "zm"}) {
        newtags[t] = original_tags.at(t);
    }
    // tags need to substr
    for (auto t : {"dq", "dt", "iq", "mq", "sq"}) {
        if (is_left)
            newtags[t] = original_tags.at(t).ToString().substr(0, alignment.ref_begin);
        else
            newtags[t] = original_tags.at(t).ToString().substr(alignment.ref_end + 1);
    }
    // special tag
    newtags["qs"] = (is_left ? left_start : left_start + alignment.ref_end + 1);
    newtags["qe"] = (is_left ? left_start + alignment.ref_begin : right_end);
    newtags["cx"] = original_tags.at("cx").ToUInt8()
        | (is_left ? PacBio::BAM::LocalContextFlags::ADAPTER_BEFORE : PacBio::BAM::LocalContextFlags::ADAPTER_AFTER);
    // TODO: this can be more efficient
    auto vec = record.IPD().Encode();
    if (is_left) {
        newtags["ip"] = decltype(vec){vec.cbegin(), vec.cbegin() + alignment.ref_begin};
    } else {
        newtags["ip"] = decltype(vec){vec.cbegin() + alignment.ref_end + 1, vec.cend()};
    }
    outbam.Impl().Tags(newtags);
}
Пример #3
0
    /*
     * Also does implicit conversions form std::string and const char*
     */
    std::size_t getColumnIndex(StringView columnName)
    {
        auto& columnNameMappings = getColumnNameMappingsRef();

        using std::begin;
        using std::end;
        auto it = std::lower_bound(begin(columnNameMappings), end(columnNameMappings), columnName, [](auto&& elem, auto&& value) {
            return std::get<0>(elem) < value;
        });

        if (it != end(columnNameMappings) && !(columnName < std::get<0>(*it)))
        {
            return std::get<1>(*it);
        }
        else
        {
            throw OutOfRange{"Column name \"" + columnName.to_string() + "\" not found!"};
        }
    }
Пример #4
0
bool StringViewTo(const StringView& s, T& t) {
    std::istringstream ss(s.to_string());
    ss >> t;
    return ss.fail() ? false : true;
}