From 86927dba56341abf890e018cfd789324408ddce6 Mon Sep 17 00:00:00 2001 From: bartosz-kozak Date: Mon, 26 Jun 2017 16:18:07 +0200 Subject: [PATCH] Create Csv_to_fasta.py --- python/Csv_to_fasta.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 python/Csv_to_fasta.py diff --git a/python/Csv_to_fasta.py b/python/Csv_to_fasta.py new file mode 100644 index 0000000..6e1ec38 --- /dev/null +++ b/python/Csv_to_fasta.py @@ -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()