inline int32_t left() const { if (isPaired()) { return std::min(bam_pos(read1), bam_pos(read2)); } else { return bam_pos(read1); } }
void LanPairingHandler::packageReceived(const NetworkPackage& np) { m_pairingTimeout.stop(); bool wantsPair = np.get<bool>(QStringLiteral("pair")); if (wantsPair) { if (isPairRequested()) { //We started pairing qCDebug(KDECONNECT_CORE) << "Pair answer"; setInternalPairStatus(Paired); } else { qCDebug(KDECONNECT_CORE) << "Pair request"; if (isPaired()) { //I'm already paired, but they think I'm not acceptPairing(); return; } Daemon::instance()->askPairingConfirmation(this); setInternalPairStatus(RequestedByPeer); } } else { //wantsPair == false qCDebug(KDECONNECT_CORE) << "Unpair request"; setInternalPairStatus(NotPaired); if (isPairRequested()) { Q_EMIT pairingError(i18n("Canceled by other peer")); } } }
/** * returns 0 on success, -1 on failure. */ int writeToFile(scram_fd* fp) { int r1 = scram_put_seq(fp, read1); if (r1 == 0 and isPaired()) { return scram_put_seq(fp, read2); } else { return r1; } }
inline int32_t right() const { if (isPaired()) { return std::max(bam_pos(read1) + bam_seq_len(read1), bam_pos(read2) + bam_seq_len(read2)); } else { return bam_pos(read1) + bam_seq_len(read1); } }
void Device::reloadPlugins() { QHash<QString, KdeConnectPlugin*> newPluginMap; QMultiMap<QString, KdeConnectPlugin*> newPluginsByIncomingInterface; QMultiMap<QString, KdeConnectPlugin*> newPluginsByOutgoingInterface; QSet<QString> supportedIncomingInterfaces; QSet<QString> supportedOutgoingInterfaces; QStringList unsupportedPlugins; if (isPaired() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices KConfigGroup pluginStates = KSharedConfig::openConfig(pluginsConfigFile())->group("Plugins"); PluginLoader* loader = PluginLoader::instance(); const bool deviceSupportsCapabilities = !m_incomingCapabilities.isEmpty() || !m_outgoingCapabilities.isEmpty(); foreach (const QString& pluginName, loader->getPluginList()) { const KPluginMetaData service = loader->getPluginInfo(pluginName); const QSet<QString> incomingInterfaces = KPluginMetaData::readStringList(service.rawData(), "X-KdeConnect-SupportedPackageType").toSet(); const QSet<QString> outgoingInterfaces = KPluginMetaData::readStringList(service.rawData(), "X-KdeConnect-OutgoingPackageType").toSet(); const bool pluginEnabled = isPluginEnabled(pluginName); if (pluginEnabled) { supportedIncomingInterfaces += incomingInterfaces; supportedOutgoingInterfaces += outgoingInterfaces; } //If we don't find intersection with the received on one end and the sent on the other, we don't //let the plugin stay //Also, if no capabilities are specified on the other end, we don't apply this optimizaton, as //we assume that the other client doesn't know about capabilities. const bool capabilitiesSupported = deviceSupportsCapabilities && (!incomingInterfaces.isEmpty() || !outgoingInterfaces.isEmpty()); if (capabilitiesSupported && (m_incomingCapabilities & outgoingInterfaces).isEmpty() && (m_outgoingCapabilities & incomingInterfaces).isEmpty() ) { qCWarning(KDECONNECT_CORE) << "not loading " << pluginName << "because of unmatched capabilities"; unsupportedPlugins.append(pluginName); continue; } if (pluginEnabled) { KdeConnectPlugin* plugin = m_plugins.take(pluginName); if (!plugin) { plugin = loader->instantiatePluginForDevice(pluginName, this); } foreach(const QString& interface, incomingInterfaces) { newPluginsByIncomingInterface.insert(interface, plugin); } foreach(const QString& interface, outgoingInterfaces) { newPluginsByOutgoingInterface.insert(interface, plugin); } newPluginMap[pluginName] = plugin; }
void Device::reloadPlugins() { QHash<QString, KdeConnectPlugin*> newPluginMap; QMultiMap<QString, KdeConnectPlugin*> newPluginsByIncomingInterface; QMultiMap<QString, KdeConnectPlugin*> newPluginsByOutgoingInterface; if (isPaired() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices KConfigGroup pluginStates = KSharedConfig::openConfig(pluginsConfigFile())->group("Plugins"); PluginLoader* loader = PluginLoader::instance(); //Code borrowed from KWin foreach (const QString& pluginName, loader->getPluginList()) { QString enabledKey = pluginName + QString::fromLatin1("Enabled"); bool isPluginEnabled = (pluginStates.hasKey(enabledKey) ? pluginStates.readEntry(enabledKey, false) : loader->getPluginInfo(pluginName).isEnabledByDefault()); if (isPluginEnabled) { KdeConnectPlugin* plugin = m_plugins.take(pluginName); QStringList incomingInterfaces, outgoingInterfaces; if (plugin) { incomingInterfaces = m_pluginsByIncomingInterface.keys(plugin); outgoingInterfaces = m_pluginsByOutgoingInterface.keys(plugin); } else { const KPluginMetaData service = loader->getPluginInfo(pluginName); incomingInterfaces = KPluginMetaData::readStringList(service.rawData(), "X-KdeConnect-SupportedPackageType"); outgoingInterfaces = KPluginMetaData::readStringList(service.rawData(), "X-KdeConnect-OutgoingPackageType"); } //If we don't find intersection with the received on one end and the sent on the other, we don't //let the plugin stay //Also, if no capabilities are specified on the other end, we don't apply this optimizaton, as //we assume that the other client doesn't know about capabilities. if (!m_incomingCapabilities.isEmpty() && !m_outgoingCapabilities.isEmpty() && (m_incomingCapabilities & outgoingInterfaces.toSet()).isEmpty() && (m_outgoingCapabilities & incomingInterfaces.toSet()).isEmpty() ) { delete plugin; continue; } if (!plugin) { plugin = loader->instantiatePluginForDevice(pluginName, this); } foreach(const QString& interface, incomingInterfaces) { newPluginsByIncomingInterface.insert(interface, plugin); } foreach(const QString& interface, outgoingInterfaces) { newPluginsByOutgoingInterface.insert(interface, plugin); } newPluginMap[pluginName] = plugin; }
inline uint32_t fragLen() const { if (!isPaired()) { return 0; } auto leftmost1 = bam_pos(read1); auto leftmost2 = bam_pos(read2); // The length of the mapped read that is "rightmost" w.r.t. the forward strand. auto rightmostLen = (leftmost1 < leftmost2) ? bam_seq_len(read2) : bam_seq_len(read1); return std::abs(leftmost1 - leftmost2) + rightmostLen; //return std::abs(read1->core.isize) + std::abs(read1->core.l_qseq) + std::abs(read2->core.l_qseq); }
int main (int argc, char **argv) { LineStream ls; Texta tokens = NULL; char *line; int hasQual = 0; int hasSeqs = 0; int start=1; ls = ls_createFromFile ("-"); while (line = ls_nextLine (ls)) { // Put all the lines of the SAM header in comments if (line[0] == '@') { printf ("# %s\n", line); continue; } // Parse each SAM entry and store into array tokens = textFieldtokP (line, "\t"); if (arrayMax (tokens) < 11) { textDestroy( tokens ); ls_destroy (ls); die ("Invalid SAM entry: %s", line); } SamEntry *currSamE = NULL; SamEntry *mateSamE = NULL; AllocVar(currSamE ); int ret = generateSamEntry( tokens, currSamE, &hasSeqs, &hasQual ); textDestroy( tokens ); if ( ret==0 ) { if ( isPaired ( currSamE ) ) ls_nextLine( ls ); // discarding next entry too (the mate) destroySamEntry( currSamE ); freeMem( currSamE ); continue; } if ( isPaired( currSamE ) ) { int hasQual2, hasSeq2; AllocVar( mateSamE ); Texta secondEnd = NULL; secondEnd = textFieldtok (ls_nextLine( ls ) , "\t"); ret = generateSamEntry( secondEnd, mateSamE, &hasSeq2, &hasQual2 ); textDestroy( secondEnd ); if( ret == 0 ) { destroySamEntry( currSamE ); destroySamEntry( mateSamE ); freeMem( currSamE ); freeMem( mateSamE ); continue; } if (strcmp (currSamE->qname, mateSamE->qname) != 0) { die ("Please note that for paired-end data, sam2mrf requires the mate pairs to be on subsequent lines. You may want to sort the SAM file first.\nEx: sort -r file.sam | sam2mrf > file.mrf\n"); } } // Print MRF headers if( start ) { printf ("%s", MRF_COLUMN_NAME_BLOCKS); if (hasSeqs) printf("\t%s", MRF_COLUMN_NAME_SEQUENCE); if (hasQual) printf("\t%s", MRF_COLUMN_NAME_QUALITY_SCORES); printf ("\t%s\n", MRF_COLUMN_NAME_QUERY_ID); start=0; } // Print AlignmentBlocks printMrfAlignBlocks (currSamE, R_FIRST); if( isPaired ( currSamE ) ) { printf ("|"); printMrfAlignBlocks (mateSamE, R_SECOND); } seq_init(); // Print Sequence if (hasSeqs) { if (!currSamE->seq) die ("Entry missing sequence column\n"); if( currSamE->flags & S_QUERY_STRAND ) seq_reverseComplement( currSamE->seq, strlen(currSamE->seq)); printf ("\t%s", currSamE->seq); if (mateSamE) { if (!mateSamE->seq) die ("Entry missing sequence column\n"); if( mateSamE->flags & S_MATE_STRAND ) seq_reverseComplement( mateSamE->seq, strlen(mateSamE->seq)); printf ("|%s", mateSamE->seq); } } // Print quality scores if (hasQual) { if (!currSamE->qual) die ("Entry missing quality scores column\n"); printf ("\t%s", currSamE->qual); if (mateSamE) { if (!mateSamE->qual) die ("Entry missing quality scores column\n"); printf ("|%s", mateSamE->qual); } } // Print queryID if (mateSamE) { printf ("\t%s|%s", currSamE->qname,"2"); // No need to print out both IDs, but need the pipe symbol for consistency } else { printf ("\t%s", currSamE->qname); } printf("\n"); destroySamEntry( currSamE ); freeMem( currSamE ); if( isPaired( currSamE ) ) { destroySamEntry ( mateSamE ); freeMem( mateSamE ); } } // clean up ls_destroy (ls); return EXIT_SUCCESS; }
void OctreeGrid::testSubdivideRandom(bool graded, bool paired) { bool bfs = false; std::vector<std::pair<int, int> > leaves, next; // Init: start with root cells leaves.reserve(m_Cells.size()); for (int i = 0; i < (int) m_Cells.size(); ++i) { leaves.emplace_back(0, i); } std::default_random_engine gen; std::uniform_real_distribution<double> distr(0, 1); assertIsValid(); int counter = 0; int nextCheck = (int) leaves.size(); while (!leaves.empty()) { std::uniform_int_distribution<int> take(0, (int) leaves.size() - 1); int i = take(gen); int depth = leaves[i].first; int id = leaves[i].second; std::swap(leaves[i], leaves.back()); leaves.pop_back(); if (depth < m_MaxDepth) { if (distr(gen) > 0.2 && cellIsLeaf(id)) { int newId = (int) m_Cells.size(); splitCell(id, graded, paired); for (int k = 0; k < 8; ++k) { if (bfs) { next.emplace_back(depth + 1, newId++); } else { leaves.emplace_back(depth + 1, newId++); } } } } ++counter; if (!bfs && counter == nextCheck) { assertIsValid(); nextCheck = (int) leaves.size(); counter = 0; } if (leaves.empty()) { assertIsValid(); std::swap(leaves, next); } } assertIsValid(); //std::shuffle(m_Cells.begin(), m_Cells.end(), std::default_random_engine()); // logger_debug("Octree", "Graded %s", is2to1Graded()); // logger_debug("Octree", "Build ok"); std::cout << "Graded: " << is2to1Graded() << std::endl; std::cout << "Paired: " << isPaired() << std::endl; // logger_debug("Octree", "Num nodes: %s", m_Nodes.size()); // logger_debug("Octree", "Num cells: %s", m_Cells.size()); if (graded) { oct_assert(is2to1Graded()); } if (paired) { oct_assert(isPaired()); } }
inline bool isLeft() const { return isPaired() ? false : (isLeftOrphan() ? true : false); }