Created
March 18, 2016 18:57
-
-
Save rpetit3/ddb85be296cdf46361bc to your computer and use it in GitHub Desktop.
rename-fasta-header.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
""" | |
Prefix a set of FASTA (STDIN) headers with a given string. | |
Example run: zcat my_fasta.gz | ./rename-fasta-header.py headers.txt PREFIX | |
""" | |
from __future__ import print_function | |
if __name__ == '__main__': | |
import sys | |
import argparse as ap | |
parser = ap.ArgumentParser( | |
prog='fastq_cleanup', | |
conflict_handler='resolve', | |
description='Prefix a a set of FASTA headers with a given string.') | |
group1 = parser.add_argument_group('Options', '') | |
group1.add_argument('header', metavar="LIST_FILE", type=str, | |
help='A list of headers to search for and prefix.') | |
group1.add_argument('prefix', metavar="STR", type=str, | |
help='A string to prefix the fasta headers with.') | |
args = parser.parse_args() | |
headers = {} | |
with open(args.header, 'r') as fh: | |
for line in fh: | |
line = '>{0}'.format(line) | |
headers[line] = True | |
for line in sys.stdin: | |
if line in headers: | |
line = line.replace('>', '>{0}-'.format(args.prefix)) | |
print(line, end="") |
Hi @gitanjali0806, you will need to make sure your headers.txt file matches headers in the FASTA file exactly.
Thanks for your message
Will try and update
…On Wed, 21 Feb 2024, 17:22 Robert A. Petit III, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Hi @gitanjali0806 <https://github.com/gitanjali0806>, you will need to
make sure your headers.txt file matches headers in the FASTA file exactly.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/rpetit3/ddb85be296cdf46361bc#gistcomment-4923108>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQ4FNBOEGIMJB4RJF2R65MTYUXNWLBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZTEOJUGU3TEOFHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Hi @gitanjali0806, you will need to make sure your headers.txt file matches headers in the FASTA file exactly.
I have checked the name in the header file it matches exactly with the fasta file..
i want to replace ">TCONS_00000001 gene=JAJFZO010000001.1_gene_1" with "JAJFZO010000001.1"
Ah, this likely will not be possible with this script, as it doesn't replace anything only adds. So, if the prefix were "MYFASTA", ">TCONS_00000001 gene=JAJFZO010000001.1_gene_1" would become ">MAYFASTA-TCONS_00000001 gene=JAJFZO010000001.1_gene_1"
I wonder if you could just get away with using something like sed
Thanks for the guidance will try by sed
…On Fri, 23 Feb 2024, 00:03 Robert A. Petit III, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Ah, this likely will not be possible with this script, as it doesn't
replace anything only adds. So, if the prefix were "MYFASTA",
">TCONS_00000001 gene=JAJFZO010000001.1_gene_1" would become
">MAYFASTA-TCONS_00000001 gene=JAJFZO010000001.1_gene_1"
I wonder if you could just get away with using something like sed
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/rpetit3/ddb85be296cdf46361bc#gistcomment-4928598>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQ4FNBMRXWXBNMAFLYI5IZTYU6FQ7BFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVAZTEOJUGU3TEOFHORZGSZ3HMVZKMY3SMVQXIZI>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is not working