Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Sign in to follow this  
MrKickkiller

Bash: Looking for a way to merge 4 lines into one line.

Recommended Posts

Posted · Original PosterOP

Hi

 

I'm looking for a (simple) way to merge 4 lines in 4 seperate files into one.

 

The lines would look like

  • A---A-A-----A
  • -T-------------
  • --C--C---C---
  • ---G-----------

These are (supposedly) results of dna probing tests.(Yea I know I mismatched some lines, deal with it  :P )

I would like the result to be something like:

ATCGACACA

 

 

 


That time I saved Linus' WiFi pass from appearing on YouTube: 

A sudden Linus re-appears : http://linustechtips.com/main/topic/390793-important-dailymotion-account-still-active/

Link to post
Share on other sites

Hi

 

I'm looking for a (simple) way to merge 4 lines in 4 seperate files into one.

 

The lines would look like

  • A---A-A-----A
  • -T-------------
  • --C--C---C---
  • ---G-----------

These are (supposedly) results of dna probing tests.(Yea I know I mismatched some lines, deal with it  :P )

I would like the result to be something like:

ATCGACACA

http://www.grymoire.com/Unix/Sed.html

sed 's/\-//g' dna.txt  | tr '\n' ' ' | sed 's/\s//g'
Link to post
Share on other sites
Posted · Original PosterOP

 

http://www.grymoire.com/Unix/Sed.html

sed 's/\-//g' dna.txt  | tr '\n' ' ' | sed 's/\s//g'

 

Well I've been think about your suggestion and wouldn't that just give me Line1WithoutDashesLine2WithoutDashesLine3WithoutDashes   

I need to like combine those 4 lines together, not append them and then remove the dashes.

The "rules" are :

  • Only 1 base is possible in each and every slot of the sequence: So there is not possibility of having like A on the first character and C on the first character.
  • There are no empty (no bases) spots in the sequence.

Hope this made somewhat sense?


That time I saved Linus' WiFi pass from appearing on YouTube: 

A sudden Linus re-appears : http://linustechtips.com/main/topic/390793-important-dailymotion-account-still-active/

Link to post
Share on other sites

how about that?

for (int i=0, i<sequence.length, i++){  if (line1[i] != '-'){    newline=newline+line1[i];  }  else if (line2[i] != '-'){    newline=newline+line2[i];  }  else if (line3[i] != '-'){    newline=newline+line3[i];  }  else {    newline=newline+line4[i];  }}

in case you have a varying number of subsequences you can use a second for loop to cycle through them. ;)

 

EDIT: sorry for the java fu, just saw you are looking for a shell script. hope you can interpret it :ph34r:


Personal Build Project "Rained-On"

helped building up the CPU Overclocking Database and GPU Overclocking Database, check them out ;)

#KilledMyWife #MakeBombs #LinusIsNotFunny || Please, dont use non-default grey font colors. Think about the night-theme users! ;)

Link to post
Share on other sites

Well I've been think about your suggestion and wouldn't that just give me Line1WithoutDashesLine2WithoutDashesLine3WithoutDashes   

I need to like combine those 4 lines together, not append them and then remove the dashes.

The "rules" are :

  • Only 1 base is possible in each and every slot of the sequence: So there is not possibility of having like A on the first character and C on the first character.
  • There are no empty (no bases) spots in the sequence.

Hope this made somewhat sense?

Oh, I see what you mean. I will write a script when I get home soon.

Link to post
Share on other sites
Posted · Original PosterOP

how about that?

for (int i=0, i<sequence.length, i++){  if (line1[i] != '-'){    newline=newline+line1[i];  }  else if (line2[i] != '-'){    newline=newline+line2[i];  }  else if (line3[i] != '-'){    newline=newline+line3[i];  }  else {    newline=newline+line4[i];  }}

in case you have a varying number of subsequences you can use a second for loop to cycle through them. ;)

 

EDIT: sorry for the java fu, just saw you are looking for a shell script. hope you can interpret it :ph34r:

 

Yea, I understand your suggestion; And i could totally make it work in bash, but the professor is asking for a command, not a script, so yeah :/


That time I saved Linus' WiFi pass from appearing on YouTube: 

A sudden Linus re-appears : http://linustechtips.com/main/topic/390793-important-dailymotion-account-still-active/

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


×