Skip to content

Commit 7ccffa8

Browse files
authored
Merge pull request #86 from miRTop/patch_0.4.27
release 0.4.27
2 parents 6c29654 + 8aeb7a5 commit 7ccffa8

File tree

9 files changed

+441
-338
lines changed

9 files changed

+441
-338
lines changed

.github/workflows/ci-cd.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI
2+
3+
on: push
4+
5+
jobs:
6+
build:
7+
name: Build distribution 📦
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v4
12+
- name: Set up Python
13+
uses: actions/setup-python@v5
14+
with:
15+
python-version: "3.x"
16+
- name: Install pypa/build
17+
run: >-
18+
python3 -m
19+
pip install
20+
build
21+
--user
22+
- name: Build a binary wheel and a source tarball
23+
run: python3 -m build
24+
- name: Store the distribution packages
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: python-package-distributions
28+
path: dist/
29+
30+
publish-to-pypi:
31+
name: >-
32+
Publish Python 🐍 distribution 📦 to PyPI
33+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
34+
needs:
35+
- build
36+
runs-on: ubuntu-latest
37+
environment:
38+
name: pypi
39+
url: https://pypi.org/p/mirtop # Replace <package-name> with your PyPI project name
40+
permissions:
41+
id-token: write # IMPORTANT: mandatory for trusted publishing
42+
43+
steps:
44+
- name: Download all the dists
45+
uses: actions/download-artifact@v4
46+
with:
47+
name: python-package-distributions
48+
path: dist/
49+
- name: Publish distribution 📦 to PyPI
50+
uses: pypa/gh-action-pypi-publish@release/v1
51+
52+
github-release:
53+
name: >-
54+
Sign the Python 🐍 distribution 📦 with Sigstore
55+
and upload them to GitHub Release
56+
needs:
57+
- publish-to-pypi
58+
runs-on: ubuntu-latest
59+
60+
permissions:
61+
contents: write # IMPORTANT: mandatory for making GitHub Releases
62+
id-token: write # IMPORTANT: mandatory for sigstore
63+
64+
steps:
65+
- name: Download all the dists
66+
uses: actions/download-artifact@v4
67+
with:
68+
name: python-package-distributions
69+
path: dist/
70+
- name: Sign the dists with Sigstore
71+
uses: sigstore/[email protected]
72+
with:
73+
inputs: >-
74+
./dist/*.tar.gz
75+
./dist/*.whl
76+
- name: Create GitHub Release
77+
env:
78+
GITHUB_TOKEN: ${{ github.token }}
79+
run: >-
80+
gh release create
81+
'${{ github.ref_name }}'
82+
--repo '${{ github.repository }}'
83+
--notes ""
84+
- name: Upload artifact signatures to GitHub Release
85+
env:
86+
GITHUB_TOKEN: ${{ github.token }}
87+
# Upload to GitHub Release using the `gh` CLI.
88+
# `dist/` contains the built packages, and the
89+
# sigstore-produced signatures and certificates.
90+
run: >-
91+
gh release upload
92+
'${{ github.ref_name }}' dist/**
93+
--repo '${{ github.repository }}'
94+

HISTORY.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
0.4.27
2+
3+
* fix random order in Variant field [#84](https://github.com/miRTop/mirtop/issues/83)
4+
* fix possible duplication of lines [#80](https://github.com/miRTop/mirtop/issues/80)
5+
* accept prefix for gff output [#84](https://github.com/miRTop/mirtop/issues/84)
6+
17
0.4.26
28

39
* Support spaces and special characters in bam files

mirtop/gff/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def reader(args):
6868
if args.low_memory:
6969
return None
7070
merged = merge.merge(out_dts, samples)
71-
fn_merged_out = op.join(args.out, "mirtop.%s" % args.out_format)
71+
fn_merged_out = op.join(args.out, "%s.%s" % (args.prefix, args.out_format))
7272
_write(merged, header.create(samples, database, header.make_tools([args.format])), fn_merged_out, args)
7373

7474

mirtop/gff/convert.py

+51-50
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import print_function
44

55
import os.path as op
6+
import pandas as pd
67

78
from mirtop.mirna import fasta, mapper
89
from mirtop.mirna.realign import read_id
@@ -25,69 +26,69 @@ def convert_gff_counts(args):
2526
UID miRNA Variant Sample1 Sample2 ... Sample N
2627
"""
2728
sep = "\t"
28-
variant_header = sep.join(['iso_5p', 'iso_3p',
29-
'iso_add3p', 'iso_snp'])
29+
variant_header = ['iso_5p', 'iso_3p',
30+
'iso_add3p', 'iso_snp']
3031
if args.add_extra:
3132
precursors = fasta.read_precursor(args.hairpin, args.sps)
3233
matures = mapper.read_gtf_to_precursor(args.gtf)
33-
variant_header = sep.join([variant_header,
34-
'iso_5p_nt', 'iso_3p_nt',
35-
'iso_add3p_nt', 'iso_snp_nt'])
34+
variant_header = variant_header + ['iso_5p_nt', 'iso_3p_nt', 'iso_add3p_nt', 'iso_snp_nt']
3635

3736
logger.info("INFO Reading GFF file %s", args.gff)
3837
logger.info("INFO Writing TSV file to directory %s", args.out)
3938

4039
gff_file = open(args.gff, 'r')
4140
out_file = op.join(args.out, "%s.tsv" % op.splitext(op.basename(args.gff))[0])
41+
all_lines = []
4242
missing_parent = 0
4343
missing_mirna = 0
4444
unvalid_uid = 0
45-
with open(out_file, 'w') as outh:
46-
47-
for samples_line in gff_file:
48-
if samples_line.startswith("## COLDATA:"):
49-
samples = sep.join(samples_line.strip().split("COLDATA:")[1].strip().split(","))
50-
header = sep.join(['UID', 'Read', 'miRNA', 'Variant',
51-
variant_header, samples])
52-
print(header, file=outh)
53-
break
54-
55-
for mirna_line in gff_file:
56-
gff = feature(mirna_line)
57-
attr = gff.attributes
58-
UID = attr["UID"]
59-
Read = attr["Read"]
60-
mirna = attr["Name"]
61-
parent = attr["Parent"]
62-
variant = attr["Variant"]
63-
try:
64-
read_id(UID)
65-
except KeyError:
66-
unvalid_uid += 1
45+
#with open(out_file, 'w') as outh:
46+
47+
for samples_line in gff_file:
48+
if samples_line.startswith("## COLDATA:"):
49+
samples = [sep.join(samples_line.strip().split("COLDATA:")[1].strip().split(","))]
50+
#header = sep.join(['UID', 'Read', 'miRNA', 'Variant',
51+
# variant_header, samples])
52+
#print(header, file=outh)
53+
break
54+
55+
for mirna_line in gff_file:
56+
gff = feature(mirna_line)
57+
attr = gff.attributes
58+
UID = attr["UID"]
59+
Read = attr["Read"]
60+
mirna = attr["Name"]
61+
parent = attr["Parent"]
62+
variant = attr["Variant"]
63+
try:
64+
read_id(UID)
65+
except KeyError:
66+
unvalid_uid += 1
67+
continue
68+
69+
expression = [sep.join(attr["Expression"].strip().split(","))]
70+
cols_variants = _expand(variant)
71+
logger.debug("COUNTS::Read:%s" % Read)
72+
logger.debug("COUNTS::EXTRA:%s" % variant)
73+
if args.add_extra:
74+
if parent not in precursors:
75+
missing_parent += 1
6776
continue
68-
69-
expression = sep.join(attr["Expression"].strip().split(","))
70-
cols_variants = sep.join(_expand(variant))
71-
logger.debug("COUNTS::Read:%s" % Read)
72-
logger.debug("COUNTS::EXTRA:%s" % variant)
73-
if args.add_extra:
74-
if parent not in precursors:
75-
missing_parent += 1
76-
continue
77-
if mirna not in matures[parent]:
78-
missing_mirna += 1
79-
continue
80-
extra = variant_with_nt(mirna_line, precursors, matures)
81-
if extra == "Invalid":
82-
continue
83-
logger.debug("COUNTS::EXTRA:%s" % extra)
84-
cols_variants = sep.join([cols_variants] + _expand(extra, True))
85-
summary = sep.join([UID, Read, mirna, variant,
86-
cols_variants, expression])
87-
logger.debug(summary)
88-
print(summary, file=outh)
89-
90-
gff_file.close()
77+
if mirna not in matures[parent]:
78+
missing_mirna += 1
79+
continue
80+
extra = variant_with_nt(mirna_line, precursors, matures)
81+
if extra == "Invalid":
82+
continue
83+
logger.debug("COUNTS::EXTRA:%s" % extra)
84+
cols_variants = cols_variants + _expand(extra, True)
85+
summary = [UID, Read, mirna, variant] + cols_variants + expression
86+
logger.debug(summary)
87+
all_lines.append(summary)
88+
#import pdb; pdb.set_trace()
89+
df = pd.DataFrame(all_lines, columns = ['UID', 'Read', 'miRNA', 'Variant'] + variant_header + samples)
90+
df = df.drop_duplicates()
91+
df.to_csv(out_file, sep="\t", index=False)
9192
logger.info("Missing Parents in hairpin file: %s" % missing_parent)
9293
logger.info("Missing MiRNAs in GFF file: %s" % missing_mirna)
9394
logger.info("Non valid UID: %s" % unvalid_uid)

mirtop/gff/stats.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ def _add_missing(df):
107107
# ref_miRNA_mean
108108
category = "ref_miRNA_mean"
109109
if sum(df['category']==category) == 0:
110-
df2 = {'category': category, 'sample': df['sample'].iat[0], 'counts': 0}
111-
df = df.append(df2, ignore_index = True)
110+
df2 = pd.DataFrame({'category': category, 'sample': df['sample'].iat[0], 'counts': 0}, index=[0])
111+
df = pd.concat([df, df2], ignore_index = True)
112112

113113
category = "isomiR_sum"
114114
if sum(df['category']==category) == 0:
115-
df2 = {'category': category, 'sample': df['sample'].iat[0], 'counts': 0}
116-
df = df.append(df2, ignore_index = True)
115+
df2 = pd.DataFrame({'category': category, 'sample': df['sample'].iat[0], 'counts': 0}, index=[0])
116+
df = pd.concat([df, df2], ignore_index = True)
117117

118118
return df
119119

mirtop/libs/parse.py

+2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def _add_subparser_gff(subparsers):
8282
parser.add_argument("files", nargs="*", help="Bam files.")
8383
parser.add_argument("-o", "--out", dest="out", required=1,
8484
help="dir of output files")
85+
parser.add_argument("--prefix", dest="prefix", required=0,
86+
default="mirtop", help="prefix for output file")
8587
parser.add_argument("--sps",
8688
help="species")
8789
parser.add_argument("--keep-name", action="store_true",

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import os
44
from setuptools import setup, find_packages
55

6-
version = '0.4.26'
7-
6+
version = '0.4.27'
87
url = 'http://github.com/mirtop/mirtop'
98

109

0 commit comments

Comments
 (0)