[2] | 1 | #!/usr/bin/env python |
---|
| 2 | # This code exists in 2 places: ~/datatypes/converters and ~/tools/fasta_tools |
---|
| 3 | """ |
---|
| 4 | Input: fasta, int |
---|
| 5 | Output: tabular |
---|
| 6 | format convert: fasta to tabular |
---|
| 7 | """ |
---|
| 8 | |
---|
| 9 | import sys, os |
---|
| 10 | |
---|
| 11 | def __main__(): |
---|
| 12 | infile = sys.argv[1] |
---|
| 13 | outfile = sys.argv[2] |
---|
| 14 | keep_first = int( sys.argv[3] ) |
---|
| 15 | fasta_title = fasta_seq = '' |
---|
| 16 | if keep_first == 0: |
---|
| 17 | keep_first = None |
---|
| 18 | else: |
---|
| 19 | keep_first += 1 |
---|
| 20 | out = open( outfile, 'w' ) |
---|
| 21 | for i, line in enumerate( open( infile ) ): |
---|
| 22 | line = line.rstrip( '\r\n' ) |
---|
| 23 | if not line or line.startswith( '#' ): |
---|
| 24 | continue |
---|
| 25 | if line.startswith( '>' ): |
---|
| 26 | if i > 0: |
---|
| 27 | out.write('\n') |
---|
| 28 | out.write(line[1:keep_first]) |
---|
| 29 | out.write('\t') |
---|
| 30 | else: |
---|
| 31 | out.write(line) |
---|
| 32 | if i > 0: |
---|
| 33 | out.write('\n') |
---|
| 34 | out.close() |
---|
| 35 | |
---|
| 36 | if __name__ == "__main__" : __main__() |
---|
| 37 | |
---|