Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/sprocket-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
env:
RUNNER: ${{ matrix.runner }}
run: |
sprocket dev test --filter-tag reference --filter-tag slow --filter-tag high_mem ${{ matrix.file }}
sprocket dev test --exclude-tag reference --exclude-tag slow --exclude-tag high_mem ${{ matrix.file }}
2 changes: 2 additions & 0 deletions data_structures/flag_filter.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ task validate_string_is_12bit_int {
}
command <<<
set -euo pipefail
if [[ "~{number}" =~ ^[1-9][0-9]*$ ]]; then
# number is in decimal
if [ "~{number}" -lt 4096 ]; then
Expand Down
6 changes: 6 additions & 0 deletions data_structures/read_group.wdl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ task get_read_groups {
Int disk_size_gb = ceil(bam_size) + 10 + modify_disk_size_gb

command <<<
set -euo pipefail

python3 /scripts/data_structures/get_read_groups.py \
"~{bam}" \
read_groups.json
Expand Down Expand Up @@ -181,6 +183,8 @@ task validate_read_group {
]

command <<<
set -euo pipefail

exit_code=0
if ~{restrictive}; then
if [[ "~{read_group.ID}" =~ ~{restrictive_pattern} ]]
Expand Down Expand Up @@ -396,6 +400,8 @@ task inner_read_group_to_string {
else " "

command <<<
set -euo pipefail

if ~{format_as_sam_record}; then
echo -n "@RG~{delimiter}" > out.txt
fi
Expand Down
20 changes: 10 additions & 10 deletions scripts/data_structures/get_read_groups.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import pysam
import json

import pysam


def main(bam_path, outfile_path):
sam = pysam.AlignmentFile(bam_path, "rb")

out_file = open(outfile_path, "w")
header = sam.header.to_dict()["RG"]
modified_header = []
for read_group in sorted(header, key=lambda d: d["ID"]):
modified_header.append(
{k: v.upper() if k == "PL" else v for k, v in read_group.items()}
)
json.dump(modified_header, out_file)
out_file.close()
with open(outfile_path, "w") as out_file:
header = sam.header.to_dict()["RG"]
modified_header = []
for read_group in sorted(header, key=lambda d: d["ID"]):
modified_header.append(
{k: v.upper() if k == "PL" else v for k, v in read_group.items()}
)
json.dump(modified_header, out_file)


if __name__ == "__main__":
Expand Down
49 changes: 23 additions & 26 deletions scripts/htseq/calc_tpm.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
def main(counts_name_path, feature_lengths_path, outfile_path, has_header):
counts_file = open(counts_name_path, "r")
counts = {}
if has_header:
counts_file.readline()
for line in counts_file:
gene, count = line.split("\t")
if gene[0:2] == "__":
break
counts[gene.strip()] = int(count.strip())
counts_file.close()
with open(counts_name_path, "r") as counts_file:
counts = {}
if has_header:
counts_file.readline()
for line in counts_file:
gene, count = line.split("\t")
if gene[0:2] == "__":
break
counts[gene.strip()] = int(count.strip())

lengths_file = open(feature_lengths_path, "r")
rpks = {} # Reads Per Kilobase
tot_rpk = 0
lengths_file.readline() # discard header
for line in lengths_file:
gene, length = line.split("\t")
rpk = counts[gene.strip()] / int(length.strip()) * 1000
tot_rpk += rpk
rpks[gene.strip()] = rpk
lengths_file.close()
with open(feature_lengths_path, "r") as lengths_file:
rpks = {} # Reads Per Kilobase
tot_rpk = 0
lengths_file.readline() # discard header
for line in lengths_file:
gene, length = line.split("\t")
rpk = counts[gene.strip()] / int(length.strip()) * 1000
tot_rpk += rpk
rpks[gene.strip()] = rpk

scaling_factor = tot_rpk / 1000000

sample_name = ".".join(outfile_path.split(".")[:-2]) # assumed to end in `.TPM.txt`
outfile = open(outfile_path, "w")
print(f"feature\t{sample_name}", file=outfile)
for gene, rpk in sorted(rpks.items()):
tpm = rpk / scaling_factor
print(f"{gene}\t{tpm:.3f}", file=outfile)
outfile.close()
with open(outfile_path, "w") as outfile:
print(f"feature\t{sample_name}", file=outfile)
for gene, rpk in sorted(rpks.items()):
tpm = rpk / scaling_factor
print(f"{gene}\t{tpm:.3f}", file=outfile)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions scripts/methylation/combine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import argparse

import pandas as pd


Expand Down
5 changes: 3 additions & 2 deletions scripts/methylation/filter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import argparse
import csv
import pandas as pd

import numpy as np
import argparse
import pandas as pd


def get_args():
Expand Down
3 changes: 2 additions & 1 deletion scripts/methylation/generate_umap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse

import pandas as pd
import umap
import argparse


def get_args():
Expand Down
5 changes: 3 additions & 2 deletions scripts/methylation/plot_umap.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pandas as pd
import matplotlib.pyplot as plt
import argparse

import matplotlib.pyplot as plt
import pandas as pd


def get_args():
parser = argparse.ArgumentParser(description="Plot UMAP coordinates.")
Expand Down
25 changes: 12 additions & 13 deletions scripts/util/calc_feature_lengths.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from collections import defaultdict

import gtfparse
import numpy as np
from collections import defaultdict


def main(gtf_path, outfile_path, id_attr):
gtf = gtfparse.read_gtf(gtf_path)

only_exons = gtf[gtf["feature"] == "exon"]
exon_starts = defaultdict(lambda: [])
exon_ends = defaultdict(lambda: [])
exon_starts = defaultdict(list)
exon_ends = defaultdict(list)
gene_start_offset = {}
gene_end_offset = {}
gene_exon_intersection = {}
Expand Down Expand Up @@ -43,16 +44,14 @@ def main(gtf_path, outfile_path, id_attr):
- gene_start_offset[feature_id]
] = True

outfile = open(outfile_path, "w")
print("feature\tlength", file=outfile)
for gene, exonic_intersection in sorted(gene_exon_intersection.items()):
# np.count_nonzero() is faster than sum
# np.count_nonzero() evaluates the "truthfulness" of
# of all elements (by calling their '.__bool__()' method)
length = np.count_nonzero(exonic_intersection)
print(f"{gene}\t{length}", file=outfile)

outfile.close()
with open(outfile_path, "w") as outfile:
print("feature\tlength", file=outfile)
for gene, exonic_intersection in sorted(gene_exon_intersection.items()):
# np.count_nonzero() is faster than sum
# np.count_nonzero() evaluates the "truthfulness" of
# of all elements (by calling their '.__bool__()' method)
length = np.count_nonzero(exonic_intersection)
print(f"{gene}\t{length}", file=outfile)


if __name__ == "__main__":
Expand Down
Loading
Loading