Skip to content

Commit

Permalink
Create Csv_to_fasta.py
Browse files Browse the repository at this point in the history
  • Loading branch information
bartosz-kozak authored Jun 26, 2017
1 parent 19a5926 commit 86927db
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions python/Csv_to_fasta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/python2.7
# coding: utf-8

# Simple script to convert csv file to fasta fromat

# import librarys
import pandas as pd
import sys
import os.path

# create file name for fasta file
filename = sys.argv[-1]
outname = filename.split('.')
outname1 = '.'.join([outname[0], 'fasta'])

# read data (csv file)
df = pd.read_csv(filename, header=None)
df.columns = ['id', 'seq']

# create fasta file
fh = open(outname1, 'w')

# function for conversion to fasta format
for i in range(0,len(df)):
n = df.at[i,'id']
seq = df.at[i, 'seq']
fh.write(">%s\n" % n)
fh.write("%s\n" % seq)
fh.close()

0 comments on commit 86927db

Please sign in to comment.