Skip to content

Commit

Permalink
Fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
drpatelh committed Sep 12, 2022
1 parent 4d7cbef commit 65082e5
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 53 deletions.
2 changes: 1 addition & 1 deletion assets/email_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<meta name="description" content="nf-core/scrnaseq: Pipeline for processing of 10xGenomics single cell rnaseq data">
<meta name="description" content="nf-core/scrnaseq: Pipeline for processing 10x Genomics single cell rnaseq data">
<title>nf-core/scrnaseq Pipeline Report</title>
</head>
<body>
Expand Down
11 changes: 6 additions & 5 deletions bin/cellranger_mtx_to_h5ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import scanpy as sc
import argparse

def mtx_to_adata( mtx_h5: str, sample: str, verbose: bool = False ):

def mtx_to_adata(mtx_h5: str, sample: str, verbose: bool = False):

if verbose:
print("Reading in {}".format(mtx_h5))
Expand All @@ -19,10 +20,10 @@ def mtx_to_adata( mtx_h5: str, sample: str, verbose: bool = False ):

parser = argparse.ArgumentParser(description="Converts mtx output to h5ad.")

parser.add_argument("-m", "--mtx", dest="mtx", help="Path to mtx h5 file." )
parser.add_argument("-v", "--verbose", dest="verbose", help="Toggle verbose messages", default=False )
parser.add_argument("-s", "--sample", dest="sample", help="Sample name" )
parser.add_argument("-o", "--out", dest="out", help="Output path." )
parser.add_argument("-m", "--mtx", dest="mtx", help="Path to mtx h5 file.")
parser.add_argument("-v", "--verbose", dest="verbose", help="Toggle verbose messages", default=False)
parser.add_argument("-s", "--sample", dest="sample", help="Sample name")
parser.add_argument("-o", "--out", dest="out", help="Output path.")

args = vars(parser.parse_args())

Expand Down
15 changes: 7 additions & 8 deletions bin/concat_h5ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import argparse


def read_samplesheet(samplesheet):
df = pd.read_csv(samplesheet)
df.set_index("sample")
Expand All @@ -12,14 +13,15 @@ def read_samplesheet(samplesheet):
# only keep unique values using set()
df = df.groupby(["sample"]).agg(lambda column: ",".join(set(column)))

return(df)
return df


if __name__ == "__main__":

parser = argparse.ArgumentParser(description="Concatenates h5ad files and merge metadata from samplesheet")

parser.add_argument("-i", "--input", dest="input", help="Path to samplesheet.csv")
parser.add_argument("-o", "--out", dest="out", help="Output path.")
parser.add_argument("-i", "--input", dest="input", help="Path to samplesheet.csv")
parser.add_argument("-o", "--out", dest="out", help="Output path.")
parser.add_argument("-s", "--suffix", dest="suffix", help="Suffix of matrices to remove and get sample name")

args = vars(parser.parse_args())
Expand All @@ -28,10 +30,7 @@ def read_samplesheet(samplesheet):
df_samplesheet = read_samplesheet(args["input"])

# find all h5ad and append to dict
dict_of_h5ad = {
str(path).replace(args["suffix"], ""): sc.read_h5ad(path)
for path in Path(".").rglob('*.h5ad')
}
dict_of_h5ad = {str(path).replace(args["suffix"], ""): sc.read_h5ad(path) for path in Path(".").rglob("*.h5ad")}

# concat h5ad files
adata = ad.concat(dict_of_h5ad, label="sample", merge="unique", index_unique="_")
Expand All @@ -40,4 +39,4 @@ def read_samplesheet(samplesheet):
adata.obs = adata.obs.join(df_samplesheet, on="sample")
adata.write_h5ad(args["out"], compression="gzip")

print("Wrote h5ad file to {}".format(args["out"]))
print("Wrote h5ad file to {}".format(args["out"]))
14 changes: 6 additions & 8 deletions bin/mtx_to_h5ad.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import argparse


def mtx_to_adata(
mtx_file: str, barcode_file: str, feature_file: str, sample: str, aligner: str, verbose: bool = False
):
def mtx_to_adata(mtx_file: str, barcode_file: str, feature_file: str, sample: str, aligner: str, verbose: bool = False):

if verbose:
print("Reading in {}".format(mtx_file))

adata = sc.read_mtx(mtx_file)
if aligner == 'star': # for some reason star matrix comes transposed and doesn't fit when values are appended directly
if (
aligner == "star"
): # for some reason star matrix comes transposed and doesn't fit when values are appended directly
adata = adata.transpose()
adata.obs_names = pd.read_csv(barcode_file, header=None, sep="\t")[0].values
adata.var_names = pd.read_csv(feature_file, header=None, sep="\t")[0].values
Expand All @@ -26,9 +26,7 @@ def mtx_to_adata(
parser = argparse.ArgumentParser(description="Converts mtx output to h5ad.")

parser.add_argument("-m", "--mtx", dest="mtx", help="Path to mtx file.")
parser.add_argument(
"-v", "--verbose", dest="verbose", help="Toggle verbose messages", default=False
)
parser.add_argument("-v", "--verbose", dest="verbose", help="Toggle verbose messages", default=False)
parser.add_argument("-f", "--feature", dest="feature", help="Path to feature file.")
parser.add_argument("-b", "--barcode", dest="barcode", help="Path to barcode file.")
parser.add_argument("-s", "--sample", dest="sample", help="Sample name")
Expand All @@ -38,7 +36,7 @@ def mtx_to_adata(
args = vars(parser.parse_args())

adata = mtx_to_adata(
args["mtx"], args["barcode"], args["feature"], args["sample"], args["aligner"],verbose=args["verbose"]
args["mtx"], args["barcode"], args["feature"], args["sample"], args["aligner"], verbose=args["verbose"]
)

adata.write_h5ad(args["out"], compression="gzip")
Expand Down
63 changes: 32 additions & 31 deletions bin/t2g.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#This was downloaded on 2019-06-23 from https://github.com/bustools/getting_started/releases/
#All credit goes to the original authors from the Kallisto/BUStools team!
# This was downloaded on 2019-06-23 from https://github.com/bustools/getting_started/releases/
# All credit goes to the original authors from the Kallisto/BUStools team!
# BSD 2-Clause License
#
# Copyright (c) 2017, Nicolas Bray, Harold Pimentel, Páll Melsted and Lior Pachter
Expand Down Expand Up @@ -29,43 +29,43 @@

import sys, argparse

def create_transcript_list(input, use_name = True, use_version = False):

def create_transcript_list(input, use_name=True, use_version=False):
r = {}
for line in input:
if len(line) == 0 or line[0] == '#':
if len(line) == 0 or line[0] == "#":
continue
l = line.strip().split('\t')
if l[2] == 'transcript':
l = line.strip().split("\t")
if l[2] == "transcript":
info = l[8]
d = {}
for x in info.split('; '):
for x in info.split("; "):
x = x.strip()
p = x.find(' ')
p = x.find(" ")
if p == -1:
continue
k = x[:p]
p = x.find('"',p)
p2 = x.find('"',p+1)
v = x[p+1:p2]
p = x.find('"', p)
p2 = x.find('"', p + 1)
v = x[p + 1 : p2]
d[k] = v


if 'transcript_id' not in d or 'gene_id' not in d:
if "transcript_id" not in d or "gene_id" not in d:
continue

tid = d['transcript_id'].split(".")[0]
gid = d['gene_id'].split(".")[0]
tid = d["transcript_id"].split(".")[0]
gid = d["gene_id"].split(".")[0]
if use_version:
if 'transcript_version' not in d or 'gene_version' not in d:
if "transcript_version" not in d or "gene_version" not in d:
continue

tid += '.' + d['transcript_version']
gid += '.' + d['gene_version']
tid += "." + d["transcript_version"]
gid += "." + d["gene_version"]
gname = None
if use_name:
if 'gene_name' not in d:
if "gene_name" not in d:
continue
gname = d['gene_name']
gname = d["gene_name"]

if tid in r:
continue
Expand All @@ -74,26 +74,27 @@ def create_transcript_list(input, use_name = True, use_version = False):
return r



def print_output(output, r, use_name = True):
def print_output(output, r, use_name=True):
for tid in r:
if use_name:
output.write("%s\t%s\t%s\n"%(tid, r[tid][0], r[tid][1]))
output.write("%s\t%s\t%s\n" % (tid, r[tid][0], r[tid][1]))
else:
output.write("%s\t%s\n"%(tid, r[tid][0]))
output.write("%s\t%s\n" % (tid, r[tid][0]))


if __name__ == "__main__":


parser = argparse.ArgumentParser(add_help=True, description='Creates transcript to gene info from GTF files\nreads from standard input and writes to standard output')
parser.add_argument('--use_version', '-v', action='store_true', help='Use version numbers in transcript and gene ids')
parser.add_argument('--skip_gene_names', '-s', action='store_true', help='Do not output gene names')
parser = argparse.ArgumentParser(
add_help=True,
description="Creates transcript to gene info from GTF files\nreads from standard input and writes to standard output",
)
parser.add_argument(
"--use_version", "-v", action="store_true", help="Use version numbers in transcript and gene ids"
)
parser.add_argument("--skip_gene_names", "-s", action="store_true", help="Do not output gene names")
args = parser.parse_args()



input = sys.stdin
r = create_transcript_list(input, use_name = not args.skip_gene_names, use_version = args.use_version)
r = create_transcript_list(input, use_name=not args.skip_gene_names, use_version=args.use_version)
output = sys.stdout
print_output(output, r)

0 comments on commit 65082e5

Please sign in to comment.