-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from U-BDS/dev
Various Fixes: Updated documentation and reporting, isoquant downgrading, adding 5 prime support
- Loading branch information
Showing
27 changed files
with
2,483 additions
and
81 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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,90 @@ | ||
# This file stores the parameter used in this repo | ||
|
||
import os | ||
import numpy as np | ||
|
||
## Output prefix | ||
DEFAULT_PREFIX = '' | ||
|
||
#################################################### | ||
############# polyT and adaptor finding############# | ||
#################################################### | ||
## adaptor finding | ||
ADPT_SEQ='CTTCCGATCT' #searched adaptor sequence | ||
ADPT_WIN=200 #search adaptor in subsequence from both end of the reads with this size | ||
ADPT_MAC_MATCH_ED=2 #minimum proportion of match required when searching | ||
|
||
## format suffix | ||
SEQ_SUFFIX_WIN=200 | ||
SEQ_SUFFIX_MIN_MATCH_PROP=1 | ||
SEQ_SUFFIX_AFT_ADPT=(20,50) | ||
|
||
## poly T searching | ||
PLY_T_LEN=4 #length of searched poly T | ||
|
||
## TSO searching | ||
TSO_SEQ='TTTCTTATATGGG' | ||
|
||
#################################################### | ||
####### DEFAULT in getting putative bc ###### | ||
#################################################### | ||
# input | ||
DEFAULT_GRB_MIN_SCORE=15 | ||
DEFAULT_GRB_KIT='v3' | ||
DEFAULT_UMI_SIZE= 12 if DEFAULT_GRB_KIT=='v3' else 10 | ||
|
||
# The 10X barcode whitelists has been packed in the package | ||
DEFAULT_GRB_WHITELIST_V3=os.path.join(os.path.dirname(__file__), '10X_bc', '3M-february-2018.zip') | ||
DEFAULT_GRB_WHITELIST_V2=os.path.join(os.path.dirname(__file__), '10X_bc', '737K-august-2016.txt') | ||
|
||
#output | ||
DEFAULT_GRB_OUT_RAW_BC='putative_bc.csv' | ||
DEFAULT_GRB_OUT_WHITELIST = 'whitelist.csv' | ||
DEFAULT_GRB_OUT_FASTQ = "matched_reads.fastq.gz" | ||
DEFAULT_GRB_FLANKING_SIZE = 5 | ||
|
||
#################################################### | ||
##### DEFAULT in generating whitelist ###### | ||
#################################################### | ||
# quantile based threshold | ||
def default_count_threshold_calculation(count_array, exp_cells): | ||
top_count = np.sort(count_array)[::-1][:exp_cells] | ||
return np.quantile(top_count, 0.95)/20 | ||
|
||
def high_sensitivity_threshold_calculation(count_array, exp_cells): | ||
top_count = np.sort(count_array)[::-1][:exp_cells] | ||
return np.quantile(top_count, 0.95)/200 | ||
|
||
# list for empty drops (output in high-sensitivity mode) | ||
DEFAULT_EMPTY_DROP_FN = 'emtpy_bc_list.csv' | ||
DEFAULT_KNEE_PLOT_FN = 'knee_plot.png' | ||
DEFAULT_BC_STAT_FN = "summary.txt" | ||
DEFAULT_EMPTY_DROP_MIN_ED = 5 # minimum edit distance from emtpy drop BC to selected BC | ||
DEFAULT_EMPTY_DROP_NUM = 2000 # number of BC in the output | ||
|
||
|
||
#################################################### | ||
##### DEFAULT in Demultiplexing ###### | ||
#################################################### | ||
|
||
DEFAULT_ASSIGNMENT_ED = 2 | ||
# Make sure this is smaller than DEFAULT_GRB_FLANKING_SIZE | ||
assert DEFAULT_GRB_FLANKING_SIZE >= DEFAULT_ASSIGNMENT_ED | ||
DEFAULT_ED_FLANKING = DEFAULT_ASSIGNMENT_ED | ||
|
||
|
||
|
||
BLAZE_LOGO = \ | ||
""" | ||
BBBBBBBBBBBBBBB LLLLL AAAAAA ZZZZZZZZZZZZZZEEEEEEEEEEEEEEE | ||
BBBBB&&&&&&&BBBB LLLLL AAAAAAAA ZZZZZZZZZZZZZZEEEEEEEEEEEEEEE | ||
BBBBB^^^^^^!BBBB LLLLL AAAAAAAAAA. ZZZZZ. EEEE | ||
BBBBB BBBB LLLLL AAAA AAAA. ZZZZZ. EEEEEEEEEEEEEEE | ||
BBBBBBBBBBBBBBB LLLLL AAAAAAAAAAAAAA ZZZZZ. EEEEEEEEEEEEEEE | ||
BBBBBBBBBBBBBBB LLLLL AAAAAAAAAAAAAAAA. ZZZZZ. EEEE | ||
BBBBB BBBB LLLLL AAAAAA AAAAA ZZZZZZZZZZZZEEEEEEEEEEEEEEE | ||
BBBBB BBBB LLLLLAAAAAA AAAAAZZZZZZZZZZZZEEEEEEEEEEEEEEE | ||
BBBBBBBBBBBBBBBB LLLLLLLLLLLLLLLLLLLL . ^PPPPPPY. ^PPPPPPY. 7PPP | ||
BBBBBBBBBBBBBBB LLLLLLLLLLLLLLLLLLLL...!BBBBBBP:...!BBBBBBP:.::.?BBB | ||
""" | ||
|
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,69 @@ | ||
# find specific reads with given read id and output to a new fastq file | ||
|
||
|
||
import argparse | ||
import Bio.SeqIO | ||
import multiprocessing as mp | ||
import textwrap | ||
from pathlib import Path | ||
|
||
|
||
import helper | ||
|
||
def parse_arg(): | ||
parser = argparse.ArgumentParser( | ||
description=textwrap.dedent( | ||
''' | ||
Find specific reads with given read id and output to a new fastq file | ||
''')) | ||
|
||
# Required positional argument | ||
parser.add_argument('input_fastq_dir', type=str, | ||
help='Fastq directory, Note that this should be a folder.') | ||
|
||
# required name argment | ||
requiredNamed = parser.add_argument_group('These Arguments are required') | ||
requiredNamed.add_argument( | ||
'--output_file', type=str, required = True, | ||
help='Filename for the output fastq.') | ||
requiredNamed.add_argument('--id_file', type=str, required = True, | ||
help='A file containing all the read ids to look for.') | ||
|
||
parser.add_argument('--threads', type=int, | ||
help='Number of threads. Default: # of CPU - 1') | ||
|
||
|
||
args = parser.parse_args() | ||
|
||
return args | ||
|
||
def find_reads(in_fastq, id_list): | ||
fastq = Bio.SeqIO.parse(in_fastq, "fastq") | ||
read_list = [r for r in fastq if r.id in id_list] | ||
return read_list | ||
# check id | ||
def main(args): | ||
|
||
# get ids (from args.id_file) | ||
ids = [] | ||
with open (args.id_file, 'r') as f: | ||
for line in f: | ||
ids.append(line.strip()) | ||
|
||
|
||
fastq_fns = list(Path(args.input_fastq_dir).rglob('*.fastq')) | ||
rst_futures = helper.multiprocessing_submit(find_reads, | ||
fastq_fns, | ||
n_process=args.threads, | ||
id_list = ids) | ||
|
||
rst_ls = [] | ||
for f in rst_futures: | ||
rst_ls+=f.result() | ||
|
||
print(len(rst_ls)) | ||
Bio.SeqIO.write(rst_ls, args.output_file, 'fastq') | ||
|
||
if __name__ == '__main__': | ||
args = parse_arg() | ||
main(args) |
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,82 @@ | ||
|
||
get_fastqc_counts() | ||
{ | ||
fastqc_file=$1 | ||
counts=$(unzip -p ${fastqc_file} $(basename ${fastqc_file} .zip)/fastqc_data.txt | \ | ||
grep 'Total Sequences' | \ | ||
cut -f2 -d$'\t') | ||
echo $counts | ||
|
||
} | ||
|
||
output="" | ||
input="" | ||
|
||
while [[ $# -gt 0 ]] | ||
do | ||
flag=$1 | ||
|
||
case "${flag}" in | ||
--input) input=$2; shift;; | ||
--output) output=$2; shift;; | ||
*) echo "Unknown option $1 ${reset}" && exit 1 | ||
esac | ||
shift | ||
done | ||
|
||
header="" | ||
data="" | ||
|
||
header="sample,base_fastq_counts,trimmed_read_counts,extracted_read_counts,corrected_read_counts" | ||
echo "$header" > $output | ||
|
||
for sample_name in $(for file in $(readlink -f $input)/*.zip; do echo $file; done | cut -f1 -d'.' | sort -u) | ||
do | ||
raw_fastqc="${sample_name}.raw_fastqc.zip" | ||
trim_fastqc="${sample_name}.trimmed_fastqc.zip" | ||
extract_fastqc="${sample_name}.extracted_fastqc.zip" | ||
correct_csv="${sample_name}.corrected_bc_umi.tsv" | ||
data="$(basename $sample_name)" | ||
|
||
# RAW FASTQ COUNTS | ||
|
||
if [[ -s "$raw_fastqc" ]] | ||
then | ||
fastqc_counts=$(get_fastqc_counts "$raw_fastqc") | ||
data="$data,$fastqc_counts" | ||
else | ||
data="$data," | ||
fi | ||
|
||
# TRIM COUNTS | ||
|
||
if [[ -s "$trim_fastqc" ]] | ||
then | ||
trim_counts=$(get_fastqc_counts "$trim_fastqc") | ||
data="$data,$trim_counts" | ||
else | ||
data="$data," | ||
fi | ||
|
||
# PREEXTRACT COUNTS | ||
|
||
if [ -s "$extract_fastqc" ] | ||
then | ||
extract_counts=$(get_fastqc_counts "$extract_fastqc") | ||
data="$data,$extract_counts" | ||
else | ||
data="$data," | ||
fi | ||
|
||
# CORRECT COUNTS | ||
|
||
|
||
if [ -s $correct_csv ] | ||
then | ||
correct_counts=$(cut -f6 $correct_csv | awk '{if ($0 != "") {print $0}}' | wc -l) | ||
data="$data,$correct_counts" | ||
else | ||
data="$data," | ||
fi | ||
echo "$data" >> $output | ||
done |
Oops, something went wrong.