![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
need help in R programming | abh | Introductions | 0 | 08-08-2012 09:54 AM |
How to fetch any older version ACCs from NCBI using programming language? | Brace | Bioinformatics | 5 | 06-20-2012 07:38 PM |
Computer Language Benchmarks Game | gringer | Bioinformatics | 0 | 12-12-2011 02:29 PM |
C programming question | arkal | Bioinformatics | 1 | 10-24-2011 10:48 PM |
![]() |
|
Thread Tools |
![]() |
#1 |
Member
Location: Ahmedabad Join Date: Dec 2013
Posts: 18
|
![]()
Dear Friends,
I am newbie in Biology field, I dont know how to use progrmming language. My query is I have one file which I want to convert in simple file which should be without white space, line breaker and without any space, e.g I have attached my file with this query. I need some script or some command. Thank you for viewing replying in advance, Have great day ahead |
![]() |
![]() |
![]() |
#2 |
Member
Location: Turkey Join Date: Apr 2013
Posts: 18
|
![]()
you can use string replace in python
|
![]() |
![]() |
![]() |
#3 |
Member
Location: Ahmedabad Join Date: Dec 2013
Posts: 18
|
![]() |
![]() |
![]() |
![]() |
#4 |
Registered Vendor
Location: Eugene, OR Join Date: May 2013
Posts: 438
|
![]()
at a unix command line:
awk '/^>/ {printf("\n%s\n",$0);next; } { printf("%s",$0);} END {printf("\n");}' < test.txt
__________________
Providing nextRAD genotyping and PacBio sequencing services. http://snpsaurus.com |
![]() |
![]() |
![]() |
#5 | |
Member
Location: Ahmedabad Join Date: Dec 2013
Posts: 18
|
![]() Quote:
Thanks again for your help. |
|
![]() |
![]() |
![]() |
#6 |
Member
Location: Turkey Join Date: Apr 2013
Posts: 18
|
![]()
make eol_format.py executable with chmod a+x eol_format.py
run as: python eol_format.py test.txt (put a space after .py and write file path/name) this will write you a file with test.txt.edit.txt. Code is pretty straightforward, you can read what it does and change by checking syntax by googling. |
![]() |
![]() |
![]() |
#7 |
Member
Location: Germany Join Date: May 2014
Posts: 23
|
![]()
omerfaruk's script works though it doesn't really show the beauty of the python language, so here is a more elegant version of it:
import sys with open(sys.argv[1], 'r') as infile: with open(sys.argv[2], 'w') as outfile: for line in infile: if line[0] != '>': line = line.strip() outfile.write(line) copy this exactly as it is formatted to a text editor, save it under whatevername.py, then from the command line run it like this: python nameofscript input_file output_file Recommendation: if you consider learning one programming language, choose python. Cheers, Wolfgang |
![]() |
![]() |
![]() |
#8 |
Member
Location: Germany Join Date: May 2014
Posts: 23
|
![]()
great, this forum removes significant whitespace
![]() so here's the script again as an attachment with correct formatting. |
![]() |
![]() |
![]() |
#9 |
Member
Location: Ahmedabad Join Date: Dec 2013
Posts: 18
|
![]()
Tons of thank you omerfaruk and wolma. It really helped me. I did know about python much but now I would like to learn because of beauty of python, thanks again wolma and omerfaruk.
Have great time ahead, |
![]() |
![]() |
![]() |
#10 |
Devon Ryan
Location: Freiburg, Germany Join Date: Jul 2011
Posts: 3,478
|
![]()
@wolma: You need to just use the "code" tags:
Code:
import sys with open(sys.argv[1], 'r') as infile: with open(sys.argv[2], 'w') as outfile: for line in infile: if line[0] != '>': line = line.strip() outfile.write(line) |
![]() |
![]() |
![]() |
#11 |
Super Moderator
Location: Walnut Creek, CA Join Date: Jan 2014
Posts: 2,707
|
![]() |
![]() |
![]() |
![]() |
#12 |
Member
Location: Germany Join Date: May 2014
Posts: 23
|
![]()
@dpryan: Thanks for the hint (should have read the FAQ before complaining) !
I'll give it a try with a slightly enhanced version of my previous suggestion. This one will work correctly with multisequence fasta files (my first version would not put a line break between the end of the previous sequence and a new title line): Code:
import sys record_sep = '' with open(sys.argv[1], 'r') as infile: with open(sys.argv[2], 'w') as outfile: for line in infile: if line[0] == '>': outfile.write(record_sep) record_sep = '\n' else: line = line.strip() outfile.write(line) |
![]() |
![]() |
![]() |
#13 |
Rick Westerman
Location: Purdue University, Indiana, USA Join Date: Jun 2008
Posts: 1,104
|
![]() |
![]() |
![]() |
![]() |
Thread Tools | |
|
|