Skip to main content
added 335 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
Map[{FromDigits @ #, {##2}} & @@@ # & @* StringSplit] @ StringSplit[l, "\n"]
{{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}}, 
  {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}},
  {121, {"gcagtataaa", "caataataaa"}}}}

Also

f = Normal[{#, DeleteCases[{##2}, ""]} & @@@ SemanticImportString[#]] &;
f /@ l
{{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}}, 
  {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}}, 
  {121, {"gcagtataaa", "caataataaa"}}}}

and

f2 = {FromDigits @ #, {##2}} & @@@ 
      Split[StringSplit @ #, Not @* StringMatchQ[NumberString] @* First] &;
f2 /@ l
 {{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}},
   {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}},
   {121, {"gcagtataaa", "caataataaa"}}}}
Map[{FromDigits @ #, {##2}} & @@@ # & @* StringSplit] @ StringSplit[l, "\n"]
{{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}}, 
  {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}},
  {121, {"gcagtataaa", "caataataaa"}}}}

Also

f = Normal[{#, DeleteCases[{##2}, ""]} & @@@ SemanticImportString[#]] &;
f /@ l
{{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}}, 
  {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}}, 
  {121, {"gcagtataaa", "caataataaa"}}}}
Map[{FromDigits @ #, {##2}} & @@@ # & @* StringSplit] @ StringSplit[l, "\n"]
{{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}}, 
  {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}},
  {121, {"gcagtataaa", "caataataaa"}}}}

Also

f = Normal[{#, DeleteCases[{##2}, ""]} & @@@ SemanticImportString[#]] &;
f /@ l
{{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}}, 
  {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}}, 
  {121, {"gcagtataaa", "caataataaa"}}}}

and

f2 = {FromDigits @ #, {##2}} & @@@ 
      Split[StringSplit @ #, Not @* StringMatchQ[NumberString] @* First] &;
f2 /@ l
 {{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}},
   {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}},
   {121, {"gcagtataaa", "caataataaa"}}}}
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

Map[{FromDigits @ #, {##2}} & @@@ # & @* StringSplit] @ StringSplit[l, "\n"]
{{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}}, 
  {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}},
  {121, {"gcagtataaa", "caataataaa"}}}}

Also

f = Normal[{#, DeleteCases[{##2}, ""]} & @@@ SemanticImportString[#]] &;
f /@ l
{{{1, {"atattaggtt", "tttacctacc", "caggaaaagc", "caaccaacct"}}, 
  {61, {"ctctaaacga", "actttaaaat", "ctgtgtagct", "gtcgctcggc"}}, 
  {121, {"gcagtataaa", "caataataaa"}}}}