454ITS数据按barcode和primer分类程序v1.0

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

  1 #include <cstdio>
  2 #include <cstdlib>
  3 #include <string>
  4 #include <iostream>
  5 #include <fstream>
  6 #include <iomanip>
  7 #include <getopt.h>
  8 using namespace std;
  9
 10 int max_mis = 1;
 11 int N = 0;
 12 string primer = "";
 13 string* barcode = NULL;
 14 string* barcodeName = NULL;
 15 void usage ()
 16 {
 17         cout << "\nUsage: splitByBarcode [options] <read.fasta> <barcode.txt> <output prefix>\n"
 18         << "  -m <int>  allow the max mis num, default " << max_mis << "\n"
 19     << "  -p <string> primer, required    "<<endl
 20     << "  -n <int>  barcode num, required"<<endl;
 21         exit(1);
 22 }
 23 struct COMPARE{
 24     int ifCompared;
 25     int posStart;
 26     int posEnd;
 27 };
 28 COMPARE compare(string reads, string barcode, int maxmis,int b,int e);
 29 int main(int argc, char *argv[])
 30 {
 31     if (argc < 4)
 32     {
 33         usage();
 34     }
 35     int c;
 36     while ((c=getopt(argc,argv,"m:n:p:")) != -1)
 37     {
 38         switch (c)
 39         {
 40             case ‘m‘ : max_mis = atoi(optarg);break;
 41             case ‘n‘ : N = atoi(optarg); break;
 42             case ‘p‘ : primer = optarg;break;
 43             default  : cout<<"error:"<<(char)c<<endl;usage();
 44         }
 45     }
 46     if(N<=0){
 47         cerr<<"please input the required barcode num\n";
 48         exit(1);
 49     }
 50     if(primer == ""){
 51         cerr<<"please input the required primer\n";
 52         exit(1);
 53     }
 54     string seq_file = argv[optind++];
 55     string barcode_file = argv[optind++];
 56     string outPrefix = argv[optind++];
 57     string out_file = outPrefix + ".list";
 58     barcode = new string[N];
 59     barcodeName = new string[N];
 60
 61     for(int i=0;i<N;i++){
 62         barcodeName[i] = "";
 63         barcode[i] = "";
 64     }
 65
 66     ifstream reads;
 67     reads.open(seq_file.c_str());
 68     if(!reads){
 69         cerr<<"fail to open input file"<<seq_file<<endl;
 70     }
 71     ifstream barcode_in;
 72     barcode_in.open(barcode_file.c_str());
 73     if(!barcode_in){
 74         cerr<<"fail to open barcode file" <<barcode_file<<endl;
 75     }
 76
 77     string text;
 78     int k=0;
 79     while( getline( barcode_in, text, ‘\n‘) )
 80     {
 81         int startPos = 0, endPos;
 82         endPos = text.find("\t");
 83         barcodeName[k] = text.substr(startPos, endPos-startPos+1);
 84         startPos = endPos + 1;
 85         endPos = text.find("\t",startPos);
 86         barcode[k] = text.substr(startPos, endPos-startPos+1);
 87         //cout << barcodeName[k] <<"\t"<< barcodeForward[k] <<"\t"<< barcodeReverse[k] << endl;
 88         k++;
 89     }
 90
 91     ofstream splitlist;
 92     splitlist.open(out_file.c_str());
 93     if(!splitlist){
 94         cerr<<"fail to creat output file" << out_file <<endl;
 95     }
 96     int line_num = 1;
 97     splitlist<<"barcodeName\tid\tid_line\n";
 98     while( getline( reads, text, ‘\n‘) )
 99     {
100         string seq = "", id = "";
101         id = text;
102         getline( reads, text, ‘\n‘);
103         seq = text;
104
105         COMPARE p1 ,p2;
106         p1.ifCompared = p2.ifCompared = 0;
107         for(int k=0;k<N;k++){
108             p1 = compare(seq,primer,max_mis,0,seq.length()-primer.length()+1);
109             if( p1.ifCompared )
110             {
111                 p2 = compare(seq,barcode[k],0,0,p1.posStart);
112                 if ( p2.ifCompared ){
113                 //cout<<seq1<<"\t"<<barcodeForward[k]<<"\t"<<seq2<<"\t"<<barcodeReverse[k]<<endl;
114                     splitlist<<barcodeName[k]<<"\t"<<id<<"\t"<<line_num<<endl;
115                     break;
116                 }
117             }
118         }
119         line_num = line_num + 2;
120     }
121     delete[] barcode;
122     delete[] barcodeName;
123     splitlist.close();
124     barcode_in.close();
125     reads.close();
126 }
127 COMPARE compare(string reads, string barcode, int maxmis, int b, int e)
128 {
129     COMPARE p;
130     //cout<<b<<"\t"<<e<<endl;
131 //    cout<<barcode<<"\t"<<barcode.length()<<endl;
132     for(int i=b;i<e;i++)
133     {
134         int mismatch = 0;
135         int pos = 0;
136         while(mismatch <= maxmis ){
137             if(reads[i+pos] != barcode[pos]) mismatch++;
138             pos++;
139             if(pos == barcode.length()){
140                 p.posStart = i;
141                 p.posEnd = i+pos;
142             //    cout<<p.posStart<<"\t"<<p.posEnd<<endl;
143                 p.ifCompared = 1;
144                 return p;
145             }
146         }
147     }
148     p.ifCompared = 0;
149     return p;
150 }
时间: 2024-07-30 10:16:57

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

layUI之DataTable组件V1.0(父子表管理传值/数据表格与select&amp;laydate结合等)

目录 layUI之DataTable数据表格组件V1.0 概述 一.下载与引用 二.组件功能介绍 三.父表格渲染 四.子表弹出渲染 五.父表增/删/改/查 六.其他特色功能 七.最后说点啥 layUI之DataTable数据表格组件V1.0 概述 ? 公司项目中对于表格操作的要求较多,比如"父子表格关联进行数据传递"."表格中使用select组件"."表格中使用日期控件"."表格输入格式验证"."数据表格新增(删除)

主流区块链技术特点及Fabric V0.6&V1.0版本特点

声明:文章内容来源于网络. 一.主流区块链技术特点 二.Hyperledger的fabric V0.6总体架构: 对应的0.6版本的运行时架构: 0.6版本的架构特点是: 结构简单: 应用-成员管理-Peer的三角形关系,主要业务功能全部集中于Peer节点:    架构问题:由于peer节点承担了太多的功能,所以带来扩展性.可维护性.安全性.业务隔离等方面的诸多问题,所以0.6版本在推出后,并没有大规模被行业使用,只是在一些零星的案例中进行业务验证: 三.Hyperledger的fabric V

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

前段时间,项目要开发热力图插件,研究了heatmap.js,打算好好总结一下. 本文主要有以下几部分内容: 部分源码理解 如何迁移到v2.0 v2.0官方文档译文 关于heatmap.js介绍,请看这里: http://www.oschina.net/p/heatmap-js 目前,对于热力图的开发,百度.高德开发平台上使用的都是这款JS开源库.当然,现在还有我们公司:P 百度示例:http://developer.baidu.com/map/jsdemo.htm#c1_15 高德示例:http

效率飞速提高Four Dimension Technologies GeoTools v17.0 1CD+AutoHook.2017.v1.0.3.00 1CD

效率飞速提高Four Dimension Technologies GeoTools v17.0 1CD+AutoHook.2017.v1.0.3.00 1CD GeoTools v12.18 1CD     GeoTools写的是测绘.GIS用户心中最初但现在有这个程序它是有用的,只是任何AutoCAD用户相关的足够的命令.GeoTools现在是几乎所有的AutoCAD用户有用.它解决了很多常见的问题和地图生产的要求和编辑AutoCAD是地理数据的一个非常方便的工具捕获(GIS底图).处理.转

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

http://www.cnblogs.com/qianxudetianxia/archive/2012/04/05/2433669.html 1. 软件说明(1). 花界是一款看花软件:“看花,议花,说花,提高您的赏花素养!”. (2). 发布<花界>V1.0正式版,一是检验,综合,统一本博客技术分析,二是从理论到实践的转换. 2. 应用下载下载地址:点击谷歌市场:点击 3. 源码下载源码托管:传送门 4. 业务简介(1). 持续更新高清花朵的图片赏析:(2). 给花儿分门别类,教你区分不同的

业务数据库开发上线流程v1.0

XX业务数据库开发上线流程v1.0 草拟时间:2015.11.23制订时间:修订时间: 0x00 目的 本文定义了业务在开发上线发布过程中涉及的数据库相关流程,指引业务人员高效完成数据库上线工作,最终确保上线质量可控. 0x01 适用范围 人员:所有研发人员,运维人员数据库:业务所有MySQL 数据库 0x02 流程说明 流程内容包含:数据库申请-->功能开发---功能与性能测试-->提交审核-->运维审核--->上线变更---验证---上线结束 1. 数据库服务申请 流程负责人员

003-主流区块链技术特点及Hyperledger的fabric V1.0

一.最新的1.0运行时架构: 1.0 架构要点: 分拆Peer的功能,将Blockchain的数据维护和共识服务进行分离,共识服务从Peer节点中完全分离出来,独立为Orderer节点提供共识服务: 基于新的架构,实现多通道(channel)的结构,实现了更为灵活的业务适应性(业务隔离.安全性等方面) 支持更强的配置功能和策略管理功能,进一步增强系统的灵活性和适应性: 1.0版本架构目标: 1.chaincode信任的灵活性:支持多个ordering服务节点,增强共识的容错能力和对抗ordere

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

(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:ABP经过2年多的开发,终于发布第一个主要版本了,谨此提醒ABP的使用者. ASP.NET Boilerplate之前顺带介绍过两次.下面直接摘抄一点阳铭的介绍(http://www.cnblogs.com/mienreal/p/4528641.html): ABP是"ASP.NET Boilerplate Project (ASP.NET样板项目)"的简称. ASP.NE

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

原文网址:http://blog.sina.com.cn/s/blog_46dac66f01000b57.html 寻找最好的笔记软件:三强篇(EverNote.Mybase.Surfulater) v1.0 作者:SuperboyAC 编译:xbeta 本系列还有:海选篇.三强篇.梦想篇.结论.篇外 通过上一篇<寻找最好的笔记软件:海选篇>的综合分析,作者发现有3种软件具有较明显的优势,可谓“笔记软件三强”.它们是:EverNote.Mybase 和 Surfulater.此三者相同之间差异