不知道有什么好办法可以让primer允许漏配,现在仅仅是允许错配,还是有一些没有配上,454数据有些primer漏配了一些,下一步解决这个问题

 #include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <getopt.h>
using namespace std; int max_mis = ;
int N = ;
string primer = "";
string* barcode = NULL;
string* barcodeName = NULL;
void usage ()
{
cout << "\nUsage: splitByBarcode [options] <read.fasta> <barcode.txt> <output prefix>\n"
<< " -m <int> allow the max mis num, default " << max_mis << "\n"
<< " -p <string> primer, required "<<endl
<< " -n <int> barcode num, required"<<endl;
exit();
}
struct COMPARE{
int ifCompared;
int posStart;
int posEnd;
};
COMPARE compare(string reads, string barcode, int maxmis,int b,int e);
int main(int argc, char *argv[])
{
if (argc < )
{
usage();
}
int c;
while ((c=getopt(argc,argv,"m:n:p:")) != -)
{
switch (c)
{
case 'm' : max_mis = atoi(optarg);break;
case 'n' : N = atoi(optarg); break;
case 'p' : primer = optarg;break;
default : cout<<"error:"<<(char)c<<endl;usage();
}
}
if(N<=){
cerr<<"please input the required barcode num\n";
exit();
}
if(primer == ""){
cerr<<"please input the required primer\n";
exit();
}
string seq_file = argv[optind++];
string barcode_file = argv[optind++];
string outPrefix = argv[optind++];
string out_file = outPrefix + ".list";
barcode = new string[N];
barcodeName = new string[N]; for(int i=;i<N;i++){
barcodeName[i] = "";
barcode[i] = "";
} ifstream reads;
reads.open(seq_file.c_str());
if(!reads){
cerr<<"fail to open input file"<<seq_file<<endl;
}
ifstream barcode_in;
barcode_in.open(barcode_file.c_str());
if(!barcode_in){
cerr<<"fail to open barcode file" <<barcode_file<<endl;
} string text;
int k=;
while( getline( barcode_in, text, '\n') )
{
int startPos = , endPos;
endPos = text.find("\t");
barcodeName[k] = text.substr(startPos, endPos-startPos+);
startPos = endPos + ;
endPos = text.find("\t",startPos);
barcode[k] = text.substr(startPos, endPos-startPos+);
//cout << barcodeName[k] <<"\t"<< barcodeForward[k] <<"\t"<< barcodeReverse[k] << endl;
k++;
} ofstream splitlist;
splitlist.open(out_file.c_str());
if(!splitlist){
cerr<<"fail to creat output file" << out_file <<endl;
}
int line_num = ;
splitlist<<"barcodeName\tid\tid_line\n";
while( getline( reads, text, '\n') )
{
string seq = "", id = "";
id = text;
getline( reads, text, '\n');
seq = text; COMPARE p1 ,p2;
p1.ifCompared = p2.ifCompared = ;
for(int k=;k<N;k++){
p1 = compare(seq,primer,max_mis,,seq.length()-primer.length()+);
if( p1.ifCompared )
{
p2 = compare(seq,barcode[k],,,p1.posStart);
if ( p2.ifCompared ){
//cout<<seq1<<"\t"<<barcodeForward[k]<<"\t"<<seq2<<"\t"<<barcodeReverse[k]<<endl;
splitlist<<barcodeName[k]<<"\t"<<id<<"\t"<<line_num<<endl;
break;
}
}
}
line_num = line_num + ;
}
delete[] barcode;
delete[] barcodeName;
splitlist.close();
barcode_in.close();
reads.close();
}
COMPARE compare(string reads, string barcode, int maxmis, int b, int e)
{
COMPARE p;
//cout<<b<<"\t"<<e<<endl;
// cout<<barcode<<"\t"<<barcode.length()<<endl;
for(int i=b;i<e;i++)
{
int mismatch = ;
int pos = ;
while(mismatch <= maxmis ){
if(reads[i+pos] != barcode[pos]) mismatch++;
pos++;
if(pos == barcode.length()){
p.posStart = i;
p.posEnd = i+pos;
// cout<<p.posStart<<"\t"<<p.posEnd<<endl;
p.ifCompared = ;
return p;
}
}
}
p.ifCompared = ;
return p;
}

454ITS数据按barcode和primer分类程序v1.0的更多相关文章

  1. 痞子衡嵌入式:kFlashFile v1.0 - 一个基于Flash的掉电数据存取方案

    大家好,我是痞子衡,是正经搞技术的痞子.今天给大家带来的是痞子衡的个人小项目 - kFlashFile. 痞子衡最近在参与一个基于 i.MXRT1170 的项目,项目有个需求,需要在 Flash 里实 ...

  2. ASP.NET Boilerplate终于发布v1.0了

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:ABP经过2年多的开发,终于发布第一个主要版本了,谨此提醒ABP的使用者. ASP.N ...

  3. 【JS】heatmap.js v1.0 到 v2.0,详细总结一下:)

    前段时间,项目要开发热力图插件,研究了heatmap.js,打算好好总结一下. 本文主要有以下几部分内容: 部分源码理解 如何迁移到v2.0 v2.0官方文档译文 关于heatmap.js介绍,请看这 ...

  4. 基于Qt5.5.0的sql数据库、SDK_tts文本语音朗读的CET四六级单词背诵系统软件的编写V1.0

    作者:小波 QQ:463431476 请关注我的博客园:http://www.cnblogs.com/xiaobo-Linux/ 我的第二款软件:CET四六级单词背诵软件.基于QT5.5.0.sql数 ...

  5. The P4 Language Specification v1.0.2 Header and Fields

    前言 本文参考P4.org网站给出的<The P4 Language Specification v1.0.2>的第二部分首部及字段,仅供学习:). 欢迎交流! Header and Fi ...

  6. 高性能以太网芯片W5500 数据手册 V1.0(二)

    继续给大家介绍W5500 数据手册. 2.4       固定数据长度模式(FDM) 在外设主机不能控制 SCSn 时,可以使用固定数据长度模式. 此时,SCSn 必须连接到低电平(保持接地).与此同 ...

  7. [Android应用]《花界》V1.0 正式版隆重发布!

    http://www.cnblogs.com/qianxudetianxia/archive/2012/04/05/2433669.html 1. 软件说明(1). 花界是一款看花软件:“看花,议花, ...

  8. 【转】寻找最好的笔记软件:三强篇(EverNote、Mybase、Surfulater) (v1.0) (

    原文网址:http://blog.sina.com.cn/s/blog_46dac66f01000b57.html 寻找最好的笔记软件:三强篇(EverNote.Mybase.Surfulater) ...

  9. 《Ruby语言入门教程v1.0》学习笔记-01

    <Ruby语言入门教程v1.0> 编著:张开川 邮箱:kaichuan_zhang@126.com 想要学习ruby是因为公司的自动化测试使用到了ruby语言,但是公司关于ruby只给了一 ...

随机推荐

  1. CentOS安装Nginx 报错“configure: error: the HTTP rewrite module requires the PCRE library”解决办法

    错误提示: ./configure: error: the HTTP rewrite module requires the PCRE library.      yum install gcc gc ...

  2. 构建Nginx均衡LAMP高性能服务器

    LNAMP(Linux+Nginx+Apache+Mysql+PHP)架构受到很多IT企业的青睐,取代了原来认为很好的LNMP(Linux+Nginx+Mysql+PHP)架构,那我们说LNAMP到底 ...

  3. flask-login使用笔记

    看外国文献的中文翻译  翻译的程度有的让人会疯,翻译最好的状态是异译 直译会显的很生硬 看起来确实难过:所以在看的时候,建议都看外国文献吧,或者自己用谷歌翻译,感觉比一些翻译的博客准多了: 在使用fl ...

  4. Android HandlerThread 源码分析

    HandlerThread 简介: 我们知道Thread线程是一次性消费品,当Thread线程执行完一个耗时的任务之后,线程就会被自动销毁了.如果此时我又有一 个耗时任务需要执行,我们不得不重新创建线 ...

  5. 逐步搭建Lamp环境之rpm软件包管理

    Linux中的rpm软件包管理类似于windows下的"xxx软件管家"."xxx电脑管家",其作用主要用于查询软件的安装情况.安装软件.卸载软件. 以下针对这 ...

  6. Python爬虫(十九)_动态HTML介绍

    JavaScript JavaScript是网络上最常用也是支持者对多的客户端脚本语言.它可以收集用户的跟踪数据,不需要重载页面直接提交表单,在页面嵌入多媒体文件,甚至运行网页游戏. 我们可以在网页源 ...

  7. 》》stroll--各种特效下拉菜单

    <!doctype html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  8. 2016年7月微软MVP申请開始了!

    2016年7月微软MVP申请開始了! CSDN与微软合作,长期为用户提供申请"微软最有价值专家"的平台.希望有兴趣.资历的朋友以及正在朝这个方向努力的朋友能够积极參与. 2016年 ...

  9. 谈谈调用腾讯云【OCR-通用印刷体识别】Api踩的坑

    一.写在前面 最近做项目需要用到识别图片中文字的功能,本来用的Tesseract这个写的,不过效果不是很理想. 随后上网搜了一下OCR接口,就准备使用腾讯云.百度的OCR接口试一下效果.不过这个腾讯云 ...

  10. Office Add-in 架构和入门

    作者:陈希章 发表于2017年7月12日 前言 从2月26日开始写这个Office 365开发概览系列文章-- https://aka.ms/office365devguide,到现在已经有17篇文章 ...