Skip to content

Commit

Permalink
Merge pull request #37 from stjude/fix
Browse files Browse the repository at this point in the history
Fix
  • Loading branch information
rawagiha authored Apr 18, 2023
2 parents fdbf1d8 + 426ef91 commit 797fff3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
18 changes: 7 additions & 11 deletions rnaindel/analysis/postprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def postprocess(df, data_dir, perform_outlier_analysis, pon):

df = df[df["keep_this"]]

df.reset_index(drop=True, inplace=True)

return sort_positionally(df)


Expand Down Expand Up @@ -61,7 +63,6 @@ def is_rescurable_homopolymer(row):


def filter_str(row, non_somatic_db, pon, mapping_thresh):

pred = row["predicted_class"]

if pred == "somatic":
Expand All @@ -79,7 +80,6 @@ def filter_str(row, non_somatic_db, pon, mapping_thresh):


def filter_by_db(row, non_somatic_db, pon):

non_somatic_hits = row["indel"].query_vcf(non_somatic_db)

if non_somatic_hits:
Expand Down Expand Up @@ -126,16 +126,12 @@ def reclassify_by_knowledge(row, cosmic):


def sort_positionally(df):
df["chrom"] = df.apply(lambda x: x["chrom"].replace("chr", ""), axis=1)
df["chrom"] = df.apply(lambda x: 23 if x["chrom"] == "X" else x["chrom"], axis=1)
df["chrom"] = df.apply(lambda x: 24 if x["chrom"] == "Y" else x["chrom"], axis=1)
df["chrom"] = df.apply(lambda x: int(x["chrom"]), axis=1)

df.sort_values(["chrom", "cpos"], inplace=True)
df["_chrom"] = df.apply(lambda x: x["chrom"].replace("chr", ""), axis=1)
df["_chrom"] = df.apply(lambda x: 23 if x["chrom"] == "X" else x["_chrom"], axis=1)
df["_chrom"] = df.apply(lambda x: 24 if x["chrom"] == "Y" else x["_chrom"], axis=1)
df["_chrom"] = df.apply(lambda x: int(x["_chrom"]), axis=1)

df["chrom"] = df.apply(lambda x: "Y" if x["chrom"] == 24 else x["chrom"], axis=1)
df["chrom"] = df.apply(lambda x: "X" if x["chrom"] == 23 else x["chrom"], axis=1)
df["chrom"] = df.apply(lambda x: "chr" + str(x["chrom"]), axis=1)
df.sort_values(["_chrom", "cpos"], inplace=True)

return df

Expand Down
30 changes: 18 additions & 12 deletions rnaindel/analysis/vcf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


def write_vcf(df, version, arguments, tdna, ndna):

header = (
header_1(version, arguments.reference)
+ filter_fields()
Expand All @@ -17,7 +16,14 @@ def write_vcf(df, version, arguments, tdna, ndna):
+ bottom_header(arguments.bam)
)

f = open(arguments.output_vcf, "w")
_out_vcf = arguments.output_vcf
if _out_vcf.endswith(".vcf.gz"):
_out_vcf = _out_vcf[:-3]

if not _out_vcf.endswith(".vcf"):
_out_vcf = _out_vcf + ".vcf"

f = open(_out_vcf, "w")

f.write("\n".join(header))

Expand All @@ -27,9 +33,7 @@ def write_vcf(df, version, arguments, tdna, ndna):

f.close()

pysam.tabix_index(
arguments.output_vcf, preset="vcf", force=True, keep_original=False
)
pysam.tabix_index(_out_vcf, preset="vcf", force=True, keep_original=False)


def header_1(version, fasta):
Expand Down Expand Up @@ -230,13 +234,15 @@ def parse_row_to_vcf_record(row):


def generate_info_str(row):
info_str = "predicted_class={};probabilities={},{},{};annotation={};cosmic_cnt={};".format(
row["predicted_class"],
row["prob_s"],
row["prob_g"],
row["prob_a"],
row["annotation"],
row["cosmic_cnt"],
info_str = (
"predicted_class={};probabilities={},{},{};annotation={};cosmic_cnt={};".format(
row["predicted_class"],
row["prob_s"],
row["prob_g"],
row["prob_a"],
row["annotation"],
row["cosmic_cnt"],
)
)

if row["pop_freq"] > 0:
Expand Down
3 changes: 1 addition & 2 deletions rnaindel/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__version__ = "3.2.3"

__version__ = "3.2.4"

0 comments on commit 797fff3

Please sign in to comment.