-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
zUMIs2.5 improve BC error correction
- Loading branch information
1 parent
6b55fc8
commit aae3813
Showing
11 changed files
with
184 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
|
||
if(@ARGV != 4) | ||
{ | ||
"\n##################################################################################### | ||
Usage: perl $0 <inbam> <outbam> <BCbinmap> <samtools-executable> \n | ||
Please drop your suggestions and clarifications to <christoph.ziegenhain\@ki.se>\n | ||
######################################################################################\n\n"; | ||
exit; | ||
} | ||
BEGIN{ | ||
$inbam=$ARGV[0]; | ||
$outbam=$ARGV[1]; | ||
$binmap=$ARGV[2]; | ||
$samtoolsexc=$ARGV[3]; | ||
} | ||
|
||
open(INBAM, "$samtoolsexc view $inbam | sed 's/BC:Z://' | " ) || die "Couldn't open file $inbam. Check permissions!\n Check if it is a bam file and it exists\n\n"; | ||
open(BCBAM,"| $samtoolsexc view -b -o $outbam -"); | ||
|
||
|
||
my %bcmap; | ||
open(DATA, "cat $binmap | sed 's/,/\t/g' | cut -f1,3 | grep -v 'falseBC' | ") || die "Can't open $binmap ! \n"; | ||
while (<DATA>) { | ||
my ($raw, @fixedBC) = split(/\t/); | ||
$bcmap{$raw} = \@fixedBC; | ||
} | ||
close DATA; | ||
|
||
|
||
while (<INBAM>) { | ||
$read=$_; | ||
chomp($read); | ||
@read = split(/\t/,$read); | ||
$thisBC = $read[11]; | ||
|
||
if (defined($bcmap{$thisBC})) { | ||
#print "BC is in hash\n"; | ||
$correctBC = $bcmap{$thisBC}[0]; | ||
chomp($correctBC); | ||
} | ||
else { | ||
#print "BC is not in hash\n"; | ||
$correctBC = $thisBC; | ||
} | ||
|
||
print BCBAM $read[0],"\t",$read[1],"\t",$read[2],"\t",$read[3],"\t",$read[4],"\t",$read[5],"\t",$read[6],"\t",$read[7],"\t",$read[8],"\t", | ||
$read[9],"\t",$read[10],"\t","BX:Z:",$thisBC,"\t","BC:Z:",$correctBC,"\t",$read[12],"\n"; | ||
|
||
} | ||
close INBAM; | ||
close BCBAM; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env Rscript | ||
library(methods) | ||
library(data.table) | ||
library(yaml) | ||
library(ggplot2) | ||
|
||
########################## | ||
myYaml <- commandArgs(trailingOnly = T) | ||
|
||
opt <-read_yaml(myYaml) | ||
setwd(opt$out_dir) | ||
source(paste0(opt$zUMIs_directory,"/barcodeIDFUN.R")) | ||
options(datatable.fread.input.cmd.message=FALSE) | ||
data.table::setDTthreads(threads=opt$num_threads) | ||
|
||
####################################################################### | ||
####################################################################### | ||
##### Barcode handling & chunking | ||
|
||
#read file with barcodecounts | ||
# bc is the vector of barcodes to keep | ||
bccount<-cellBC(bcfile = opt$barcodes$barcode_file, | ||
bcnum = opt$barcodes$barcode_num, | ||
bcauto = opt$barcodes$automatic, | ||
bccount_file= paste0(opt$out_dir,"/", opt$project, ".BCstats.txt"), | ||
outfilename = paste0(opt$out_dir,"/zUMIs_output/stats/",opt$project,".detected_cells.pdf")) | ||
|
||
fwrite(bccount,file=paste0(opt$out_dir,"/zUMIs_output/",opt$project,"kept_barcodes.txt")) | ||
|
||
#check if binning of adjacent barcodes should be run | ||
if(opt$barcodes$BarcodeBinning > 0){ | ||
binmap <- BCbin(bccount_file = paste0(opt$out_dir,"/", opt$project, ".BCstats.txt"), | ||
bc_detected = bccount) | ||
fwrite(binmap,file=paste0(opt$out_dir,"/zUMIs_output/",opt$project,".BCbinning.txt")) | ||
#update the number reads in BCcount table | ||
binmap_additional <- binmap[, .(addtl = sum(n)), by = trueBC] | ||
bccount[match(binmap_additional$trueBC,XC),n := n + binmap_additional$addtl] | ||
fwrite(bccount,file=paste0(opt$out_dir,"/zUMIs_output/",opt$project,"kept_barcodes_binned.txt")) | ||
} | ||
|
||
############################################################## | ||
q() |
Oops, something went wrong.