Skip to content

Commit d1b4d8e

Browse files
committed
reformat code using black
1 parent a958d53 commit d1b4d8e

File tree

5 files changed

+56
-16
lines changed

5 files changed

+56
-16
lines changed

src/cbiohub/analyze.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ def find_variant(
9999

100100

101101
def variant_frequency_per_clinical_attribute(
102-
variant: Union[GenomicVariant, ProteinVariant], clinical_attribute,
103-
directory=None, group_by_study_id=False, count_samples=False, sql=False
102+
variant: Union[GenomicVariant, ProteinVariant],
103+
clinical_attribute,
104+
directory=None,
105+
group_by_study_id=False,
106+
count_samples=False,
107+
sql=False,
104108
):
105109
"""Check how frequently a particular variant occurs per cancer type."""
106110
if directory is None:
@@ -136,8 +140,12 @@ def variant_frequency_per_clinical_attribute(
136140
"""
137141
group_by_clause = f"clinical.{clinical_attribute}, TotalPerAttribute.total"
138142
total_group_by = f"clinical.{clinical_attribute}"
139-
total_join = f"clinical.{clinical_attribute} = TotalPerAttribute.{clinical_attribute}"
140-
total_select = f"clinical.{clinical_attribute}, COUNT(DISTINCT {count_attribute}) AS total"
143+
total_join = (
144+
f"clinical.{clinical_attribute} = TotalPerAttribute.{clinical_attribute}"
145+
)
146+
total_select = (
147+
f"clinical.{clinical_attribute}, COUNT(DISTINCT {count_attribute}) AS total"
148+
)
141149

142150
if group_by_study_id:
143151
total_select = f"clinical.STUDY_ID, {total_select}"

src/cbiohub/cli.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def cli():
4646

4747
cli.add_command(data)
4848

49+
4950
@cli.command()
5051
def config():
5152
"""Display the current configuration settings."""
@@ -86,11 +87,18 @@ def find(arg1, arg2, arg3, arg4, arg5, processed_dir, sql):
8687
if arg1 and arg2 and arg3 and arg4:
8788
# assuming chrom/pos/start/end
8889
exists, unique_ids = find_variant(
89-
chrom=arg1, start=arg2, end=arg3, ref=arg4, alt=arg5, directory=processed_dir
90+
chrom=arg1,
91+
start=arg2,
92+
end=arg3,
93+
ref=arg4,
94+
alt=arg5,
95+
directory=processed_dir,
9096
)
9197
elif arg1 and arg2:
9298
# assuming gene/protein_change
93-
exists, unique_ids = find_variant(hugo_symbol=arg1, protein_change=arg2, directory=processed_dir)
99+
exists, unique_ids = find_variant(
100+
hugo_symbol=arg1, protein_change=arg2, directory=processed_dir
101+
)
94102
else:
95103
click.echo(click.style("❌ Invalid arguments.", fg="red"))
96104
return
@@ -108,6 +116,7 @@ def find(arg1, arg2, arg3, arg4, arg5, processed_dir, sql):
108116
else:
109117
click.echo(click.style("❌ Variant not found.", fg="red"))
110118

119+
111120
def detect_variant_type(args):
112121
"""
113122
Detects the variant type based on the number and structure of arguments.
@@ -121,10 +130,13 @@ def detect_variant_type(args):
121130
elif len(args) == 2:
122131
return ProteinVariant(*args)
123132
else:
124-
raise click.UsageError("Could not detect variant type. Ensure arguments match either chrom/start/end/ref/alt or gene/protein_change format.")
133+
raise click.UsageError(
134+
"Could not detect variant type. Ensure arguments match either chrom/start/end/ref/alt or gene/protein_change format."
135+
)
136+
125137

126138
@cli.command(help="Check how frequently a particular variant occurs per cancer type.")
127-
@click.argument('args', nargs=-1, required=True)
139+
@click.argument("args", nargs=-1, required=True)
128140
@click.option(
129141
"--clinical-attribute",
130142
default="CANCER_TYPE",
@@ -143,14 +155,20 @@ def detect_variant_type(args):
143155
help="Count samples instead of patients",
144156
)
145157
@common_options
146-
def variant_frequency(args, clinical_attribute, processed_dir, sql, group_by_study_id, count_samples):
158+
def variant_frequency(
159+
args, clinical_attribute, processed_dir, sql, group_by_study_id, count_samples
160+
):
147161
"""Check how frequently a particular variant occurs per cancer type (or
148162
other clinical sample attributes)."""
149163
variant = detect_variant_type(args)
150164

151165
result = variant_frequency_per_clinical_attribute(
152-
variant, clinical_attribute, directory=processed_dir, sql=sql, group_by_study_id=group_by_study_id,
153-
count_samples=count_samples
166+
variant,
167+
clinical_attribute,
168+
directory=processed_dir,
169+
sql=sql,
170+
group_by_study_id=group_by_study_id,
171+
count_samples=count_samples,
154172
)
155173
if sql:
156174
return print(result)

src/cbiohub/data_commands.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ def combine(output_dir):
167167
)
168168

169169
for mutation_file in MUTATION_DATA_FILES:
170-
mutation_file = study.processed_path / mutation_file.replace("txt","parquet")
170+
mutation_file = study.processed_path / mutation_file.replace(
171+
"txt", "parquet"
172+
)
171173
if mutation_file.exists():
172174
table = pq.read_table(mutation_file)
173175
# Select only specific columns and adjust their types

src/cbiohub/study.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
settings,
66
) # Assuming settings is a module with PROCESSED_PATH defined
77

8-
MUTATION_DATA_FILES = ["data_mutations.txt", "data_mutations_extended.txt", "data_nonsignedout_mutations.txt"]
8+
MUTATION_DATA_FILES = [
9+
"data_mutations.txt",
10+
"data_mutations_extended.txt",
11+
"data_nonsignedout_mutations.txt",
12+
]
13+
914

1015
class Study:
1116
def __init__(self, study_path: Path):
@@ -16,7 +21,9 @@ def __init__(self, study_path: Path):
1621
self.patient_data_file = "data_clinical_patient.txt"
1722
# mutation data can have multiple names
1823
self.mutation_data_files = [
19-
mut_file for mut_file in MUTATION_DATA_FILES if (self.study_path / mut_file).exists()
24+
mut_file
25+
for mut_file in MUTATION_DATA_FILES
26+
if (self.study_path / mut_file).exists()
2027
]
2128
# all mutation data files are combined into this file
2229
self.mutation_parquet_file = "data_mutations.parquet"
@@ -180,7 +187,10 @@ def is_processed(self):
180187
source_files = [
181188
self.study_path / self.sample_data_file,
182189
self.study_path / self.patient_data_file,
183-
*[self.study_path / mutation_data_file for mutation_data_file in self.mutation_data_files],
190+
*[
191+
self.study_path / mutation_data_file
192+
for mutation_data_file in self.mutation_data_files
193+
],
184194
self.study_path / "meta_study.txt",
185195
]
186196

src/cbiohub/variant.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ def __init__(self, chrom, start, end, ref, alt):
1010
class ProteinVariant:
1111
def __init__(self, gene, protein_change):
1212
self.gene = gene
13-
self.protein_change = protein_change if protein_change.startswith("p.") else f"p.{protein_change}"
13+
self.protein_change = (
14+
protein_change if protein_change.startswith("p.") else f"p.{protein_change}"
15+
)

0 commit comments

Comments
 (0)