Skip to content

Commit

Permalink
improve output
Browse files Browse the repository at this point in the history
  • Loading branch information
“chhylp123” committed Jun 29, 2019
1 parent d0fb1ea commit e8092b5
Show file tree
Hide file tree
Showing 11 changed files with 1,010 additions and 904 deletions.
69 changes: 38 additions & 31 deletions Bitmapper_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ int main(int argc, char *argv[])
double loadingTime;
double mappingTime;
char outputFileName[NAME_LENGTH];
char bam_outputFileName[NAME_LENGTH];



Expand All @@ -69,18 +68,17 @@ int main(int argc, char *argv[])
return 1;
}

if(Mapped_File)
{
sprintf(outputFileName, "%s%s",Mapped_FilePath , Mapped_File);
}
else
{
outputFileName[0] = '\0';
}


sprintf(outputFileName, "%s%s",Mapped_FilePath , Mapped_File);
sprintf(bam_outputFileName, "%s.tmp", outputFileName);



if (output_methy == 0)
{
Output_gene(outputFileName);
}




if (!is_pairedEnd)
{
Expand All @@ -105,14 +103,16 @@ int main(int argc, char *argv[])

if (output_methy == 0)
{
//这个Prepare_alignment()就是将这个文件里的变量各种配置到新文件中
OutPutSAM_Nounheader(chhy_ih_refGenName, refChromeCont, argc, argv);


if (bam_output == 1)
if (bam_output == 0)
{
init_bam_file_from_sam(outputFileName, bam_outputFileName);
Output_gene(outputFileName);
OutPutSAM_Nounheader(chhy_ih_refGenName, refChromeCont, argc, argv);
}
else
{
init_bam_header(outputFileName, chhy_ih_refGenName, refChromeCont, argc, argv);
}

}


Expand Down Expand Up @@ -200,19 +200,20 @@ int main(int argc, char *argv[])
fprintf(stderr, "Start alignment in sensitive mode.\n");
}


///fprintf(stderr, "is_local: %d\n", is_local);


if (output_methy == 0)
{

OutPutSAM_Nounheader(chhy_ih_refGenName, refChromeCont, argc, argv);

if (bam_output == 1)
if (bam_output == 0)
{
init_bam_file_from_sam(outputFileName, bam_outputFileName);
Output_gene(outputFileName);
OutPutSAM_Nounheader(chhy_ih_refGenName, refChromeCont, argc, argv);
}
else
{
init_bam_header(outputFileName, chhy_ih_refGenName, refChromeCont, argc, argv);
}

}


Expand All @@ -224,7 +225,7 @@ int main(int argc, char *argv[])
if(THREAD_COUNT==1)
{

Map_Pair_Seq(0);
Map_Pair_Seq(0);
}
else
{
Expand All @@ -247,9 +248,7 @@ int main(int argc, char *argv[])

if (bam_output == 1)
{
///close_bam_file();
close_bam_file_rename(bam_outputFileName, outputFileName);

close_bam_file();
}

///这个一打开速度就奇慢,不知道为什么
Expand Down Expand Up @@ -284,8 +283,16 @@ int main(int argc, char *argv[])
{
char mapstatsFileName[NAME_LENGTH];

sprintf(mapstatsFileName, "%s.mapstats", outputFileName);

if (outputFileName[0] == '\0')
{
sprintf(mapstatsFileName, "stdout.mapstats");
}
else
{
sprintf(mapstatsFileName, "%s.mapstats", outputFileName);
}


FILE* mapstats_fp = fopen(mapstatsFileName, "w");

if (mapstats_fp != NULL)
Expand Down
22 changes: 14 additions & 8 deletions Process_CommandLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
int is_index = 0;
int is_search = 0;
int is_methy = 0;
int is_pairedEnd;
int is_pairedEnd = 0;
int cropSize = 0;
int minDistance_pair=0;
int maxDistance_pair=500;
int over_all_seed_length = 30;
unsigned int THREAD_COUNT = 1;
char *Read_File1;
char *Read_File2;
char *Mapped_File = "output";
///char *Mapped_File = NULL;
///char *Mapped_File = "output";
char *Mapped_File = NULL;
char *Mapped_FilePath = "";
char *folder_path = NULL;
char *bmm_folder_path = NULL;
Expand Down Expand Up @@ -272,19 +272,25 @@ int CommandLine_process (int argc, char *argv[])
}


if (!is_pairedEnd && Read_File2 != NULL)

if (Read_File1 != NULL && Read_File2 != NULL)
{
is_pairedEnd = 1;
}

if (!is_pairedEnd && Read_File2 != NULL)
{
fprintf(stderr, "Please not indicate the read2 files for single-end mode!\n");
return 0;
}

if (is_pairedEnd && (minDistance_pair <0 || maxDistance_pair < 0 || minDistance_pair > maxDistance_pair))
if (is_pairedEnd && (minDistance_pair <0 || maxDistance_pair < 0 || minDistance_pair > maxDistance_pair))
{
fprintf(stderr, "Please set a valid range for paired-end mode.\n");
return 0;
}

if (is_pairedEnd && Read_File1 == NULL)
if (is_pairedEnd && Read_File1 == NULL)
{
fprintf(stderr, "Please indicate the read1 file for single-end mode.\n");
return 0;
Expand Down Expand Up @@ -414,11 +420,11 @@ void Print_H()
fprintf(stderr," --search [file/folder]\tSearch in the specified genome. If the indexes of this genome are built without \"--index_folder\", \n\t\t\tplease provide the path to the fasta file of genome (index files should be in the same folder). \n\t\t\tOtherwise please provide the path to the index folder (set by \"--index_folder\" during indexing).\n");
fprintf(stderr," --fast \t\tSet bitmapperBS in fast mode (default). This option is only available in paired-end mode.\n");
fprintf(stderr," --sensitive \t\tSet bitmapperBS in sensitive mode. This option is only available in paired-end mode.\n");
fprintf(stderr," --pe \t\t\tSearch will be done in paired-end mode.\n");
//fprintf(stderr," --pe \t\t\tSearch will be done in paired-end mode.\n");
fprintf(stderr," --seq [file]\t\tInput sequences in fastq/fastq.gz format [file]. This option is used \n\t\t\tfor single-end reads.\n");
fprintf(stderr," --seq1 [file]\t\tInput sequences in fastq/fastq.gz format [file] (First file). \n\t\t\tUse this option to indicate the first file of \n\t\t\tpaired-end reads. \n");
fprintf(stderr," --seq2 [file]\t\tInput sequences in fastq/fastq.gz format [file] (Second file). \n\t\t\tUse this option to indicate the second file of \n\t\t\tpaired-end reads. \n");
fprintf(stderr," -o [file]\t\tOutput of the mapped sequences in SAM or BAM format. The default is \"output\" in SAM format.\n");
fprintf(stderr," -o [file]\t\tOutput of the mapped sequences in SAM or BAM format. The default is \"stdout\" (standard output) in SAM format.\n");
fprintf(stderr, " --sam \t\t\tOutput mapping results in SAM format (default).\n");
fprintf(stderr, " --bam \t\t\tOutput mapping results in BAM format.\n");
fprintf(stderr, " --methy_out \t\tOutput the intermediate methylation result files, instead of SAM or BAM files.\n");
Expand Down
107 changes: 45 additions & 62 deletions Process_Reads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,21 +188,6 @@ int inputReads_paired_directly(
//****************************读第一个read*************************************

/*************************处理第一个read********************************/
///处理read name
read1_length = strlen(seqList1->name);
///去回车
seqList1->name[read1_length - 1] = '\0';
for (j = 0; j < read1_length; j++)
{
if (seqList1->name[j] == ' ' || seqList1->name[j] == '/')
{
seqList1->name[j] = '\0';
break;
}
}



///处理read seq
read1_length = strlen(seqList1->seq);
///去回车
Expand Down Expand Up @@ -268,21 +253,6 @@ int inputReads_paired_directly(


/*************************处理第二个read********************************/
///处理read name
read2_length = strlen(seqList2->name);
///去回车
seqList2->name[read2_length - 1] = '\0';
for (j = 0; j < read2_length; j++)
{
if (seqList2->name[j] == ' ' || seqList2->name[j] == '/')
{
seqList2->name[j] = '\0';
break;
}
}



///处理read seq
read2_length = strlen(seqList2->rseq);
///去回车
Expand Down Expand Up @@ -311,6 +281,30 @@ int inputReads_paired_directly(



///处理read name
read1_length = strlen(seqList1->name);
///去回车
seqList1->name[read1_length - 1] = '\0';

///处理read name
read2_length = strlen(seqList2->name);
///去回车
seqList2->name[read2_length - 1] = '\0';



for (j = 0; j < read1_length && j < read2_length; j++)
{
if (seqList1->name[j] != seqList2->name[j]||
seqList1->name[j] == ' ' ||
seqList1->name[j] == '/'
)
{
seqList1->name[j] = '\0';
seqList2->name[j] = '\0';
break;
}
}

return 1;

Expand All @@ -331,21 +325,6 @@ inline int post_process_paired_reads(Read_buffer_pe_sub_block* curr_sub_block)
for (i = 0; i < curr_sub_block->sub_block_read_number; i++)
{
/*************************处理第一个read********************************/
///处理read name
seq_length1 = strlen(curr_sub_block->read1[i].name);
///去回车
curr_sub_block->read1[i].name[seq_length1 - 1] = '\0';
for (j = 0; j < seq_length1; j++)
{
if (curr_sub_block->read1[i].name[j] == ' ' || curr_sub_block->read1[i].name[j] == '/')
{
curr_sub_block->read1[i].name[j] = '\0';
break;
}
}



///处理read seq
seq_length1 = strlen(curr_sub_block->read1[i].seq);
///去回车
Expand Down Expand Up @@ -376,21 +355,6 @@ inline int post_process_paired_reads(Read_buffer_pe_sub_block* curr_sub_block)


/*************************处理第二个read********************************/
///处理read name
seq_length2 = strlen(curr_sub_block->read2[i].name);
///去回车
curr_sub_block->read2[i].name[seq_length2 - 1] = '\0';
for (j = 0; j < seq_length2; j++)
{
if (curr_sub_block->read2[i].name[j] == ' ' || curr_sub_block->read2[i].name[j] == '/')
{
curr_sub_block->read2[i].name[j] = '\0';
break;
}
}



///处理read seq
seq_length2 = strlen(curr_sub_block->read2[i].rseq);
///去回车
Expand All @@ -417,9 +381,28 @@ inline int post_process_paired_reads(Read_buffer_pe_sub_block* curr_sub_block)

/*************************处理第二个read********************************/

///处理read name
seq_length1 = strlen(curr_sub_block->read1[i].name);
///去回车
curr_sub_block->read1[i].name[seq_length1 - 1] = '\0';
///处理read name
seq_length2 = strlen(curr_sub_block->read2[i].name);
///去回车
curr_sub_block->read2[i].name[seq_length2 - 1] = '\0';



for (j = 0; j < seq_length1; j++)
{
if (
curr_sub_block->read1[i].name[j] != curr_sub_block->read2[i].name[j]||
curr_sub_block->read1[i].name[j] == ' ' ||
curr_sub_block->read1[i].name[j] == '/'
)
{
curr_sub_block->read1[i].name[j] = '\0';
curr_sub_block->read2[i].name[j] = '\0';
break;
}
}

}
}
Expand Down
5 changes: 2 additions & 3 deletions Process_sam_out.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,7 @@ void OutPutSAM_Nounheader(_rg_name_l *_ih_refGenName, int refChromeCont, int ar
int i = 0;
for (i = 0; i<refChromeCont; i++)
{
fprintf(_out_fp, "@SQ\tSN:%s\tLN:%u\n", _ih_refGenName[i]._rg_chrome_name, _ih_refGenName[i]._rg_chrome_length);

fprintf(_out_fp, "@SQ\tSN:%s\tLN:%llu\n", _ih_refGenName[i]._rg_chrome_name, _ih_refGenName[i]._rg_chrome_length);
}

fprintf(_out_fp, "@PG\tID:BitMapperBS\tVN:%s\tCL:", versionN);
Expand Down Expand Up @@ -1221,7 +1220,7 @@ void multi_outputQ(SAM map, int thread_id)



int Output_gene ( char *fileName)
int Output_gene (char *fileName)
{

if (fileName[0] == '\0')
Expand Down
Loading

0 comments on commit e8092b5

Please sign in to comment.