SEQanswers

Go Back   SEQanswers > Bioinformatics > Bioinformatics



Similar Threads
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

Reply
 
Thread Tools
Old 05-29-2014, 08:15 PM   #1
Desai
Member
 
Location: Ahmedabad

Join Date: Dec 2013
Posts: 18
Default Programming Language

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
Attached Files
File Type: txt test.txt (1.6 KB, 22 views)
Desai is offline   Reply With Quote
Old 05-29-2014, 09:31 PM   #2
omerfaruk
Member
 
Location: Turkey

Join Date: Apr 2013
Posts: 18
Default

you can use string replace in python
omerfaruk is offline   Reply With Quote
Old 05-29-2014, 09:54 PM   #3
Desai
Member
 
Location: Ahmedabad

Join Date: Dec 2013
Posts: 18
Default

Quote:
Originally Posted by omerfaruk View Post
you can use string replace in python
Hey, thanks for your help but as I said I dont know how to use python. Could you do it for me? Thank you for giving your time?
Desai is offline   Reply With Quote
Old 05-29-2014, 10:05 PM   #4
SNPsaurus
Registered Vendor
 
Location: Eugene, OR

Join Date: May 2013
Posts: 451
Default

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
SNPsaurus is offline   Reply With Quote
Old 05-29-2014, 11:08 PM   #5
Desai
Member
 
Location: Ahmedabad

Join Date: Dec 2013
Posts: 18
Default

Quote:
Originally Posted by SNPsaurus View Post
at a unix command line:
awk '/^>/ {printf("\n%s\n",$0);next; } { printf("%s",$0);} END {printf("\n");}' < test.txt
Hey friend Thank you for reply. However still it dosent working for me, the script which you had send that was just for the that test.txt file not working with my original problem file . I am here attaching second file which is exact format that I want. Please help me, Its very urgent. I have to analysis thousands files so I can not waste time behind erasing every space.

Thanks again for your help.
Attached Files
File Type: txt test(2).txt (3.8 KB, 8 views)
Desai is offline   Reply With Quote
Old 05-29-2014, 11:30 PM   #6
omerfaruk
Member
 
Location: Turkey

Join Date: Apr 2013
Posts: 18
Default

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.
Attached Files
File Type: zip eol_format.py.zip (358 Bytes, 8 views)
omerfaruk is offline   Reply With Quote
Old 05-29-2014, 11:52 PM   #7
wolma
Member
 
Location: Germany

Join Date: May 2014
Posts: 23
Default

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
wolma is offline   Reply With Quote
Old 05-29-2014, 11:56 PM   #8
wolma
Member
 
Location: Germany

Join Date: May 2014
Posts: 23
Default Programming Language

great, this forum removes significant whitespace

so here's the script again as an attachment with correct formatting.
Attached Files
File Type: zip solution.py.zip (298 Bytes, 9 views)
wolma is offline   Reply With Quote
Old 05-30-2014, 01:10 AM   #9
Desai
Member
 
Location: Ahmedabad

Join Date: Dec 2013
Posts: 18
Default Thank you Reply

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,
Desai is offline   Reply With Quote
Old 05-30-2014, 06:56 AM   #10
dpryan
Devon Ryan
 
Location: Freiburg, Germany

Join Date: Jul 2011
Posts: 3,479
Default

@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)
dpryan is offline   Reply With Quote
Old 05-30-2014, 09:07 AM   #11
Brian Bushnell
Super Moderator
 
Location: Walnut Creek, CA

Join Date: Jan 2014
Posts: 2,707
Default

Quote:
Originally Posted by dpryan View Post
@wolma: You need to just use the "code" tags:
Or a language where indent level is not syntactically relevant *cough*

Just kidding, I think Python is a good choice in this case.
Brian Bushnell is offline   Reply With Quote
Old 05-30-2014, 12:29 PM   #12
wolma
Member
 
Location: Germany

Join Date: May 2014
Posts: 23
Default

@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)
wolma is offline   Reply With Quote
Old 06-02-2014, 09:44 AM   #13
westerman
Rick Westerman
 
Location: Purdue University, Indiana, USA

Join Date: Jun 2008
Posts: 1,104
Default

Quote:
Originally Posted by wolma View Post
great, this forum removes significant whitespace
Only if you consider whitespace to be significant. :-)
westerman is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off




All times are GMT -8. The time now is 11:23 AM.


Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Single Sign On provided by vBSSO