Skip to content

Commit

Permalink
Merge branch 'dev' into 136-fix-merge_tablesr-fails-if-given-empty-input
Browse files Browse the repository at this point in the history
  • Loading branch information
deliaBlue authored Jul 31, 2024
2 parents fd7aa10 + c5d78df commit bcaba31
Show file tree
Hide file tree
Showing 18 changed files with 923 additions and 363 deletions.
494 changes: 322 additions & 172 deletions scripts/mirna_extension.py

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions scripts/mirna_quantification.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,18 @@ def collapsed_nh_contribution(aln: pysam.AlignedSegment) -> float:
The contribution is computed as the ratio of the number of reads collapsed
in the alignment and the NH value. It is assumed that the alignment query
name contians the number of collapsed reads as well as the NH value in the
name contains the number of collapsed reads as well as the NH value in the
format NAME-COUNT_NH.
Args:
aln:
Alignment to which the overall contribution is calculated
Returns:
the conrtibution of the alignment to the overall count
Contribution of alignment to overall count
"""
name = str(aln.query_name)
values = []
try:
if val := re.search(r"\d+_\d+$", name):
values = val.group().split("_")
Expand All @@ -274,17 +275,18 @@ def collapsed_contribution(aln: pysam.AlignedSegment) -> float:
The contribution is computed as the ratio of the number of reads collapsed
in the alignment and the value stored in the NH tag. If the tag is missing,
the NH value is 1. It is assumed that the alignment query name contians
the NH value is 1. It is assumed that the alignment query name contains
the number of collapsed reads in the format NAME-COUNT.
Args:
aln:
Alignment to which the overall contribution is calculated
Returns:
the conrtibution of the alignment to the overall count
Contribution of alignment to overall count
"""
name = str(aln.query_name)
collapsed = 0.0
try:
if coll := re.search(r"\d+$", name):
collapsed = float(coll.group())
Expand Down Expand Up @@ -312,17 +314,18 @@ def nh_contribution(aln: pysam.AlignedSegment) -> float:
The contribution is computed as the ratio of the number of reads collapsed
in the alignment and the value stored in the NH tag. If the tag is missing,
the NH value is 1. It is assumed that the alignment query name contians the
the NH value is 1. It is assumed that the alignment query name contains the
NH value in the format NAME_NH.
Args:
aln:
Alignment to which the overall contribution is calculated
Returns:
the conrtibution of the alignment to the overall count
Contribution of alignment to overall count
"""
name = str(aln.query_name)
nh_val = 0.0
try:
if cont := re.search(r"\d+$", name):
nh_val = float(cont.group())
Expand Down Expand Up @@ -352,7 +355,7 @@ def contribution(aln: pysam.AlignedSegment) -> float:
Alignment to which the overall contribution is calculated
Returns:
the conrtibution of the alignment to the overall count
Contribution of alignment to overall count
"""
try:
return 1 / float(aln.get_tag("NH"))
Expand All @@ -362,7 +365,7 @@ def contribution(aln: pysam.AlignedSegment) -> float:


def get_name(pre_name: str) -> list[str]:
"""Get the final name for the spieces name.
"""Get the final name for the species name.
Take a string and processes it to obtain the final name for the species
and the type of miRNA the string belongs to. Only the feat_name is
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions scripts/tests/files/extreme_chr_mir_anno.gff3
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
19 . miRNA 0 80 . + . ID=MIMAT0002822;Alias=MIMAT0002822;Name=hsa-miR-512-5p;Derives_from=MI0003140
19 . miRNA 83 124 . + . ID=MIMAT0002823;Alias=MIMAT0002823;Name=hsa-miR-512-3p;Derives_from=MI0003140
19 . miRNA 1 80 . + . ID=MIMAT0002822;Alias=MIMAT0002822;Name=hsa-miR-512-1-5p;Derives_from=MI0003140
19 . miRNA 599982 600000 . + . ID=MIMAT0004978;Alias=MIMAT0004978;Name=hsa-miR-935;Derives_from=MI0005757
2 changes: 1 addition & 1 deletion scripts/tests/files/extreme_chr_primir_anno.gff3
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
19 . miRNA_primary_transcript 0 124 . + . ID=MI0003140;Alias=MI0003140;Name=hsa-mir-512-1_-2_+2
19 . miRNA_primary_transcript 1 122 . + . ID=MI0003140;Alias=MI0003140;Name=hsa-mir-512-1_-1_+0
19 . miRNA_primary_transcript 515667 600000 . + . ID=MI0005757;Alias=MI0005757;Name=hsa-mir-935_-0_+3
6 changes: 3 additions & 3 deletions scripts/tests/files/extreme_mir_anno.gff3
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
19 . miRNA 6 80 . + . ID=MIMAT0002822;Alias=MIMAT0002822;Name=hsa-miR-512-5p;Derives_from=MI0003140
19 . miRNA 83 124 . + . ID=MIMAT0002823;Alias=MIMAT0002823;Name=hsa-miR-512-3p;Derives_from=MI0003140
19 . miRNA 315716 315757 . + . ID=MIMAT0004978;Alias=MIMAT0004978;Name=hsa-miR-935;Derives_from=MI0005757
19 . miRNA 10 76 . + . ID=MIMAT0002822;Alias=MIMAT0002822;Name=hsa-miR-512-1-5p;Derives_from=MI0003140
19 . miRNA 87 120 . + . ID=MIMAT0002823;Alias=MIMAT0002823;Name=hsa-miR-512-1-3p;Derives_from=MI0003140
19 . miRNA 315720 315756 . + . ID=MIMAT0004978;Alias=MIMAT0004978;Name=hsa-miR-935;Derives_from=MI0005757
2 changes: 1 addition & 1 deletion scripts/tests/files/extreme_primir_anno.gff3
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
19 . miRNA_primary_transcript 6 124 . + . ID=MI0003140;Alias=MI0003140;Name=hsa-mir-512-1_-3_+2
19 . miRNA_primary_transcript 9 122 . + . ID=MI0003140;Alias=MI0003140;Name=hsa-mir-512-1_-0_+0
19 . miRNA_primary_transcript 315667 315757 . + . ID=MI0005757;Alias=MI0005757;Name=hsa-mir-935_-0_+0
3 changes: 3 additions & 0 deletions scripts/tests/files/in_illegal_mirna_anno.gff3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
19 . miRNA_primary_transcript 2 122 . + . ID=MI0003140;Alias=MI0003140;Name=hsa-mir-512-1
19 . miRNA 3 74 . + . ID=MIMAT0002822;Alias=MIMAT0002822;Name=hsa-miR-512-5p;Derives_from=MI0003140
19 . miRNA 0 24 . + . ID=MIMAT2002822;Alias=MIMAT2002822;Name=hsa-miR-512-3p;Derives_from=MI0003140
11 changes: 6 additions & 5 deletions scripts/tests/files/in_mirna_anno.gff3
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
19 . miRNA_primary_transcript 2517 2614 . + . ID=MI0003141;Alias=MI0003141;Name=hsa-mir-512-2
19 . miRNA 2536 2558 . + . ID=MIMAT0002822_1;Alias=MIMAT0002822;Name=hsa-miR-512-5p;Derives_from=MI0003141
19 . miRNA 2573 2594 . + . ID=MIMAT0002823_1;Alias=MIMAT0002823;Name=hsa-miR-512-3p;Derives_from=MI0003141
19 . miRNA_primary_transcript 5328 5400 . + . ID=MI0003786;Alias=MI0003786;Name=hsa-mir-1323
19 . miRNA 5338 5359 . + . ID=MIMAT0005795;Alias=MIMAT0005795;Name=hsa-miR-1323;Derives_from=MI0003786
19 . miRNA_primary_transcript 121035 121101 . + . ID=MI0000779;Alias=MI0000779;Name=hsa-mir-371a
19 . miRNA 121040 121059 . + . ID=MIMAT0004687;Alias=MIMAT0004687;Name=hsa-miR-371a-5p;Derives_from=MI0000779
19 . miRNA 121076 121098 . + . ID=MIMAT0000723;Alias=MIMAT0000723;Name=hsa-miR-371a-3p;Derives_from=MI0000779
19 . miRNA_primary_transcript 121037 121102 . - . ID=MI0017393;Alias=MI0017393;Name=hsa-mir-371b
19 . miRNA 121075 121096 . - . ID=MIMAT0019892;Alias=MIMAT0019892;Name=hsa-miR-371b-5p;Derives_from=MI0017393
19 . miRNA 121038 121060 . - . ID=MIMAT0019893;Alias=MIMAT0019893;Name=hsa-miR-371b-3p;Derives_from=MI0017393
3 changes: 1 addition & 2 deletions scripts/tests/files/in_mirna_extreme_chr_mirs.gff3
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
19 . miRNA_primary_transcript 2 122 . + . ID=MI0003140;Alias=MI0003140;Name=hsa-mir-512-1
19 . miRNA 3 74 . + . ID=MIMAT0002822;Alias=MIMAT0002822;Name=hsa-miR-512-5p;Derives_from=MI0003140
19 . miRNA 89 118 . + . ID=MIMAT0002823;Alias=MIMAT0002823;Name=hsa-miR-512-3p;Derives_from=MI0003140
19 . miRNA_primary_transcript 515667 599997 . + . ID=MI0005757;Alias=MI0005757;Name=hsa-mir-935
19 . miRNA 599988 599996 . + . ID=MIMAT0004978;Alias=MIMAT0004978;Name=hsa-miR-935;Derives_from=MI0005757
19 . miRNA 599988 599996 . + . ID=MIMAT0004978;Alias=MIMAT0004978;Name=hsa-miR-935;Derives_from=MI0005757
2 changes: 1 addition & 1 deletion scripts/tests/files/in_mirna_extreme_mirs.gff3
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
19 . miRNA 12 74 . + . ID=MIMAT0002822;Alias=MIMAT0002822;Name=hsa-miR-512-5p;Derives_from=MI0003140
19 . miRNA 89 118 . + . ID=MIMAT0002823;Alias=MIMAT0002823;Name=hsa-miR-512-3p;Derives_from=MI0003140
19 . miRNA_primary_transcript 315667 315757 . + . ID=MI0005757;Alias=MI0005757;Name=hsa-mir-935
19 . miRNA 315722 315754 . + . ID=MIMAT0004978;Alias=MIMAT0004978;Name=hsa-miR-935;Derives_from=MI0005757
19 . miRNA 315722 315754 . + . ID=MIMAT0004978;Alias=MIMAT0004978;Name=hsa-miR-935;Derives_from=MI0005757
18 changes: 18 additions & 0 deletions scripts/tests/files/in_replica_mirna_anno.gff3
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
3 . miRNA_primary_transcript 160404745 160404825 . + . ID=MI0000115;Alias=MI0000115;Name=hsa-mir-16-2
3 . miRNA 160404754 160404775 . + . ID=MIMAT0000069_1;Alias=MIMAT0000069;Name=hsa-miR-16-5p;Derives_from=MI0000115
3 . miRNA 160404797 160404818 . + . ID=MIMAT0004518;Alias=MIMAT0004518;Name=hsa-miR-16-2-3p;Derives_from=MI0000115
13 . miRNA_primary_transcript 50048973 50049061 . - . ID=MI0000070;Alias=MI0000070;Name=hsa-mir-16-1
13 . miRNA 50049027 50049048 . - . ID=MIMAT0000069;Alias=MIMAT0000069;Name=hsa-miR-16-5p;Derives_from=MI0000070
13 . miRNA 50048985 50049006 . - . ID=MIMAT0004489;Alias=MIMAT0004489;Name=hsa-miR-16-1-3p;Derives_from=MI0000070
20 . miRNA_primary_transcript 63919449 63919520 . + . ID=MI0005763;Alias=MI0005763;Name=hsa-mir-941-1
20 . miRNA 63919495 63919517 . + . ID=MIMAT0004984;Alias=MIMAT0004984;Name=hsa-miR-941;Derives_from=MI0005763
20 . miRNA_primary_transcript 63919505 63919576 . + . ID=MI0005764;Alias=MI0005764;Name=hsa-mir-941-2
20 . miRNA 63919551 63919573 . + . ID=MIMAT0004984_1;Alias=MIMAT0004984;Name=hsa-miR-941;Derives_from=MI0005764
20 . miRNA_primary_transcript 63919561 63919632 . + . ID=MI0005765;Alias=MI0005765;Name=hsa-mir-941-3
20 . miRNA 63919607 63919629 . + . ID=MIMAT0004984_2;Alias=MIMAT0004984;Name=hsa-miR-941;Derives_from=MI0005765
21 . miRNA_primary_transcript 8206563 8206618 . + . ID=MI0033425;Alias=MI0033425;Name=hsa-mir-10401
21 . miRNA 8206563 8206582 . + . ID=MIMAT0041633;Alias=MIMAT0041633;Name=hsa-miR-10401-5p;Derives_from=MI0033425
21 . miRNA 8206598 8206618 . + . ID=MIMAT0041634;Alias=MIMAT0041634;Name=hsa-miR-10401-3p;Derives_from=MI0033425
21 . miRNA_primary_transcript 8250772 8250827 . + . ID=MI0033425_2;Alias=MI0033425;Name=hsa-mir-10401
21 . miRNA 8250772 8250791 . + . ID=MIMAT0041633_1;Alias=MIMAT0041633;Name=hsa-miR-10401-5p;Derives_from=MI0033425
21 . miRNA 8250807 8250827 . + . ID=MIMAT0041634_1;Alias=MIMAT0041634;Name=hsa-miR-10401-3p;Derives_from=MI0033425
9 changes: 6 additions & 3 deletions scripts/tests/files/mir_anno.gff3
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
19 . miRNA 2530 2564 . + . ID=MIMAT0002822_1;Alias=MIMAT0002822;Name=hsa-miR-512-5p;Derives_from=MI0003141
19 . miRNA 2567 2600 . + . ID=MIMAT0002823_1;Alias=MIMAT0002823;Name=hsa-miR-512-3p;Derives_from=MI0003141
19 . miRNA 5332 5365 . + . ID=MIMAT0005795;Alias=MIMAT0005795;Name=hsa-miR-1323;Derives_from=MI0003786
19 . miRNA_primary_transcript 121034 121104 . + . ID=MI0000779;Alias=MI0000779;Name=hsa-mir-371a_-1_+3
19 . miRNA 121034 121065 . + . ID=MIMAT0004687;Alias=MIMAT0004687;Name=hsa-miR-371a-5p;Derives_from=MI0000779
19 . miRNA 121070 121104 . + . ID=MIMAT0000723;Alias=MIMAT0000723;Name=hsa-miR-371a-3p;Derives_from=MI0000779
19 . miRNA_primary_transcript 121032 121102 . - . ID=MI0017393;Alias=MI0017393;Name=hsa-mir-371b_-5_+0
19 . miRNA 121032 121066 . - . ID=MIMAT0019893;Alias=MIMAT0019893;Name=hsa-miR-371b-3p;Derives_from=MI0017393
19 . miRNA 121069 121102 . - . ID=MIMAT0019892;Alias=MIMAT0019892;Name=hsa-miR-371b-5p;Derives_from=MI0017393
2 changes: 0 additions & 2 deletions scripts/tests/files/primir_anno.gff3
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
19 . miRNA_primary_transcript 2517 2614 . + . ID=MI0003141;Alias=MI0003141;Name=hsa-mir-512-2_-0_+0
19 . miRNA_primary_transcript 5328 5400 . + . ID=MI0003786;Alias=MI0003786;Name=hsa-mir-1323_-0_+0
18 changes: 18 additions & 0 deletions scripts/tests/files/replica_mirna_anno.gff3
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
3 . miRNA_primary_transcript 160404745 160404825 . + . ID=MI0000115;Alias=MI0000115;Name=hsa-mir-16-2
3 . miRNA 160404754 160404775 . + . ID=MIMAT0000069_1;Alias=MIMAT0000069;Name=hsa-miR-16-2-5p;Derives_from=MI0000115
3 . miRNA 160404797 160404818 . + . ID=MIMAT0004518;Alias=MIMAT0004518;Name=hsa-miR-16-2-3p;Derives_from=MI0000115
13 . miRNA_primary_transcript 50048973 50049061 . - . ID=MI0000070;Alias=MI0000070;Name=hsa-mir-16-1
13 . miRNA 50049027 50049048 . - . ID=MIMAT0000069;Alias=MIMAT0000069;Name=hsa-miR-16-1-5p;Derives_from=MI0000070
13 . miRNA 50048985 50049006 . - . ID=MIMAT0004489;Alias=MIMAT0004489;Name=hsa-miR-16-1-3p;Derives_from=MI0000070
20 . miRNA_primary_transcript 63919449 63919520 . + . ID=MI0005763;Alias=MI0005763;Name=hsa-mir-941-1
20 . miRNA 63919495 63919517 . + . ID=MIMAT0004984;Alias=MIMAT0004984;Name=hsa-miR-941-1;Derives_from=MI0005763
20 . miRNA_primary_transcript 63919505 63919576 . + . ID=MI0005764;Alias=MI0005764;Name=hsa-mir-941-2
20 . miRNA 63919551 63919573 . + . ID=MIMAT0004984_1;Alias=MIMAT0004984;Name=hsa-miR-941-2;Derives_from=MI0005764
20 . miRNA_primary_transcript 63919561 63919632 . + . ID=MI0005765;Alias=MI0005765;Name=hsa-mir-941-3
20 . miRNA 63919607 63919629 . + . ID=MIMAT0004984_2;Alias=MIMAT0004984;Name=hsa-miR-941-3;Derives_from=MI0005765
21 . miRNA_primary_transcript 8206563 8206618 . + . ID=MI0033425;Alias=MI0033425;Name=hsa-mir-10401
21 . miRNA 8206563 8206582 . + . ID=MIMAT0041633;Alias=MIMAT0041633;Name=hsa-miR-10401-5p;Derives_from=MI0033425
21 . miRNA 8206598 8206618 . + . ID=MIMAT0041634;Alias=MIMAT0041634;Name=hsa-miR-10401-3p;Derives_from=MI0033425
21 . miRNA_primary_transcript 8250772 8250827 . + . ID=MI0033425_2;Alias=MI0033425;Name=hsa-mir-10401-2
21 . miRNA 8250772 8250791 . + . ID=MIMAT0041633_1;Alias=MIMAT0041633;Name=hsa-miR-10401-2-5p;Derives_from=MI0033425
21 . miRNA 8250807 8250827 . + . ID=MIMAT0041634_1;Alias=MIMAT0041634;Name=hsa-miR-10401-2-3p;Derives_from=MI0033425
Loading

0 comments on commit bcaba31

Please sign in to comment.