Two Plus Two Publishing LLC Two Plus Two Publishing LLC
 

Go Back   Two Plus Two Poker Forums > Other Topics > Programming

Notices

Programming Discussions about computer programming

Reply
 
Thread Tools Display Modes
Old 07-03-2012, 08:14 PM   #1
Pooh-Bah
 
il_martilo's Avatar
 
Join Date: Nov 2007
Posts: 4,055
Adding a Delimiter

Hi all,

I'm trying to import a large amount of numerical data (representing DNA sequences) into either R or Matlab. It is currently saved as a txt file. The issue I'm running into is there is currently nothing separating data values right now.

Ex the data looks like; 1413213421423434144234142

and I need it to look like; 1 4 1 3 2 1 3 4 2 1 4 2 3 4 or as a CSV.

I'm really bad with word, is there a way to have it insert a comma or white space? Right now R is getting confused and thinks the value for the first entry in each row is simply infinity and the custom delimiter in R assumes that "" means that there is a single space.

Thanks!
il_martilo is offline   Reply With Quote
Old 07-03-2012, 08:49 PM   #2
grinder
 
iosys's Avatar
 
Join Date: Sep 2011
Location: United States Posts: 9999999
Posts: 531
Re: Adding a Delimiter

I would suggest using recursion to add the spaces.
I'm sure whatever language you are good at there is some tutorials to do what you need.
iosys is offline   Reply With Quote
Old 07-03-2012, 09:04 PM   #3
Carpal \'Tunnel
 
jukofyork's Avatar
 
Join Date: Sep 2004
Posts: 10,213
Re: Adding a Delimiter

If your whole file is just made up of those 4 characters (which I guess is likely if it's DNA) then you could just do a search and replace "1" to "1 ", "2" to "2 ", etc. You'd end up with an extra space at the end of the line but that prolly will still parse OK.

Juk
jukofyork is offline   Reply With Quote
Old 07-04-2012, 02:54 PM   #4
adept
 
Join Date: Apr 2011
Posts: 812
Re: Adding a Delimiter

Word doesn't work very well on large files (do you mean many terabytes?).

But if the file fits in word it's very easy.

Search for: <Any Character>

Replace With: <Find What Text><space>

<space> is the space character on your keyboard.

<Any Character> is found on the Special section of the Find And Replace menu. Type control-h to bring up the Find and Replace menu.

<Find What Text> is also on the Special menu.

Hope this helps.
au4all is offline   Reply With Quote
Old 07-06-2012, 04:38 AM   #5
veteran
 
Join Date: Jul 2004
Posts: 2,165
Never used R but you should be able to read this file directly into matlab without the modification. dlmread should do the trick
Neuge is offline   Reply With Quote
Old 07-07-2012, 12:58 AM   #6
Pooh-Bah
 
jmark's Avatar
 
Join Date: Dec 2003
Location: US
Posts: 3,612
Re: Adding a Delimiter

I suggested reading them in as characters in your other thread.
jmark is offline   Reply With Quote
Old 07-07-2012, 04:32 PM   #7
Pooh-Bah
 
Join Date: Apr 2005
Posts: 5,832
Re: Adding a Delimiter

If you have python installed you can type this into your terminal on a mac or linux machine.

Code:
$ cat YOUR_FILE | python -c "import sys; print ' '.join(sys.stdin.read().strip())" > OUTPUT_FILE
Example:

Code:
$ echo "1413213421423434144234142" | python -c "import sys; print ' '.join(sys.stdin.read().strip())"
1 4 1 3 2 1 3 4 2 1 4 2 3 4 3 4 1 4 4 2 3 4 1 4 2
pokergrader is offline   Reply With Quote

Reply
      

Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -4. The time now is 08:22 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.
Copyright © 2008-2010, Two Plus Two Interactive