Generates GTF from a GTF path.
(path: str)
| 64 | |
| 65 | |
| 66 | def generate_gtf(path: str) -> pd.DataFrame: |
| 67 | """Generates GTF from a GTF path.""" |
| 68 | url = parse.urlparse(path) |
| 69 | if all([url.scheme, url.netloc]): |
| 70 | with tempfile.TemporaryDirectory() as d: |
| 71 | path, _ = request.urlretrieve( |
| 72 | path, |
| 73 | filename=os.path.join(d, os.path.basename(path)), |
| 74 | ) |
| 75 | logging.info('Downloaded GTF to %s', path) |
| 76 | gtf = pyranges.read_gtf(path, as_df=True, duplicate_attr=True) |
| 77 | else: |
| 78 | gtf = pyranges.read_gtf(path, as_df=True, duplicate_attr=True) |
| 79 | |
| 80 | gtf['gene_id_nopatch'] = gtf['gene_id'].str.split('.', expand=True)[0] |
| 81 | return gtf |
| 82 | |
| 83 | |
| 84 | def main(_) -> None: |