func main() { pdbf1, chain1, s1, e1 := util.Arg(0), util.Arg(1), util.Arg(2), util.Arg(3) pdbf2, chain2, s2, e2 := util.Arg(4), util.Arg(5), util.Arg(6), util.Arg(7) entry1 := util.PDBRead(pdbf1) entry2 := util.PDBRead(pdbf2) s1n, e1n := util.ParseInt(s1), util.ParseInt(e1) s2n, e2n := util.ParseInt(s2), util.ParseInt(e2) r, err := pdb.RMSD( entry1, chain1[0], s1n, e1n, entry2, chain2[0], s2n, e2n) util.Assert(err) fmt.Println(r) }
func getPdbChain(fp string) *pdb.Chain { b := path.Base(fp) if !strings.HasSuffix(b, ".fmap") { util.Fatalf("Expected file named 'something.fmap' but got '%s'.", b) } idAndChain := b[0 : len(b)-5] if len(idAndChain) != 5 { util.Fatalf("Expected 4-letter PDB id concatenated with 1-letter "+ "chain identifier, but got '%s' instead.", idAndChain) } pdbName := idAndChain[0:4] chainId := idAndChain[4] pdbCat := idAndChain[1:3] pdbFile := fmt.Sprintf("pdb%s.ent.gz", pdbName) pdbPath := path.Join(util.FlagPdbDir, pdbCat, pdbFile) entry := util.PDBRead(pdbPath) chain := entry.Chain(chainId) if chain == nil { util.Fatalf("Could not find chain '%c' in PDB entry '%s'.", chainId, pdbPath) } return chain }
func main() { flag.BoolVar(&flagAllFragments, "all-fragments", flagAllFragments, "When set, all fragments will be shown, even if the best fragment\n"+ "of each ATOM set is the same.") util.FlagParse( "fraglib align.{fasta,ali,a2m,a3m} pdb-file out-csv", "Writes a CSV file to out-csv containing the best matching fragment\n"+ "for each pairwise contiguous set of alpha-carbon atoms of the\n"+ "first two proteins in the alignment and PDB file.") util.AssertNArg(4) flib := util.StructureLibrary(util.Arg(0)) aligned := util.MSA(util.Arg(1)) pentry := util.PDBRead(util.Arg(2)) outcsv := util.CreateFile(util.Arg(3)) csvWriter := csv.NewWriter(outcsv) csvWriter.Comma = '\t' defer csvWriter.Flush() pf := func(record ...string) { util.Assert(csvWriter.Write(record), "Problem writing to '%s'", outcsv) } pf("start1", "end1", "start2", "end2", "frag1", "frag2", "frag_rmsd") iter := newContiguous( flib.FragmentSize(), aligned.GetFasta(0), aligned.GetFasta(1), pentry.Chains[0], pentry.Chains[1]) for iter.next() { best1 := flib.BestStructureFragment(iter.atoms1) best2 := flib.BestStructureFragment(iter.atoms2) if !flagAllFragments && best1 == best2 { continue } bestRmsd := structure.RMSD(flib.Atoms(best1), flib.Atoms(best2)) pf( fmt.Sprintf("%d", iter.s1()), fmt.Sprintf("%d", iter.e1()), fmt.Sprintf("%d", iter.s2()), fmt.Sprintf("%d", iter.e2()), fmt.Sprintf("%d", best1), fmt.Sprintf("%d", best2), fmt.Sprintf("%f", bestRmsd), ) } }
func main() { entry := util.PDBRead(flag.Arg(0)) if len(flagChain) > 0 { if len(flagChain) != 1 { util.Fatalf("Chain identifiers must be a single character.") } chain := entry.Chain(flagChain[0]) if chain == nil { util.Fatalf("Could not find chain '%c' in PDB entry '%s'.", chain.Ident, entry.Path) } showMapping(chain, chain.SequenceAtoms()) } else { for _, chain := range entry.Chains { showMapping(chain, chain.SequenceAtoms()) } } }
func main() { libPath := util.Arg(0) chain := util.Arg(1) pdbEntryPath := util.Arg(2) bowOut := util.Arg(3) lib := util.StructureLibrary(libPath) entry := util.PDBRead(pdbEntryPath) thechain := entry.Chain(chain[0]) if thechain == nil || !thechain.IsProtein() { util.Fatalf("Could not find chain with identifier '%c'.", chain[0]) } bow := bow.BowerFromChain(thechain).StructureBow(lib) if bowOut == "--" { fmt.Println(bow) } else { util.BowWrite(util.CreateFile(bowOut), bow) } }
func main() { pdbFiles := util.RecursiveFiles(util.FlagPdbDir) files := make([]string, 0, flagNum) for i := 0; i < flagNum; i++ { var index int = -1 for index == -1 || !util.IsPDB(pdbFiles[index]) { // not guaranteed to terminate O_O index = rand.Intn(len(pdbFiles)) } files = append(files, pdbFiles[index]) pdbFiles = append(pdbFiles[:index], pdbFiles[index+1:]...) } for _, f := range files { if flagPaths { fmt.Println(f) } else { e := util.PDBRead(f) fmt.Printf("%s%c\n", strings.ToLower(e.IdCode), e.Chains[0].Ident) } } }
func main() { lib = util.StructureLibrary(util.Arg(0)) pdbEntry := util.PDBRead(util.Arg(1)) if util.NArg() == 2 { for _, chain := range pdbEntry.Chains { atoms := chain.CaAtoms() bestFragsForRegion(chain, atoms, 0, len(atoms)) } } else { chainId := util.Arg(2) chain := pdbEntry.Chain(chainId[0]) if chain == nil || !chain.IsProtein() { util.Fatalf("Could not find protein chain with id '%c'.", chainId) } atoms := chain.CaAtoms() if util.NArg() == 3 { bestFragsForRegion(chain, atoms, 0, len(atoms)) } else { if util.NArg() != 5 { log.Println("Both a start and end must be provided.") util.Usage() } s, e := util.Arg(3), util.Arg(4) sn, en := util.ParseInt(s)-1, util.ParseInt(e) if en-sn < lib.FragmentSize() { util.Fatalf("The range [%s, %s] specifies %d alpha-carbon "+ "atoms while at least %d alpha-carbon atoms are required "+ "for the given fragment library.", s, e, en-sn, lib.FragmentSize()) } bestFragsForRegion(chain, atoms, sn, en) } } }
func main() { pdbEntry := util.PDBRead(flag.Arg(0)) fasEntries := make([]seq.Sequence, 0, 5) if !flagSeparateChains { var fasEntry seq.Sequence if len(pdbEntry.Chains) == 1 { fasEntry.Name = chainHeader(pdbEntry.OneChain()) } else { fasEntry.Name = fmt.Sprintf("%s", strings.ToLower(pdbEntry.IdCode)) } seq := make([]seq.Residue, 0, 100) for _, chain := range pdbEntry.Chains { if isChainUsable(chain) { seq = append(seq, chain.Sequence...) } } fasEntry.Residues = seq if len(fasEntry.Residues) == 0 { util.Fatalf("Could not find any amino acids.") } fasEntries = append(fasEntries, fasEntry) } else { for _, chain := range pdbEntry.Chains { if !isChainUsable(chain) { continue } fasEntry := seq.Sequence{ Name: chainHeader(chain), Residues: chain.Sequence, } fasEntries = append(fasEntries, fasEntry) } } if len(fasEntries) == 0 { util.Fatalf("Could not find any chains with amino acids.") } var fasOut io.Writer if flag.NArg() == 1 { fasOut = os.Stdout } else { if len(flagSplit) > 0 { util.Fatalf("The '--split' option is incompatible with a single " + "output file.") } fasOut = util.CreateFile(util.Arg(1)) } if len(flagSplit) == 0 { util.Assert(fasta.NewWriter(fasOut).WriteAll(fasEntries), "Could not write FASTA file '%s'", fasOut) } else { for _, entry := range fasEntries { fp := path.Join(flagSplit, fmt.Sprintf("%s.fasta", entry.Name)) out := util.CreateFile(fp) w := fasta.NewWriter(out) util.Assert(w.Write(entry), "Could not write to '%s'", fp) util.Assert(w.Flush(), "Could not write to '%s'", fp) } } }
func main() { libFile := util.Arg(0) brkFile := util.Arg(1) lib := util.StructureLibrary(libFile) stderrf("Loading PDB files into memory...\n") entries := make([]*pdb.Entry, util.NArg()-2) for i, pdbfile := range flag.Args()[2:] { entries[i] = util.PDBRead(pdbfile) } stderrf("Comparing the results of old fragbag and new fragbag on " + "each PDB file...\n") for _, entry := range entries { stderrf("Testing %s...\n", entry.Path) fmt.Printf("Testing %s\n", entry.Path) // Try to run old fragbag first. The output is an old-style BOW. oldBowStr, err := runOldFragbag(brkFile, entry.Path, lib.Size(), lib.FragmentSize()) if err != nil { fmt.Println(err) fmt.Printf("The output was:\n%s\n", oldBowStr) divider() continue } oldBow, err := bow.NewOldStyleBow(lib.Size(), oldBowStr) if err != nil { fmt.Printf("Could not parse the following as an old style "+ "BOW:\n%s\n", oldBowStr) fmt.Printf("%s\n", err) divider() continue } // Now use package fragbag to compute a BOW. var newBow bow.Bow if flagOldStyle { newBow = oldStyle{entry}.StructureBow(lib) } else { newBow = newStyle{entry}.StructureBow(lib) } // Create a diff and check if they are the same. If so, we passed. // Otherwise, print an error report. diff := bow.NewBowDiff(oldBow, newBow) if diff.IsSame() { fmt.Println("PASSED.") divider() continue } // Ruh roh... fmt.Println("FAILED.") fmt.Printf("\nOld BOW:\n%s\n\nNew BOW:\n%s\n", oldBow, newBow) fmt.Printf("\nDiff:\n%s\n", diff) divider() } stderrf("Done!\n") }