-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b38c88
commit 8747ac7
Showing
5 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package align | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestRandomAlignment(t *testing.T) { | ||
length := 3000 | ||
nbseqs := 500 | ||
a, err := RandomAlignment(AMINOACIDS, length, nbseqs) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
|
||
if a.Length() != length { | ||
t.Error(fmt.Sprintf("Length should be %d and is %d", length, a.Length())) | ||
} | ||
if a.NbSequences() != nbseqs { | ||
t.Error(fmt.Sprintf("Nb sequences should be %d and is %d", nbseqs, a.NbSequences())) | ||
} | ||
} | ||
|
||
func TestAppendIdentifier(t *testing.T) { | ||
a, err := RandomAlignment(AMINOACIDS, 300, 50) | ||
if err != nil { | ||
t.Error(err) | ||
|
||
} | ||
a.AppendSeqIdentifier("IDENT", false) | ||
|
||
a.IterateChar(func(name string, sequence []rune) { | ||
if !strings.HasPrefix(name, "IDENT") { | ||
t.Error("Sequence name does not start with expected id: IDENT") | ||
} | ||
}) | ||
|
||
a.AppendSeqIdentifier("IDENT", true) | ||
a.IterateChar(func(name string, sequence []rune) { | ||
if !strings.HasSuffix(name, "IDENT") { | ||
t.Error("Sequence name does not end with expected id: IDENT") | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var addIdOutput string | ||
var addIdName string | ||
var addIdRight bool | ||
|
||
// addidCmd represents the addid command | ||
var addidCmd = &cobra.Command{ | ||
Use: "addid", | ||
Short: "Adds a string to each sequence identifier of the input alignment", | ||
Long: `Adds a string to each sequence identifier of the input alignment. | ||
The string may be added to the left or to the right of each sequence identifier. | ||
`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
f := openWriteFile(addIdOutput) | ||
for al := range rootaligns { | ||
al.AppendSeqIdentifier(addIdName, addIdRight) | ||
writeAlign(al, f) | ||
} | ||
f.Close() | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(addidCmd) | ||
addidCmd.PersistentFlags().StringVarP(&addIdOutput, "out-align", "o", "stdout", "Renamed alignment output file") | ||
addidCmd.PersistentFlags().StringVarP(&addIdName, "name", "n", "none", "String to add to sequence names") | ||
addidCmd.PersistentFlags().BoolVarP(&addIdRight, "right", "r", false, "Adds the String on the right of sequence names (otherwise, adds to left)") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package cmd | ||
|
||
import ( | ||
"math/rand" | ||
"time" | ||
|
||
"github.com/fredericlemoine/goalign/align" | ||
"github.com/fredericlemoine/goalign/io" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var randomLength, randomSize int | ||
var randomAA bool | ||
var randomOutput string | ||
var randomSeed int64 | ||
|
||
// randomCmd represents the random command | ||
var randomCmd = &cobra.Command{ | ||
Use: "random", | ||
Short: "Generate random sequences", | ||
Long: `Generate random sequences. | ||
`, | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
rand.Seed(sampleSeed) | ||
var a align.Alignment | ||
var err error | ||
f := openWriteFile(addIdOutput) | ||
if !randomAA { | ||
a, err = align.RandomAlignment(align.NUCLEOTIDS, randomLength, randomSize) | ||
if err != nil { | ||
io.ExitWithMessage(err) | ||
} | ||
} else { | ||
a, err = align.RandomAlignment(align.AMINOACIDS, randomLength, randomSize) | ||
if err != nil { | ||
io.ExitWithMessage(err) | ||
} | ||
} | ||
writeAlign(a, f) | ||
f.Close() | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(randomCmd) | ||
randomCmd.PersistentFlags().IntVarP(&randomLength, "length", "l", 100, "Length of sequences to generate") | ||
randomCmd.PersistentFlags().IntVarP(&randomSize, "nb-seqs", "n", 10, "Number of sequences to generate") | ||
randomCmd.PersistentFlags().BoolVarP(&randomAA, "amino-acids", "a", false, "Aminoacid sequences (otherwise, nucleotides)") | ||
randomCmd.PersistentFlags().StringVarP(&randomOutput, "out-align", "o", "stdout", "Random alignment output file") | ||
randomCmd.PersistentFlags().Int64VarP(&randomSeed, "seed", "s", time.Now().UTC().UnixNano(), "Initial Random Seed") | ||
} |