454ITS数据按barcode和primer分类程序v1.0
不知道有什么好办法可以让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的更多相关文章
- 痞子衡嵌入式:kFlashFile v1.0 - 一个基于Flash的掉电数据存取方案
大家好,我是痞子衡,是正经搞技术的痞子.今天给大家带来的是痞子衡的个人小项目 - kFlashFile. 痞子衡最近在参与一个基于 i.MXRT1170 的项目,项目有个需求,需要在 Flash 里实 ...
- ASP.NET Boilerplate终于发布v1.0了
(此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:ABP经过2年多的开发,终于发布第一个主要版本了,谨此提醒ABP的使用者. ASP.N ...
- 【JS】heatmap.js v1.0 到 v2.0,详细总结一下:)
前段时间,项目要开发热力图插件,研究了heatmap.js,打算好好总结一下. 本文主要有以下几部分内容: 部分源码理解 如何迁移到v2.0 v2.0官方文档译文 关于heatmap.js介绍,请看这 ...
- 基于Qt5.5.0的sql数据库、SDK_tts文本语音朗读的CET四六级单词背诵系统软件的编写V1.0
作者:小波 QQ:463431476 请关注我的博客园:http://www.cnblogs.com/xiaobo-Linux/ 我的第二款软件:CET四六级单词背诵软件.基于QT5.5.0.sql数 ...
- The P4 Language Specification v1.0.2 Header and Fields
前言 本文参考P4.org网站给出的<The P4 Language Specification v1.0.2>的第二部分首部及字段,仅供学习:). 欢迎交流! Header and Fi ...
- 高性能以太网芯片W5500 数据手册 V1.0(二)
继续给大家介绍W5500 数据手册. 2.4 固定数据长度模式(FDM) 在外设主机不能控制 SCSn 时,可以使用固定数据长度模式. 此时,SCSn 必须连接到低电平(保持接地).与此同 ...
- [Android应用]《花界》V1.0 正式版隆重发布!
http://www.cnblogs.com/qianxudetianxia/archive/2012/04/05/2433669.html 1. 软件说明(1). 花界是一款看花软件:“看花,议花, ...
- 【转】寻找最好的笔记软件:三强篇(EverNote、Mybase、Surfulater) (v1.0) (
原文网址:http://blog.sina.com.cn/s/blog_46dac66f01000b57.html 寻找最好的笔记软件:三强篇(EverNote.Mybase.Surfulater) ...
- 《Ruby语言入门教程v1.0》学习笔记-01
<Ruby语言入门教程v1.0> 编著:张开川 邮箱:kaichuan_zhang@126.com 想要学习ruby是因为公司的自动化测试使用到了ruby语言,但是公司关于ruby只给了一 ...
随机推荐
- Nginx动静分离实现
Nginx动静分离实现: Nginx是一种轻量级,高性能,多进程的Web服务器,非常适合作为静态资源的服务器使用,而动态的访问操作可以使用稳定的Apache.Tomcat及IIS等来实现,这里就以Ng ...
- Java数据结构和算法(七)——链表
前面博客我们在讲解数组中,知道数组作为数据存储结构有一定的缺陷.在无序数组中,搜索性能差,在有序数组中,插入效率又很低,而且这两种数组的删除效率都很低,并且数组在创建后,其大小是固定了,设置的过大会造 ...
- Oracle table names are case sensitive (normally all uppercase)
oracle_fdw error desc: postgres=# select * from test; ERROR: Oracle table "sangli"." ...
- Linux上安装 MongoDB ZK MEMCACHE PHP扩展
安装mongo扩展: 下载地址:https://github.com/mongodb/mongo-php-driver,下载该源码包 /usr/local/php/bin/pecl install m ...
- 大白话Vue源码系列(01):万事开头难
阅读目录 Vue 的源码目录结构 预备知识 先捡软的捏 Angular 是 Google 亲儿子,React 是 Facebook 小正太,那咱为啥偏偏选择了 Vue 下手,一句话,Vue 是咱见过的 ...
- 基于Java使用Snmp4j进行监控与采集(snmptrap、snmpwalk、snmpget)
之前有在弄监控服务器这块的工作,今天来整体总结下.因为有些服务器(路由器.交换机等都是基于snmp协议的)必须使用snmp协议去监控采集和接收信息,所以必须去了解snmp相关内容,以及如何在基于jav ...
- python3 爬虫---爬取豆瓣电影TOP250
第一次爬取的网站就是豆瓣电影 Top 250,网址是:https://movie.douban.com/top250?start=0&filter= 分析网址'?'符号后的参数,第一个参数's ...
- recover all files with git
leon@DGLIRUAN2 /F/linux/android/leon/workspace/AngoWidget (master) $ git log commit 2f847e3a858ecb2f ...
- C语言之基本算法37—数组最大值及其位置
//数组运算 /* ================================================================== 题目:查找数组的最大元素,并输出其位置和值! ...
- Python的招牌菜xmlrpc
一.简单介绍 为了解决在系统的80port提供RPC的服务.而又不影响正在运行的WEB服务.人们想出了用HTTP协议传输RPC包的办法.对于差点儿是专门用于传输文本的HTTP协议.要在其上传输RPC封 ...