forked from guigolab/ggsashimi
-
Notifications
You must be signed in to change notification settings - Fork 0
Patient bam processing #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pj-sullivan
wants to merge
5
commits into
master
Choose a base branch
from
pj-sullivan/bams
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
36c337f
patient bam processing
pj-sullivan c16e470
restructure analyses
pj-sullivan 0530ee6
make inputs arguments
pj-sullivan 011d7ec
download reference genome
pj-sullivan 94f7d9f
index reference genome and create result md5sum
pj-sullivan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,92 @@ | ||
| #!/bin/bash | ||
|
|
||
| ## Define default variables | ||
| kf_id_col=1 # KF patient ID column | ||
| chr_col=3 # Chromosome | ||
| pos_col=4 # Position | ||
| label_col=11 # Additional label to add to plot for identification, i.e. gene | ||
| window=10000 # Bases to plot either side of the position given | ||
|
Comment on lines
+5
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A few notes here:
|
||
|
|
||
| ## Set up input files | ||
| while getopts i:m:k:c:p:l: opt; do | ||
| case "${opt}" in | ||
| i) input_file=${OPTARG};; # header is expected | ||
| m) manifest=${OPTARG};; | ||
| k) kf_id_col=${OPTARG};; | ||
| c) chr_col=${OPTARG};; | ||
| p) pos_col=${OPTARG};; | ||
| l) label_col=${OPTARG};; | ||
| w) window=${OPTARG};; | ||
| esac | ||
| done | ||
|
|
||
| if [[ -z "$input_file" ]]; then | ||
| echo "Error: Input file (-i) is required." | ||
| fi | ||
|
|
||
| if [[ -z "$manifest" ]]; then | ||
| echo "Error: Manifest (-m) is required." | ||
| fi | ||
|
|
||
| ## Download genome reference | ||
| URL="https://hgdownload.soe.ucsc.edu/goldenPath/hg38/bigZips/hg38.fa.gz" | ||
| ref_genome="../data/hg38.fa" | ||
|
|
||
| if [ -f "$ref_genome" ]; then | ||
| echo "Using reference genome: $ref_genome" | ||
| else | ||
| echo "Downloading reference genome..." | ||
| curl -L -o "$ref_genome.gz" "$URL" | ||
|
|
||
| # Verify download succeeded | ||
| if [ $? -eq 0 ]; then | ||
| gunzip $ref_genome.gz | ||
| samtools faidx $ref_genome | ||
| echo "Download complete: $ref_genome" | ||
| else | ||
| echo "Download failed." | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| #################################################### | ||
|
|
||
| # Loop through variant file | ||
| while read line; do | ||
| KF_id=$(echo "$line" | cut -f $kf_id_col) | ||
| chr=$(echo "$line" | cut -f $chr_col) | ||
| coord_pos=$(echo "$line" | cut -f $pos_col) | ||
| label=$(echo "$line" | cut -f $label_col) | ||
|
|
||
| prefix="$KF_id-$label-$chr-$coord_pos" | ||
| echo "Processing $prefix" | ||
|
|
||
| ## TODO: Get window from splice event | ||
| coordinates=$chr":"$(($coord_pos - $window))"-"$(($coord_pos + $window)) | ||
|
|
||
| ## get file id | ||
| crams=$(grep "$KF_id" $manifest | grep "Aligned.out.sorted.cram" | grep -v "crai" | cut -f2) | ||
|
|
||
| ## loop through each CRAM per patient | ||
| ## TODO: Make select from BS_ID an option? | ||
| for cram in $crams; do | ||
| cram_path="../data/cavatica/projects/sicklera/pbta-and-normal-crams/$cram" | ||
|
|
||
| # prefix: derive from file name | ||
| prefix=$(basename "$cram" .Aligned.out.sorted.cram) | ||
|
|
||
| echo "Converting $cram_path" | ||
| bam_path="results/bams/${prefix}-${KF_id}-${label}-${coordinates}.bam" | ||
| # input_path="variants/${prefix}-${KF_id}-${label}-${coordinates}.tsv" | ||
|
|
||
| samtools view \ | ||
| -T $ref_genome \ | ||
| -b \ | ||
| "$cram_path" \ | ||
| "$coordinates" \ | ||
| -o "$bam_path" | ||
|
|
||
| samtools index "$bam_path" | ||
|
|
||
| done | ||
| done < <(tail -n +2 $input_file) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should be doing these queries by BS_ID rather than patient ID, because there are often multiple RNA-seq cram files from different sample collections from the same patient.