Skip to content

Commit b8c06f1

Browse files
authored
Merge pull request #19 from michael-kotliar/master
Export 1-based coordinates
2 parents 3e9a4a4 + 26adb40 commit b8c06f1

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

altanalyze3/components/aggregate/main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,25 @@ def __init__(self):
5353
def add(self, sa, ea): # sa - start annotation, ea - end annotation
5454

5555
sa_shift = "" if sa.position == 0 else f"""_{sa.position}""" # junction start coord if not exact exon match
56-
ea_shift = "" if ea.position == 0 else f"""_{ea.position}""" # junction end coorf if not exact exon match
56+
ea_shift = "" if ea.position == 0 else f"""_{ea.position + 1}""" # junction end coorf if not exact exon match
5757

5858
if sa.match == AnnMatchCat.CLOSEST or ea.match == AnnMatchCat.CLOSEST: # not enough data to make a conclusion
5959
pass
6060
elif sa.gene == ea.gene and sa.strand == ea.strand: # the same gene and strand
6161
if sa.match == AnnMatchCat.EXON_END and ea.match == AnnMatchCat.EXON_START: # exact match
62-
self.__exact_match.append((f"""{sa.gene}:{sa.exon}-{ea.exon}""", sa.strand))
62+
if sa.strand == "+":
63+
self.__exact_match.append((f"""{sa.gene}:{sa.exon}-{ea.exon}""", sa.strand)) # start - end exons order
64+
elif sa.strand == "-":
65+
self.__exact_match.append((f"""{sa.gene}:{ea.exon}-{sa.exon}""", sa.strand)) # end - start exons order
66+
else:
67+
assert(False), "Not implemented logic"
6368
else: # partial match
64-
self.__partial_match.append((f"""{sa.gene}:{sa.exon}{sa_shift}-{ea.exon}{ea_shift}""", sa.strand))
69+
if sa.strand == "+":
70+
self.__partial_match.append((f"""{sa.gene}:{sa.exon}{sa_shift}-{ea.exon}{ea_shift}""", sa.strand)) # start - end exons order
71+
elif sa.strand == "-":
72+
self.__partial_match.append((f"""{sa.gene}:{ea.exon}{ea_shift}-{sa.exon}{sa_shift}""", sa.strand)) # end - start exons order
73+
else:
74+
assert(False), "Not implemented logic"
6575
else: # different gene and/or strand
6676
self.__distant_match.append((f"""{sa.gene}:{sa.exon}{sa_shift}-{ea.gene}:{ea.exon}{ea_shift}""", ".")) # distant match
6777

altanalyze3/utilities/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def export_counts_to_anndata(counts_df, location, counts_columns=None, metadata_
140140

141141
def __get_name(series, strand_coords):
142142
if strand_coords and "strand" in series and series.at["strand"] == "-":
143-
return f"""{series.at["chr"]}:{series.at["end"]}-{series.at["start"]}"""
143+
return f"""{series.at["chr"]}:{series.at["end"] + 1}-{series.at["start"]}"""
144144
else:
145-
return f"""{series.at["chr"]}:{series.at["start"]}-{series.at["end"]}"""
145+
return f"""{series.at["chr"]}:{series.at["start"]}-{series.at["end"] + 1}"""
146146

147147
csr_matrix = counts_df.loc[:, counts_columns].astype(pandas.SparseDtype(sparse_dtype, fill_value)).T.sparse.to_coo().tocsr()
148148
adata = anndata.AnnData(csr_matrix, dtype=sparse_dtype)

altanalyze3/utilities/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def get_parser(self):
223223
)
224224
aggregate_parser.add_argument(
225225
"--bed",
226-
help="Export annotated coordinates as BED file. Default: False",
226+
help="Export annotated 0-based coordinates as BED file. Default: False",
227227
action="store_true"
228228
)
229229
self.add_common_arguments(aggregate_parser)

tests/unit_tests/test_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"Cal27P5-3.bam": "3d6fdef5e90c16deed6c36b418c597c4",
1414
"Cal27P5-3.bam.bai": "c92fbf32ffcf874979c41051f0d2e16c",
1515
"Cal27P5-1-copy.bam": "6e418cb604ea82c90d4b3e832afb4997",
16-
"Cal27P5_1_aggregated_counts.bed.gz": "26251bd42bac659434799040c8b0caf8",
16+
"Cal27P5_1_aggregated_counts.bed.gz": "faee5946f7d18064773fc67e01e4ce5b",
1717
"Cal27P5_1_intcounts.bed": "6f5250f1a841438fadcbe1419966f133",
1818
"Cal27P5_1_juncounts.bed": "24f6a6ac5f831c7709102c235db03ec5",
1919
"Cal27P5_2_intcounts.bed": "2d9889a6520f96012ba7d4be5cdcfea3",

0 commit comments

Comments
 (0)