#format python DNA := Object clone do ( complementWith := Map clone complementWith atPut("A", "T") complementWith atPut("T", "A") complementWith atPut("G", "C") complementWith atPut("C", "G") title := "" sequence := "" getRcSequence := method( result := list sequence foreach(i, v, nucleotide:= v asCharacter result append(complementWith at(nucleotide)) ) result reverse join("") ) setFromString := method(s, lines := s split("\n") title = lines first slice(1) lines removeFirst slines:= stripLines(lines) sequence = slines join("") ) stripLines := method(lines, slines:= list lines foreach(i, line, slines append(line strip) ) ) toString := method(col, lines := list() for(i,0, ((sequence size) / col) floor, lines append(sequence slice(col*i, col*i+col)) ) ">" .. title .. "\n"..(lines join("\n")) ) ) splitFasta := method(file, totalLines:= list lines := list(file readLine) while(true, line := file readLine if(line == nil, break) if(line at(0) asCharacter == ">", totalLines append(lines join("\n").."\n") lines = list(line) , lines append(line) ) ) totalLines append(lines join("\n").."\n") ) main := method( dna := DNA clone records := splitFasta(stdin) records foreach(i, record, dna setFromString(record) dna sequence = dna getRcSequence dna toString(3) println ) ) MockFile := Object clone do( lines := list setString := method(s, lines = s split("\n") ) readLine := method( line := lines first lines removeFirst line ) ) DnaTest := UnitTest clone do( testGetRcSequence := method( dna := DNA clone dna title := "test" dna sequence := "AGTC" assertEquals("GACT", dna getRcSequence) dna sequence = "AAGGTCCC" assertEquals("GGGACCTT", dna getRcSequence) ) testSetFromString := method( dna := DNA clone dna setFromString(">test\nAGTC \nAAA") assertEquals("test", dna title) assertEquals("AGTCAAA", dna sequence) ) testFastaRecord := method( file := MockFile clone file setString(">test\nAGTC\nAAA\n>test2\nGGG\n") fastaRecords := splitFasta(file) assertEquals(">test\nAGTC\nAAA\n", fastaRecords at(0)) assertEquals(">test2\nGGG\n", fastaRecords at(1)) ) testDnaToString := method( dna := DNA clone dna title = "test" dna sequence = "AGTC" assertEquals(">test\nAGT\nC", dna toString(3)) ) )