Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
bartosz-kozak authored Jun 26, 2017
1 parent 67ebf3a commit f6fbc3d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
29 changes: 29 additions & 0 deletions 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()
35 changes: 35 additions & 0 deletions Fasta_to_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!usr/bin/python2.7
# coding: utf-8

# simple script to convert fasta file to csv file

# imports librarys
import sys
import os.path

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

# open fasta file
f=open(filename, "r")

# list fasta file
l=list(f)
# create csv file
fh=open(outname1, "w")

# function converting fasta to csv
for i in range(0, len(l)):
p_zn = list(l[i])[0]
if p_zn == ">":
k = ''.join(list(l[i]))[1:-1]
print k
fh.write("%s," % k)
else:
k = ''.join(list(l[i]))
#print k
fh.write("%s" % k)
fh.close()
print 'done'

0 comments on commit f6fbc3d

Please sign in to comment.